Sending proactive messages to a channel in Teams
Sending proactive messages to a channel in Teams
Sending proactive messages to a channel in Teams
Re: Sending proactive messages to a channel in Teams
Okay, so, this is how I made it work. I am posting it here for future reference.
***DISCLAIMER***: I still have no idea how to use it with `botbuilder` as was asked in my initial question, and this answer is going to use `ConnectorClient`, which is acceptable (for me, at least). Based on Hilton's directions and a GitHub issue that I saw earlier ( [https://github.com/OfficeDev/BotBuilder-MicrosoftTeams/issues/162#issuecomment-434978847](https://github.com/OfficeDev/BotBuilder-MicrosoftTeams/issues/162#issuecomment-434978847) ), I made it work finally. MS Documentation is not that helpful, since they always use `context` variable which is available when your Bot is responding to a message or activity, and they keep a record of these contexts internally while the Bot is running. However, if your Bot is restarted for some reason or you want to store your data in your database to be used later, this is the way to go.
So, the code (NodeJS):
```
const path = require('path');
const { ConnectorClient, MicrosoftAppCredentials } = require('botframework-connector');
const ENV_FILE = path.join(__dirname, '.env');
require('dotenv').config({ path: ENV_FILE });
const serviceUrl = 'https://smba.trafficmanager.net/emea/';
async function sendToChannel() {
MicrosoftAppCredentials.trustServiceUrl(serviceUrl);
var credentials = new MicrosoftAppCredentials(process.env.MicrosoftAppId, process.env.MicrosoftAppPassword);
var client = new ConnectorClient(credentials, { baseUri: serviceUrl });
var conversationResponse = await client.conversations.createConversation({
bot: {
id: process.env.MicrosoftAppId,
name: process.env.BotName
},
isGroup: true,
conversationType: "channel",
channelData: {
channel: { id: "19:[email protected]" }
},
activity: {
type: 'message',
text: 'This a message from Bot Connector Client (NodeJS)'
}
});
}
sendToChannel();
*(Réponse tronquée)*
***DISCLAIMER***: I still have no idea how to use it with `botbuilder` as was asked in my initial question, and this answer is going to use `ConnectorClient`, which is acceptable (for me, at least). Based on Hilton's directions and a GitHub issue that I saw earlier ( [https://github.com/OfficeDev/BotBuilder-MicrosoftTeams/issues/162#issuecomment-434978847](https://github.com/OfficeDev/BotBuilder-MicrosoftTeams/issues/162#issuecomment-434978847) ), I made it work finally. MS Documentation is not that helpful, since they always use `context` variable which is available when your Bot is responding to a message or activity, and they keep a record of these contexts internally while the Bot is running. However, if your Bot is restarted for some reason or you want to store your data in your database to be used later, this is the way to go.
So, the code (NodeJS):
```
const path = require('path');
const { ConnectorClient, MicrosoftAppCredentials } = require('botframework-connector');
const ENV_FILE = path.join(__dirname, '.env');
require('dotenv').config({ path: ENV_FILE });
const serviceUrl = 'https://smba.trafficmanager.net/emea/';
async function sendToChannel() {
MicrosoftAppCredentials.trustServiceUrl(serviceUrl);
var credentials = new MicrosoftAppCredentials(process.env.MicrosoftAppId, process.env.MicrosoftAppPassword);
var client = new ConnectorClient(credentials, { baseUri: serviceUrl });
var conversationResponse = await client.conversations.createConversation({
bot: {
id: process.env.MicrosoftAppId,
name: process.env.BotName
},
isGroup: true,
conversationType: "channel",
channelData: {
channel: { id: "19:[email protected]" }
},
activity: {
type: 'message',
text: 'This a message from Bot Connector Client (NodeJS)'
}
});
}
sendToChannel();
*(Réponse tronquée)*