尝试使用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": "https://b9372952.ngrok.io",
"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": "..."
}
但是显示的活动只是常规消息,完全没有提及。我想念什么?
===编辑===
另一种尝试是将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);
答案 0 :(得分:1)
发布最终答案,以便任何人都可以快速复制粘贴。
public int DirectorId { get; set; }