botframework - 我可以将信息从网页传递到 Bot Framework 网络聊天吗
问题描述
有什么方法可以将信息从网页传递到机器人。我有一个 Bot Framework 机器人,它使用嵌入在 aspx 页面上的 iframe 中的网络聊天。最终,我想根据用户所在的业务线动态设置 QnA Maker 在机器人中使用的过滤标签。而不是让他们告诉机器人他们代表哪个业务线,我希望能够通过自动向机器人发送信息。
这是 iframe 仅供参考:
<iframe src="https://webchat.botframework.com/embed/bdous-prod-newhire-bcr?s={my secret}" id="webchat"></iframe>
这可能吗?
谢谢,
迪伦
解决方案
正如 Nicolas R 所指出的,您应该使用反向渠道来执行您的询问。
您应该查看两个示例(它们实际上需要一起使用才能运行完整的示例)。它们是这个backChannelBot和BotFramework-WebChat/samples/backchannel示例。
在第一个示例中,您需要检查的重要代码可以在app.js
文件中找到:
//Bot listening for inbound backchannel events - in this case it only listens for events named "buttonClicked"
bot.on("event", function (event) {
var msg = new builder.Message().address(event.address);
msg.textLocale("en-us");
if (event.name === "buttonClicked") {
msg.text("I see that you just pushed that button");
}
bot.send(msg);
})
//Basic root dialog which takes an inputted color and sends a changeBackground event. No NLP, regex, validation here - just grabs input and sends it back as an event.
bot.dialog('/', [
function (session) {
var reply = createEvent("changeBackground", session.message.text, session.message.address);
session.endDialog(reply);
}
]);
//Creates a backchannel event
const createEvent = (eventName, value, address) => {
var msg = new builder.Message().address(address);
msg.data.type = "event";
msg.data.name = eventName;
msg.data.value = value;
return msg;
}
WebChat 示例中的相关代码部分是本节:
botConnection.activity$
.filter(function (activity) {
return activity.type === 'event' && activity.name === 'changeBackgroundColor';
})
.subscribe(function (activity) {
console.log('"changeBackground" received with value: ' + activity.value);
changeBackgroundColor(activity.value);
});
function changeBackgroundColor(newColor) {
document.getElementsByClassName('wc-message-groups')[0].style.backgroundColor = newColor;
}
function postButtonMessage(color) {
botConnection
.postActivity({
from: { id: 'me' },
name: 'changeBackgroundColor',
type: 'event',
value: color
})
.subscribe(function (id) {
console.log('"changeBackgroundColor" sent');
});
}
推荐阅读
- apache - 来自文件的 Fluentd 日志收集器
- cmd - LOG 未被识别为内部或外部命令
- sql - 如果在任何行中为真,则按具有重复对的行分组 - 结果为真
- ubuntu - 在 schedule 中使用 tcpdump 的最佳方式
- jquery - 在第一个完成后运行第二个 jQuery 点击函数
- python - read_eager() 未返回已执行命令的输出
- javascript - 如何在 Angular 手风琴中停止不必要的空容器 [循环]
- select - 获取带有打字稿的 feuser 列表,无法获取关联用户组的名称
- c# - ASP.NET 中的会话已过期
- python - protobuf 安装成功但无法导入