我使用 DirectLineJS 通过网站进行自定义网络聊天进行通信。我使用的是 Microsoft github 发布的格式https://github.com/Microsoft/BotFramework-DirectLineJS https://github.com/Microsoft/BotFramework-DirectLineJS
我如何实现它是
var directLine;
directLine= new DirectLine.DirectLine({
secret: "My_DirectLine_Secret",
});
function sendReceiveActivity(msg) {
document.getElementById("inputtext").value = "";
conversation.innerHTML = conversation.innerHTML + "ME - " + msg + "<br/><br/>";
directLine.postActivity({
from: { id: 'myUserId', name: 'myUserName' }, // required (from.name is optional)
type: 'message',
text: msg
}).subscribe(
id => console.log("Posted activity, assigned ID ", id),
error => console.log("Error posting activity", error)
);
directLine.activity$
.filter(activity => activity.type === 'message' && activity.from.id === 'mybot')
.subscribe(
message => console.log(message)"
);
}
每当我开始阅读消息时,每条消息的副本数量都会增加一份,因此我的网站将经历以下循环:
我 - 向机器人发送消息
机器人回复 - 消息 1
我 - 向机器人发送一些消息
机器人回复 - 消息 2
机器人回复 - 消息 2
我——一些消息
机器人回复 - 消息 3
机器人回复 - 消息 3
机器人回复 - 消息 3
等等
对于重复的消息,我从机器人收到的响应 ID 也不会增加,因此假设消息 3 的 ID = 00005,每个 BotReply - 消息 3 的 ID = 00005,但消息 4 的 ID = 00007
在我的实际机器人中,我使用以下方式发送消息await context.PostAsync("Some mesage");
没有别的
我该如何减少消息回复数量,只收到一条消息?
该文档指出“Direct Line 将有助于向您的客户发送每个已发送活动的副本,因此常见模式是过滤来自以下来源的传入消息:”即使我将消息过滤为来自“mybot”