如何使用 Directline Webchat 重新加载 Web 应用程序?
How to Reload Web Application using Directline Webchat?
如何使用 Directline Webchat 重新加载 Web 应用程序?
或者在 Directline Webchat 收到 Bot 的响应后,有什么方法可以调用 Javascript 函数吗?
您可以为此使用 WebChat 控件的 BackChannel:
const user = {
id: 'userid',
name: 'username'
};
const bot = {
id: 'botid',
name: 'botname'
};
const botConnection = new BotChat.DirectLine({
secret: 'SECRET'
});
BotChat.App({
bot: bot,
botConnection: botConnection,
user: user
}, document.getElementById('BotChatGoesHere'));
botConnection.activity$
.filter(function (activity) {
return activity.type === 'event' && activity.name === 'changeBackground';
})
.subscribe(function (activity) {
console.log('"changeBackground" received with value: ' + activity.value);
changeBackgroundColor(activity.value);
});
function changeBackgroundColor(newColor) {
document.body.style.backgroundColor = newColor;
}
此示例展示了机器人如何向 WebChat 发送 changeBackground 事件并更改页面的背景颜色。
来自:
https://github.com/Microsoft/BotFramework-WebChat/blob/master/samples/backchannel/index.html
您可以发送 reloadPage 事件并在 javascript 中调用 location.reload(),而不是 changeBackground 事件。
如何使用 Directline Webchat 重新加载 Web 应用程序?
或者在 Directline Webchat 收到 Bot 的响应后,有什么方法可以调用 Javascript 函数吗?
您可以为此使用 WebChat 控件的 BackChannel:
const user = {
id: 'userid',
name: 'username'
};
const bot = {
id: 'botid',
name: 'botname'
};
const botConnection = new BotChat.DirectLine({
secret: 'SECRET'
});
BotChat.App({
bot: bot,
botConnection: botConnection,
user: user
}, document.getElementById('BotChatGoesHere'));
botConnection.activity$
.filter(function (activity) {
return activity.type === 'event' && activity.name === 'changeBackground';
})
.subscribe(function (activity) {
console.log('"changeBackground" received with value: ' + activity.value);
changeBackgroundColor(activity.value);
});
function changeBackgroundColor(newColor) {
document.body.style.backgroundColor = newColor;
}
此示例展示了机器人如何向 WebChat 发送 changeBackground 事件并更改页面的背景颜色。
来自: https://github.com/Microsoft/BotFramework-WebChat/blob/master/samples/backchannel/index.html
您可以发送 reloadPage 事件并在 javascript 中调用 location.reload(),而不是 changeBackground 事件。