Cordova 或 ionic 聊天机器人实现
Cordova or ionic chat bot implementation
我们使用 angular js 开发了 cordova 移动应用程序,我们正在尝试在我们的应用程序中添加聊天机器人(聊天服务)功能任何人在 cordova 或混合移动应用程序中实现了相同的功能请让我知道最好的实施方式
您可以使用 api.ai or wit.ai 它们都有很多库,因此您可以将它与您选择的平台集成,在您的情况下,您可以使用 http。
您还可以查看 this github repo 它包含一个使用 api.ai 在 apache cordova 应用程序中创建聊天机器人的示例
在开始实施以下代码之前,请先阅读并清除有关意图、实体、实现的基础知识,然后创建一个代理。
https://dialogflow.com/docs/getting-started/basics
作为您在 cordova 中的项目,下面是快速启动实现 -
使用 Cordova CLI 安装 api.ai 插件:
cordova plugin add cordova-plugin-apiai
在 onDeviceReady[= 函数中添加到您的 index.js 文件(通常在 js 文件夹中) 31=] 以下代码
ApiAIPlugin.init(
{
clientAccessToken: "YOUR_CLIENT_ACCESS_TOKEN", // insert your client access key here
lang: "en" // set lang tag from list of supported languages
},
function(result) { /* success processing */ },
function(error) { /* error processing */ }
);
ApiAIPromises init 方法会将应用程序连接到 "Dialogflow project",它需要一个客户端访问令牌,该令牌在代理设置中可用。
如果您想要发送文本请求,请添加以下代码:
function sendText(query_text) {
try {
ApiAIPlugin.requestText(
{
query: query_text
},
function (response) {
// place your result processing here
alert(JSON.stringify(response));
},
function (error) {
// place your error processing here
alert(error);
});
} catch (e) {
alert(e);
}
}
您可以检查这个 nodejs-dialogflow 库。
这里是GitHub example you can use to get you started and check this link了解更多详情
我们使用 angular js 开发了 cordova 移动应用程序,我们正在尝试在我们的应用程序中添加聊天机器人(聊天服务)功能任何人在 cordova 或混合移动应用程序中实现了相同的功能请让我知道最好的实施方式
您可以使用 api.ai or wit.ai 它们都有很多库,因此您可以将它与您选择的平台集成,在您的情况下,您可以使用 http。 您还可以查看 this github repo 它包含一个使用 api.ai 在 apache cordova 应用程序中创建聊天机器人的示例
在开始实施以下代码之前,请先阅读并清除有关意图、实体、实现的基础知识,然后创建一个代理。
https://dialogflow.com/docs/getting-started/basics
作为您在 cordova 中的项目,下面是快速启动实现 -
使用 Cordova CLI 安装 api.ai 插件:
cordova plugin add cordova-plugin-apiai
在 onDeviceReady[= 函数中添加到您的 index.js 文件(通常在 js 文件夹中) 31=] 以下代码
ApiAIPlugin.init(
{
clientAccessToken: "YOUR_CLIENT_ACCESS_TOKEN", // insert your client access key here
lang: "en" // set lang tag from list of supported languages
},
function(result) { /* success processing */ },
function(error) { /* error processing */ }
);
ApiAIPromises init 方法会将应用程序连接到 "Dialogflow project",它需要一个客户端访问令牌,该令牌在代理设置中可用。
如果您想要发送文本请求,请添加以下代码:
function sendText(query_text) {
try {
ApiAIPlugin.requestText(
{
query: query_text
},
function (response) {
// place your result processing here
alert(JSON.stringify(response));
},
function (error) {
// place your error processing here
alert(error);
});
} catch (e) {
alert(e);
}
}
您可以检查这个 nodejs-dialogflow 库。
这里是GitHub example you can use to get you started and check this link了解更多详情