You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Teams Toolkit Bot存储问题:更新后丢失会话上下文无法发消息

Bot更新后丢失会话上下文无法发送消息的问题

问题说明

我将用户的Conversation Reference对象存储在Blob Storage中,但Bot更新后仍会丢失用户上下文,无法向该会话对象发送消息。我尝试过向会话对象甚至完整的Member对象发送消息(Bot通知似乎以此为目标),相关代码如下:

相关代码

try{
  const storedTarget = await storage.get(payload.memberId);
  if(!storedTarget){
    return res.send(404, "Member not found");
  }
  const conversationReference = storedTarget as ConversationReference;
  // 恢复会话
  await notificationApp.adapter.continueConversationAsync(
    'bot_id_number_here', 
    conversationReference,
    async (context) => {
      await context.sendActivity({
        type: 'message',
        text: 'Hello, This is a Test!'
      })
    }
  )
  res.send(200, "Success");
} catch (error) {
  console.error("Error:", error);
  console.log("Member cannot receive card", target)
}

解决要点

  • 校验会话引用完整性:确保存储的Conversation Reference包含所有必要字段——bot.id、channelId、conversation.id、user.id以及serviceUrl。部分渠道(如Teams)的serviceUrl可能在Bot更新后变更,过期地址会导致消息发送失败。
  • 确认Bot ID匹配:continueConversationAsync的第一个参数必须是当前Bot的有效ID,更新Bot后要保证这个ID和注册信息完全一致,不能写错。
  • 完整存储与反序列化:存储时要完整序列化整个Conversation Reference对象,读取时正确反序列化为对应类型,避免因字段丢失或类型转换错误导致上下文失效。
  • 适配渠道限制:部分渠道要求Bot保持会话活跃,若发送失败,可尝试通过adapter.createConversationAsync重新验证会话有效性,或重新获取用户最新的会话引用。
  • 检查权限与过期:确认Bot更新后权限未变更,部分渠道的会话令牌可能过期,若发送失败需重新获取用户的会话信息。

内容的提问来源于stack exchange,提问作者Justin J

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 00:32:48