DirectLineJS 接收机器人回复的副本
DirectLineJS receiving copies of Bot replies
我正在使用 DirectLineJS 通过网站从自定义网络聊天进行交流。我使用的是 Microsoft github 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)"
);
}
每当我开始阅读消息时,每条消息的副本数量都会增加一个,因此我的网站将经历这个循环:
我 - 向机器人发送消息
BotReply - 消息 1
我 - 向机器人发送一些消息
BotReply - 消息 2
BotReply - 消息 2
我 - 一些消息
BotReply - 消息 3
BotReply - 消息 3
BotReply - 消息 3
等等
我从机器人收到的响应 ID 对于重复消息也没有增加,所以说消息 3 的 ID = 00005,每个 BotReply - 消息 3 的 ID = 00005,但消息 4 的 ID = 00007
在我实际的 bot 中,我使用 await context.PostAsync("Some mesage");
发送消息,仅此而已
我怎样做才能将消息回复减少到只收到一个?
尽管我将我的消息过滤为来自 "mybot"
,但文档指出 "Direct Line will helpfully send your client a copy of every sent activity, so a common pattern is to filter incoming messages on from:"
如果不查看其余代码,很难准确确定发生了什么。但是,每次发送消息时,您似乎都在订阅接收消息。请尝试更改您的代码,以便您只订阅一次:
var directLine = new DirectLine.DirectLine({
secret: "My_DirectLine_Secret",
});
directLine.activity$
.filter(activity => activity.type === 'message' && activity.from.id === 'mybot')
.subscribe(
message => console.log(message)
);
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)
);
}
我正在使用 DirectLineJS 通过网站从自定义网络聊天进行交流。我使用的是 Microsoft github 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)"
);
}
每当我开始阅读消息时,每条消息的副本数量都会增加一个,因此我的网站将经历这个循环:
我 - 向机器人发送消息
BotReply - 消息 1
我 - 向机器人发送一些消息
BotReply - 消息 2
BotReply - 消息 2
我 - 一些消息
BotReply - 消息 3
BotReply - 消息 3
BotReply - 消息 3
等等
我从机器人收到的响应 ID 对于重复消息也没有增加,所以说消息 3 的 ID = 00005,每个 BotReply - 消息 3 的 ID = 00005,但消息 4 的 ID = 00007
在我实际的 bot 中,我使用 await context.PostAsync("Some mesage");
发送消息,仅此而已
我怎样做才能将消息回复减少到只收到一个?
尽管我将我的消息过滤为来自 "mybot"
,但文档指出 "Direct Line will helpfully send your client a copy of every sent activity, so a common pattern is to filter incoming messages on from:"如果不查看其余代码,很难准确确定发生了什么。但是,每次发送消息时,您似乎都在订阅接收消息。请尝试更改您的代码,以便您只订阅一次:
var directLine = new DirectLine.DirectLine({
secret: "My_DirectLine_Secret",
});
directLine.activity$
.filter(activity => activity.type === 'message' && activity.from.id === 'mybot')
.subscribe(
message => console.log(message)
);
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)
);
}