【问题标题】:How to identify if a mention in Microsoft Bots Framework in Microsoft Teams is a channel?如何确定 Microsoft Teams 中 Microsoft Bots Framework 中的提及是否为渠道?
【发布时间】:2021-01-24 02:34:02
【问题描述】:

在带有 Microsoft Teams 的 Microsoft Bots Framework 上,我可以轻松获得提及并存储它们,以便以后发送主动消息。下面的示例展示了如何根据Microsoft documentation 获取提及。

this.onMessage(async (turnContext, next) => {
    const mentions = TurnContext.getMentions(turnContext.activity);
    if (mentions){
        const firstMention = mentions[0].mentioned;
        await turnContext.sendActivity(`Hello ${firstMention.name}.`);
    } else {
        await turnContext.sendActivity(`Aw, no one was mentioned.`);
    }

    await next();
});

但是要发送主动消息,我有两种不同的消息结构,用于将消息发送给用户或通道,因此在发送消息的过程后期,我需要知道 mentions[0]是用户或频道。

我查看了文档和不同的用例,但找不到有关如何执行此操作的答案。

【问题讨论】:

  • mentions[0].提到.id 是用户和机器人/机器人和频道之间的聊天ID。当您使用此 ID 发送消息时,ID 是对话 ID,而不是用户/频道 ID,我将发送消息到 bot @提到的地方
  • 感谢您的回答。我将更新问题以使其更准确。但我的问题仍然存在,如果提及是用户或频道,我如何识别才能发送主动消息?

标签: javascript typescript botframework bots microsoft-teams


【解决方案1】:

我遇到了类似的情况,正如你所说,我没有找到直接的方法来区分用户或团队的提及,但这是我使用的:

try {
  // Check if mention is a member of a team
  const member = await TeamsInfo.getMember(
    context,
    mention.mentioned.id
  );
} catch (e) {
  try {
    // Or maybe is a team?
     const team = await TeamsInfo.getTeamDetails(
        context,
        mention.mentioned.id
      )
    );
  } catch (e) {
    console.log(e);
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-11
    • 2018-07-12
    • 2019-02-25
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    • 2017-09-24
    • 2023-03-11
    相关资源
    最近更新 更多