织梦CMS - 轻松建站从此开始!

abg欧博官网|登陆|游戏|

Sending proactive messages to a channel in Teams

时间:2025-07-24 06:35来源: 作者:admin 点击: 1 次
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 wa

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 ( ), 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();

NOTE: As Hilton pointed out, serviceUrl also needs to be loaded from your database, along with the channel id. It is available inside the activity which you receive initially when your Bot is added to team / channel / group along with channelId which you will also need, and you need to store those for future reference (do not hardcode them like in the example).

So, there is no separate createConversation and sendActivity, it's all in one call.

Thanks Hilton for your time, and a blurred image of my hand to MS Docs :)

Hope this helps someone else

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-07-28 06:07 最后登录:2025-07-28 06:07
栏目列表
推荐内容