![](/img/trans.png)
[英]How to add the microsoft botbuilder framework node.js version 4 bot in microsoft teams?
[英]Microsoft Teams botbuilder How to create conversation in another channel
(作為參考,我為該組織提供了admin_consent
,其身份驗證 scope 為offline_access User.ReadWrite.All Group.ReadWrite.All AppCatalog.ReadWrite.All
用於我用於與 Teams 實例交互的令牌。)
通過 POST /teams/{id}/installedApps 安裝應用程序后,它會發送一個conversationUpdate
更新事件,我會響應並保存整個ConversationReference
object。 它有很多我不需要的東西,但我不確定什么是必要的。 立即響應轉到指定團隊的General
頻道。
現在,我想使用該ConversationReference
將主動通知消息發布到用戶在 Teams 之外指定的頻道。 所以用戶沒有在這個頻道中與機器人交互,但我可以列出頻道並有它的 ID。
我可以使用我捕獲的整個ConversationReference
將消息發布到General
頻道,或者通過省略頻道特定字段直接在chat
中向用戶發送消息,但如果我將消息指定為,我似乎無法將消息發送到特定頻道channelId
const msBotAdapter = new BotFrameworkAdapter({
appId: TEAMS_CLIENT_ID,
appPassword: TEAMS_CLIENT_SECRET,
});
//Paired down the saved reference to look like this
const conversationReference = {
"user" : {
"id" : "9:1rafmaopfopakdfafMzCYlCtg",
"aadObjectId" : "fffffff-ffff-ffff-ffff-ffffffff"
},
"bot" : {
"id" : "8:sdfsfsdf-dddd-ddddd-aaaaa-vvvvvvv",
"name" : "Bot Name"
},
"conversation" : {
"isGroup" : true,
"conversationType" : "channel",
"tenantId" : "ffffffff-ssssss-ssssss-ss-ssssss"
},
"channelId" : "msteams",
"serviceUrl" : "https://smba.trafficmanager.net/amer/"
}
const heroCard = CardFactory.heroCard(label, text, undefined, undefined, {
subtitle: fromUser?.name ? `From: ${fromUser.name}` : undefined,
});
const channelId = {...retrieve channel Id}
const activity = {
recipient: {
id: channelId,
name: 'Test channel 2',
},
type: ActivityTypes.Message,
timestamp: new Date(),
localTimezone: 'America/New_York',
callerId: TEAMS_CLIENT_ID,
serviceUrl: conversationReference.serviceUrl!,
channelId,
from: conversationReference.bot as { id: string; name: string },
valueType: 'text',
attachments: [heroCard],
};
await msBotAdapter.createConversation(
conversationReference,
async turnContext => {
await turnContext.sendActivity(activity);
}
);
成功! 結果表明將消息定向到另一個通道需要操作ConversationReference
而不是(如我所想)在發送的Activity
中指定它。 我通過刪除我在原始問題中創建的Activity
並僅通過await turnContext.sendActivity('Test Message');
發送純文本來展示這一點。
const channelId = //retrieve desitnation channelId I use the graph api `/teams/${teamId}/channels`
const msBotAdapter = new BotFrameworkAdapter({
appId: TEAMS_CLIENT_ID,
appPassword: TEAMS_CLIENT_SECRET,
});
//Paired down the initial conversation reference to bare necessities, the important part is setting the `conversationReference.conversation.id` to the `channelId` that you wish the message to go to.
const conversationReference = {
"bot" : {
"id" : "8:sdfsfsdf-dddd-ddddd-aaaaa-vvvvvvv",
},
"conversation" : {
//This is where you dictate where the message goes
id: channelId
},
"serviceUrl" : "https://smba.trafficmanager.net/amer/"
}
await msBotAdapter.createConversation(
conversationReference,
async turnContext => {
await turnContext.sendActivity('Test Message');
}
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.