简体   繁体   English

如何为Google Assistant(Google Home)包装现有的聊天机器人

[英]How to wrap an existing chatbot for Google Assistant (Google Home)

We have a chatbot for our website today, that is not build using Google technology. 今天,我们的网站有一个聊天机器人,它不是使用Google技术构建的。 The bot has a JSON REST API where you can send the question to and which replies with the corresponding answers. 该机器人具有JSON REST API,您可以在其中将问题发送到,并用相应的答案进行答复。 So all the intents and entities are being resolved by the existing chatbot. 因此,所有的意图和实体都将由现有的聊天机器人来解决。

What is the best way to wrap this functionality in Google Assistant / for Google Home? 在Google Assistant / Google Home中包装此功能的最佳方法是什么?

To me it seems I need to extract the "original" question from the JSON that is send to our webservice (when I enable fullfilment). 对我来说,我似乎需要从发送到我们的Web服务的JSON中提取“原始”问题(启用全功能时)。

But since context is used to exchange "state" I have to find a way to exchange the context between the dialogflow and our own chatbot (see above). 但是由于上下文是用来交换“状态”的,所以我必须找到一种方法在对话框流和我们自己的聊天机器人之间交换上下文(见上文)。

But maybe there are other ways ? 但是也许还有其他方法? Can it (invoke our chatbot) be done directly (without DialogFlow as man in the middle) ? 是否可以直接完成(调用我们的聊天机器人)(中间没有DialogFlow)?

This is one of the those responses that may not be enough for someone who doesn't know what I am talking about and too much for someone who does. 对于那些不知道我在说什么的人来说,这可能是不够的,而对于那些知道我的人来说,这是太多的。 Here goes: 开始:

It sounds to me as if you need to build an Action with the Actions SDK rather than with Dialog flow. 在我看来,您似乎需要使用Actions SDK而不是Dialog flow来构建Action。 Then you implement a text "intent" in your Action - ie one that runs every time the user speaks something. 然后,在您的操作中实现一个文本“意图”-即在用户每次说话时都会运行的文本。 In that text intent you ask the AoG platform for the text - see getRawInput(). 在该文本意图中,您要求AoG平台提供文本-请参见getRawInput()。 Now you do two things. 现在您要做两件事。 One, you take that raw input and pass it to your bot. 第一,您获取原始输入并将其传递给您的机器人。 Two, you return a promise to tell AoG that you are working on a reply but you don't have it yet. 第二,您返回一个承诺,告诉AoG您正在处理回复,但还没有。 Once the promise is fulfilled - ie when your bot replies - you reply with the text you got from your bot. 兑现诺言后(即当您的漫游器回复时),您将使用从漫游器获得的文本进行回复。

I have a sample Action called the French Parrot here https://github.com/unclewill/french_parrot . 我在https://github.com/unclewill/french_parrot中有一个名为“法国鹦鹉”的动作示例。 As far as speech goes it simply speaks back whatever it hears as a parrot would. 就言语而言,它只是说出什么,就像鹦鹉会听到的一样。 It also goes to a translation service to translate the text and return the (loose) French equivalent. 它还会去翻译服务来翻译文本并返回(松散的)法语等效内容。

Your mission, should you choose to accept it, is to take the sample, rip out the code that goes to the translation service and insert the code that goes to your bot. 您的任务(如果您选择接受它)是获取示例,提取去往翻译服务的代码,然后插入去往机器人的代码。 :-) :-)

Two things I should mention. 我应该提到两件事。 One, it is not "idiomatic" Node or JavaScript you'll find in my sample. 第一,它不是我的示例中发现的“惯用”节点或JavaScript。 What can I say - I think the rest of the world is confused. 我能说什么-我认为世界其他地方感到困惑。 Really. 真。 Two, I have a minimal sample of about 50 lines that eschews the translation here https://github.com/unclewill/parrot . 第二,我有大约50行的最少样本,可以在这里避开翻译https://github.com/unclewill/parrot Another option is to use that as a base and add code to call your bot and the Promise-y code to wait on it to it. 另一个选择是将其用作基础并添加代码以调用您的机器人,并添加Promise-y代码以对其进行等待。

If you go the latter route remove the trigger phrases from the action package (action.json). 如果走后一条路线,请从操作包(action.json)中删除触发短语。

So you already have a Backend that process user inputs and sends responses back and you want to use it to process a new input flow (coming from Google Assistant)? 因此,您已经拥有一个可以处理用户输入并发送回响应的后端,并且您想使用它来处理新的输入流(来自Google助手)?

That actually my case, I've a service as a Facebook Messenger ChatBot and recently started developing a Google Home Action for it. 实际上,我的情况是,我有一个Facebook Messenger ChatBot服务,最近开始为其开发Google Home Action。

It's quite simple. 这很简单。 You just need to: 您只需要:

  { "locale": "en", "actions": [ { "name": "MAIN", "description": "Default Welcome Intent", "fulfillment": { "conversationName": "app name" }, "intent": { "name": "actions.intent.MAIN", "trigger": { "queryPatterns": [ "Talk to app name" ] } } } ], "conversations": { "app name": { "name": "app name", "url": "https://your_nodejs_middleware.com/" } } } 
 //require express and all required staff to build a Node.js server, //look on internet how to build a simple web server in Node.js //if you a new to this domain. const { ActionsSdkApp } = require('actions-on-google'); app.post('/', (req, res) => { req.body = JSON.parse(req.body); const app = new ActionsSdkApp({ request: req, response: res }); // Create functions to handle requests here function mainIntent(app) { let inputPrompt = app.buildInputPrompt(false, 'Hey! Welcome to app name!'); app.ask(inputPrompt); } function respond(app) { let userInput = app.getRawInput(); //HERE you get what user typed/said to Google Assistant. //NOW you can send the input to your BACKEND, process it, get the response_from_your_backend and send it back app.ask(response_from_your_backend); } let actionMap = new Map(); actionMap.set('actions.intent.MAIN', mainIntent); actionMap.set('actions.intent.TEXT', respond); app.handleRequest(actionMap); }); 

Hope that helped! 希望能有所帮助!

Thanks for all the help, the main parts of the solution are already given, but I summarize them here 感谢所有帮助,已经给出了解决方案的主要部分,但是我在这里总结一下

  • action.json that passes on everything to fullfilment service action.json ,将所有内容传递给fullfilment服务
  • man in the middle (in my case IBM Cloud Function ) to map JSON between services 中间的人(在我的情况下为IBM Cloud Function )在服务之间映射JSON
  • Share context/state through the conversationToken property 通过对话令牌属性共享上下文/状态

You can find the demo here: Hey Google talk to Watson 您可以在此处找到该演示: 嘿Google与Watson交谈

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM