我有一个机器人,该机器人是使用Bot Framework v4和NodeJS开发的,并已部署在Teams的多个渠道上。有没有办法更新机器人发送的消息?我尝试在BotFrameworkAdapter中实现updateActivity()函数。但是,它不会更新活动。
我将此卡从机器人中发送到了团队频道。有人单击按钮时,有什么方法可以更新卡或消息(禁用按钮)?
答案 0 :(得分:1)
关键是要确保在使用updateActivity()
时,使用由团队渠道创建的正确活动ID。您还需要确保更新后的活动已将所有“团队”数据集都设置为该数据。
在onTurn
中,捕获外发活动,以便您可以轻松保存所有必要的团队频道数据:
public onTurn = async (turnContext: TurnContext) => {
turnContext.onSendActivities(async (ctx, activities, nextSend) => {
activities.forEach(async (activity) => {
if (activity.channelData.saveMe) {
this.savedActivity = activity;
}
});
return await nextSend();
});
channelData
,conversation
信息和activity.id
实例化一些关键变量:
const teamsChannel = '19:8d60061c3d10xxxxxxxxxxxxxxxx@thread.skype';
const serviceUrl = 'https://smba.trafficmanager.net/amer/';
activity
上设置断点serviceUrl
可能因地理位置而异发送第一个活动并存储ID:
// This ensures that your bot can send to Teams
turnContext.activity.conversation.id = teamsChannel;
turnContext.activity.serviceUrl = serviceUrl;
MicrosoftAppCredentials.trustServiceUrl(serviceUrl);
// Add the saveMe flag
yourActivity.channelData = { saveMe: true };
const response = await turnContext.sendActivity(yourActivity);
this.activityToUpdateId = response.id;
更新您保存的活动:
// New data
const card2 = CardFactory.adaptiveCard(adaptiveCard2);
// Set the saved activity.id and new activity data (an adaptiveCard, in this example)
this.savedActivity.id = this.activityToUpdateId;
this.savedActivity.attachments = [card2];
发送更新:
await turnContext.updateActivity(this.savedActivity);
之前:
之后:
答案 1 :(得分:0)
我已经使用中间件进行了尝试,但是一直得到:“该机器人不属于对话名册”。问题:我的机器人正在更新用户写的消息,所以我需要特殊权限吗?
let ActivityID = context.activity.conversation.id.split("=")[1];
let updatedActivity: Partial<Activity> = {
"id": ActivityID,
"channelId": context.activity.channelId,
"channelData": context.activity.channelData,
"conversation":
{
"name": "",
"id": context.activity.conversation.id,
"isGroup": context.activity.conversation.isGroup,
"conversationType": context.activity.conversation.conversationType,
"tenantId": context.activity.conversation.tenantId
},
"type": "message",
"text": "",
"summary": "",
"attachments": [ attachment ]
} await context.updateActivity(updatedActivity);