ibm-watson - 如何在 Watson Conversation 中触发对话?
问题描述
我需要在 ibm-watson 对话中触发特定对话,但不要求用户输入某些内容(如意图)。我需要使用 botkit 来启动一个特定的对话框。那有可能吗?我正在谷歌寻找所有可能的文档和链接,但没有成功:/
解决方案
发送初始空消息会触发welcome
对话框中的事件。
为了让它做一些不同的事情,你可以在上下文中设置一些变量,并为该变量添加条件到对话框中的欢迎分支。
这就是我在我的机器人中实现它的方式:
function handleHelloEvent(bot, message) {
message.type = 'welcome';
const contextDelta: any = {};
if (message.intent) {
contextDelta.initialIntent = message.intent;
}
//more fields here
watsonMiddleware.sendToWatsonAsync(bot, message, contextDelta).catch((error) => {
message.watsonError = error;
}).then(() => {
//this is the same function which handles message_received events
return handleWatsonResponse(bot, message);
});
}
function handleWatsonResponse(bot, message) {
bot.reply(message, message.watsonData.output.text.join('\n'));
}
controller.on('hello', handleHelloEvent);
controller.on('message_received', handleWatsonResponse);
hello
事件特定于任何地方的 webchat/botkit,您可能需要为不同的平台处理不同的事件。
代码处理欢迎事件的类似示例:https
://github.com/watson-developer-cloud/botkit-middleware/#dynamic-workspace
(我也写了一个,所以有点太相似了)。
推荐阅读
- node.js - ReactJS:从 S3 渲染私有图像资产
- outlook-addin - Outlook Web 加载项从功能区中随机消失
- java - RxJava:将整个字节数组合并为一个数组
- c++ - C++梯度函数返回假值
- docker - 在 Dockerfile 中运行脚本
- reactjs - react-google-charts 未在 ie11 上显示-“无法绘制图表数据”
- java - 如何在 Hibernate 中使用 JPA Criteria API 摆脱 N+1
- asp.net - 是否可以获得正在运行应用程序的应用程序池(事先不知道网站)?
- python - 如何使用 VLC 播放已经流式传输的 H264 RTSP 数据 - 使用 Wireshark 转储到文件
- leaflet - sapUI5/OpenUI5 Leafletjs 自定义控件