I want to send a private message to user. Currently, what I have are:
user id
tenant id
bot
Here is my sample code to try to send message:
var address =
{
channelId: 'msteams',
user: { id: user.id },
channelData: {
tenant: {
id: "cscportal.onmicrosoft.com"
}
},
bot:
{
id: bot.id,
name: bot.name
},
serviceUrl: "https://smba.trafficmanager.net/amer-client-ss.msg/",
useAuth: true
}
var msg = new builder.Message().address(address);
msg.text("Hello! This is a sample message.");
msg.textLocale('en-US');
bot.send(msg);
My sample code does not work because of something wrong in my address. Can you help me to find a way to send a private message to user?
Note: I don't have conversation ID
You need the user’s unique ID and tenant ID to send a proactive message. Typically, these are obtained from a team context, either by fetching the team roster or when a user interacts with your bot in a channel. Please check documentation on how to create personal conversation. Please also read about Proactive Messages.
Here is the source code for Node.js sample for Proactive Messages.
Related
Im trying to make a vibe bot that will only send announcements to group of people. The bot will not respond or interact with anyone, as its only and primary task is sending given text as an announcement to a group of people in the same chat.
I don’t understand:
a. What is wrong?
b. Why its not working?
c. Where to find the viber chat id?
d. Can I hook up this bot to any chat group (group/community/channel)?
const ViberBot = require('viber-bot').Bot;
const TextMessage = require('viber-bot').Message.Text;
const viberBot = new ViberBot({
authToken: process.env.VIBER_AUTH_TOKEN,
name: "...name...",
avatar: "...img-url..."
});
viberBot.sendMessage({ id: process.env.VIBER_GROUP_ID }, new TextMessage("hello world!"))
I triple-checked the auth tokens, and it's correct. But I still can't find the Viber Chat Id.
I tried to get the ending of a share link (to use it as the chat id), and the result I got was the following error:
{
status: 10,
status_message: 'webhookNotSet',
chat_hostname: 'SN-CHAT-16_'
}
{
status: 10,
status_message: 'webhookNotSet',
chat_hostname: 'SN-CHAT-20_'
}
{
status: 10,
status_message: 'webhookNotSet',
chat_hostname: 'SN-CHAT-10_'
}
Does anybody know how to fix this?
I am trying to add new feature to the bot which is sending the message to some users proactively from the bot. am working on botkit ("botkit": "^0.7.4") and language nodeJS(node v10.24.1 (npm v6.14.12)).
Below is the code sample:
let bot = controller.spawn({"serviceUrl":"https://*****"});
params = { conversationType: 'personal',
tenantId: '66********',
id: 'a:1*********',
members: [
{
id: '29:1*********'
}
],
channelData: { tenant: { id: '6********' } },
is_group: false
}
bot.startConversationWithUser(params);
bot.say("hello");
Although it is not giving any error, but it is not sending the message. I checked all the documentation but fail to get any solution.
Can anyone suggest a way out where I am going wrong? Which is the right way to send proactive messages to the users on the teams?
I am trying to send an attachment using proactive messaging to a channel,
below is my code.
async function sendToChannelWithImage(message,channelId,img) {
MicrosoftAppCredentials.trustServiceUrl('');
var credentials = new MicrosoftAppCredentials('app-id', 'password');
var client = new ConnectorClient(credentials, { baseUri: 'https://smba.trafficmanager.net/us/' });
var conversationResponse = await client.conversations.createConversation({
bot: {
id: 'app-id',
name: 'test'
},
isGroup: true,
conversationType: "channel",
channelData: {
channel: { id: channelId }
},
activity: {
type: 'message',
text: message,
attachments: [img]
}
});
}
const img = {contentType: 'image/*',contentUrl: "https://theysaidso.com/img/qod/qod-inspire.jpg"};
message = 'test'
channelId = 'testid'
In this I am getting trying to send the message using bot framework,
what i have tried : https://learn.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-send-receive-attachments
Sending a proactive message to a Teams team channel is no different from sending a proactive message to a personal conversation, so you should be using sendToConversation instead of createConversation. To send a proactive message anywhere, you'll need to make sure you have the conversation ID. In Teams, it's also important to trust the service URL.
If you want to start a new thread in a team channel, you can do that by removing the thread ID from the conversation ID. See here: Microsoft Bot - Node SDK: How to post to a public channel *without replying to a prev. activity*
It looks like there's a sample about starting new threads in team channels if you'd like to check that out: https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/58.teams-start-new-thread-in-channel
This is my first time trying to create a slack bot and I am following this template code to the word, I have not made any changes, and just remixed on glitch, copy-pasted the auth tokens correctly, things worked just fine.
That is until I made the #general channel restricted for Full Member users.
This is the error I see in the logs at glitch.
PostMessage Error: restricted_action
Is there an additional scope that I need to set, other than bot ?
Here is the workspace user permissions, I am the owner for this workspace.
Here is the code:
const postAnnouncementToChannel = (user, announcement) => {
const { title, details, channel } = announcement;
let announcementData = {
token: process.env.SLACK_ACCESS_TOKEN,
channel: channel,
text: `:loudspeaker: Announcement from: <#${user}>`,
attachments: JSON.stringify([
{
title: title,
text: details,
footer: 'DM me to make announcements.'
}
])
};
send(announcementData, user);
}
const send = async(data) => {
data.as_user = true; // send DM as a bot, not Slackbot
const result = await axios.post(`${apiUrl}/chat.postMessage`, qs.stringify(data))
try {
if(result.data.error) console.log(`PostMessage Error: ${result.data.error}`);
} catch(err) {
console.log(err);
}
}
Testing it via
https://api.slack.com/methods/chat.postMessage/test
using bot-token says
{
"ok": false,
"error": "restricted_action"
}
Testing this using xoxp-token gives this:-
{
"ok": false,
"error": "missing_scope",
"needed": "chat:write:user",
"provided": "identify,bot"
}
No. You are not missing any scopes. Its just that the user you used to auth your app can not post into the general channel. Apparently admins have restricted who can post messages in that channel, e.g. to admins only.
Either use a user that has posting rights for that channel to auth your app or switch to a different channel for your testing.
Bots are not full members so I had to use user token
xoxp-token
to post to chat.postmessage, with
as_user:false
and had to add a missing_scope that is
chat:write:user
And then I was able to make this work correctly.
Credit goes to #girliemac for helping out on this one.
https://github.com/slackapi/template-announcement-approvals/issues/6
Thanks
I'm trying to create a new integration to combine slack with another chat system.
If someone sends a message from skype for example, I want his name to be used when the message is sent to slack. Right now I'm using IncomingWebhook to send messages.
private getWebClient(configuration: ConfigurationData): IncomingWebhook {
return new IncomingWebhook('https://hooks.slack.com/services/...');
}
const webhook = this.getWebClient(configuration);
await webhook.send(
{
text: 'How are you today?',
as_user: false,
username: 'slack_integration',
icon_emoji: ':chart_with_upwards_trend:',
thread_ts: event.ts
}
);
As you can see, I'm also trying to reply to the message in a thread. This is not working either. The following event I get looks as follows:
{ text: 'How are you today?',
bot_id: 'B9G8LHME1',
type: 'message',
subtype: 'bot_message',
ts: '1519830326.000061',
channel: 'C9G4BJ8BW',
event_ts: '1519830326.000061' }
The message still appears to be from my App. The name is "Slack Integration Test" (with a badge showing App right next to it).