【发布时间】:2020-04-11 00:50:01
【问题描述】:
(作为参考,我有 admin_consent 用于身份验证范围为 offline_access User.ReadWrite.All Group.ReadWrite.All AppCatalog.ReadWrite.All 的组织作为我用来与 Teams 实例交互的令牌。)
通过 POST /teams/{id}/installedApps 安装应用程序后,它会发送一个 conversationUpdate 事件,我会响应并保存整个 ConversationReference 对象。它有很多我不需要的东西,但我不确定什么是必要的。立即响应转到指定团队的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);
}
);
【问题讨论】:
-
我自己也遇到过类似的问题。这有帮助吗?我还没有尝试过解决方案...stackoverflow.com/questions/55007896/…
-
@billoverton 我终于想通了,谢谢你的链接,虽然我找不到我的解决方案。
-
(解决方案贴在下面)
标签: node.js botframework microsoft-graph-api microsoft-teams