Microsoft Bot

编程入门 行业动态 更新时间:2024-10-07 18:23:31

<a href=https://www.elefans.com/category/jswz/34/1766835.html style=Microsoft Bot"/>

Microsoft Bot

[尝试使用NodeJs SDK提及Microsoft Teams中的用户:

我正在保存参考。对话,然后还原它。恢复后,将entities填充为-我了解的-这是Mention对象。

const message = "Konnichi wa";
const conversation = await .... // restored from db
await adapter.continueConversation(conversation, async (context) => {
  const topLevelMessage = MessageFactory.text(message);
  topLevelMessage.entities = [
    {
      type: "Mention", // have tried with "mention" as well
      mentioned: context.activity.from,
      text: `@${context.activity.from.name}`,
    },
  ];
  await context.sendActivity(topLevelMessage);
});

此代码实际上是向模拟器发送包含预期数据的活动:

{
  "type": "message",
  "serviceUrl": "",
  "channelId": "emulator",
  "from": {
    "id": "0c00d490-99db-11ea-a447-1de8c692dbf4",
    "name": "Bot",
    "role": "bot"
  },
  "conversation": {
    "id": "0e086460-99db-11ea-a447-1de8c692dbf4|livechat"
  },
  "recipient": {
    "id": "4c2e3fee-fb06-43a1-b9bb-279cc67ed6e6",
    "role": "user"
  },
  "text": "Konnichi wa",
  "inputHint": "...",
  "entities": [
    {
      "type": "Mention",
      "text": "@User",
      "mentioned": {
        "id": "4c2e3fee-fb06-43a1-b9bb-279cc67ed6e6",
        "name": "User",
        "role": "user"
      }
    }
  ],
  "replyToId": "...",
  "id": "...",
  "localTimestamp": "...",
  "timestamp": "...",
  "locale": "..."
}

但是显示的活动只是常规消息,完全没有提及。我想念什么?

  • doc.microsoft

===编辑===

[另一尝试一直使用TextEncoder<at>作为this sample:

const encodedUserName = new TextEncoder().encode(context.activity.from.name);
const mention = {
    type: "mention",
    mentioned: context.activity.from,
    text: `<at>${encodedUserName}</at>`,
};

const topLevelMessage = MessageFactory.text(`${mention.text}: ${message}`);
topLevelMessage.entities = [mention];
await context.sendActivity(topLevelMessage);
回答如下:

发布最终答案,以便任何人都可以快速将其粘贴粘贴。

await adapter.continueConversation(conversation, async (context) => {
    const encodedUserName = new TextEncoder().encode(context.activity.from.name);
    const mention = {
        type: "mention",
        mentioned: context.activity.from,
        text: `<at>${encodedUserName}</at>`,
    };
    const topLevelMessage = MessageFactory.text(`${message} ${mention.text}`);
    topLevelMessage.entities = [mention];
    await context.sendActivity(topLevelMessage);
});

更多推荐

Microsoft Bot

本文发布于:2024-05-07 21:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1757330.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Microsoft   Bot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!