我用的是https://github.com/Microsoft/BotFramework-WebChat/blob/master/README.md
我想要机器人收到一个“加入”消息,每当网络聊天小部件显示在网站上。
这个想法是人类不需要开始谈话。机器人可以用一条欢迎的信息来回应加入对话的人。
这怎麽可能?
发布于 2019-01-15 12:41:44
这个“欢迎功能”是自网络聊天v3以来的一个长期讨论和话题。看起来它在两天前就被修复了,使用这个拉请求:https://github.com/Microsoft/BotFramework-WebChat/pull/1286
现在有一个关于如何做到这一点的示例,位于这里:https://github.com/Microsoft/BotFramework-WebChat/blob/master/samples/15.d.backchannel-send-welcome-event/index.html
简单地说,演示如下:
(async function () {
// In this demo, we are using Direct Line token from MockBot.
// To talk to your bot, you should use the token exchanged using your Direct Line secret.
// You should never put the Direct Line secret in the browser or client app.
// https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication
const res = await fetch('https://webchat-mockbot.azurewebsites.net/directline/token', { method: 'POST' });
const { token } = await res.json();
// We are using a customized store to add hooks to connect event
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
// When we receive DIRECT_LINE/CONNECT_FULFILLED action, we will send an event activity using WEB_CHAT/SEND_EVENT
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
value: { language: window.navigator.language }
}
});
}
return next(action);
});
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token }),
store
}, document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
请注意,由于这个PR是非常新的,它没有嵌入到latest
发行版中,所以您必须指向webchat.js
文件的master
版本,而不是latest
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
它起作用了:在您的机器人端收到Event
类型的活动通知后,您将能够在用户输入任何内容之前回复您的用户:
https://stackoverflow.com/questions/54194878
复制相似问题