【发布时间】:2020-01-11 02:48:48
【问题描述】:
我已经使用直线和 Microsft 的 sample-webchat 在网络聊天中实现了我的 v4 .NET 机器人。如何在聊天中的每条消息后启用机器人的名称和用户的名称,例如this 示例?
我已经使用 BotChat.App 和 https://cdn.botframework.com/botframework-webchat/0.11.4/botchat.js 作为脚本让它工作,但我似乎无法像 Microsoft 的示例那样使用 window.WebChat 来解决它。
这是我的网络聊天代码:
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<style>
html, body { height: 100% }
body { margin: 0 }
#webchat {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div style="display: flex">
<div style="position: relative; height: 500px; width: 370px"><div id="webchat" ></div></div>
</div>
<script>
(async function () {
const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', { method: 'POST', headers: { Authorization: 'Bearer my direct line secret' } });
const { token } = await res.json();
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
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();
BotChat.App({
botConnection: botConnection,
user: { id: '1234', name: 'user'},
bot: { id: 'botid' },
chatTitle: "I'm a custom chat title"
}, document.getElementById("webchat"));
})().catch(err => console.error(err));
</script>
</body>
</html>
【问题讨论】:
标签: reactjs botframework web-chat