使用Bot Framework更新MS Teams活动消息出现内容为空问题咨询
MS Teams机器人更新Adaptive Card为文本时内容不实时渲染问题
问题描述
调试机器人与MS Teams的交互功能时遇到以下异常:
机器人首先向用户发送一张Adaptive Card,当用户再次与机器人交互时,机器人会将这条携带卡片的消息更新为文本内容I got updated!。
但在Windows桌面端和网页端MS Teams中,更新后的消息仅显示已更新标识,内容为空,必须切换到其他会话再返回当前对话,更新后的内容才会正常加载,无法判断这是平台预期行为还是代码实现有误。
示例代码
依赖配置
"dependencies": { "adaptivecards": "^2.1.0", "axios": "^0.21.0", "botbuilder": "~4.8.0", "dotenv": "^8.2.0", "restify": "~8.4.0", (...) }
适配器初始化逻辑
const adapter = new BotFrameworkAdapter({...}); adapter.onTurnError = onTurnErrorHandler; const myBot = new EchoBot(); static processActivity(req, res) { adapter.processActivity(req, res, async context => { // 路由到主对话 await myBot.run(context); }); }
机器人主类代码
class EchoBot extends ActivityHandler { constructor() { super(); this.onMessage(async (context) => { await doSomething(context); }); } }
卡片发送与更新逻辑
someCardContent = {...}; lastCardId = undefinded; async function doSomething(turnContext) { if (!lastCardId) { { lastCardId } = await turnContext.sendActivity(MessageFactory.attachment(CardFactory.adaptiveCard(someCardContent))); } else { const newActivity = MessageFactory.text('I got updated!'); newActivity.id = lastCardId; lastCardId = undefinded; await turnContext.updateActivity(newActivity) } }
复现步骤
- 1 与机器人交互(发送问候消息)
- 2 机器人发送一张卡片:

- 3 再次交互(点击卡片按钮),卡片触发更新("Actualizado" = 已更新):

- 4 切换到其他会话后返回与该机器人的对话:

内容的提问来源于stack exchange,提问作者Fradantim
相关产品推荐
相关产品推荐

