(作为参考,我有admin_consent
用于组织,我用于与Teams实例交互的令牌的认证范围为offline_access User.ReadWrite.All Group.ReadWrite.All AppCatalog.ReadWrite.All
。)
通过POST / teams / {id} / installedApps安装应用程序后,它会发送一个conversationUpdate
事件,我对此进行了响应并保存了整个ConversationReference
对象。它有很多我不需要的东西,但是我不确定什么是必要的。立即响应将转到指定团队的General
频道。
现在,我想使用ConversationReference
将主动通知消息发布到用户在Teams之外指定的频道。因此,用户尚未在此频道中与机器人进行交互,但是我可以列出该频道并获得其ID。
我可以利用捕获的整个General
将消息发布到ConversationReference
通道中,也可以通过省略通道专用字段直接在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);
}
);
答案 0 :(得分:2)
成功!事实证明,将消息定向到另一个通道需要操纵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');
}
);