简体   繁体   中英

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. The bot has a JSON REST API where you can send the question to and which replies with the corresponding answers. 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?

To me it seems I need to extract the "original" question from the JSON that is send to our webservice (when I enable fullfilment).

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) ?

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. 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(). 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. 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 . 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. 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 . 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.

If you go the latter route remove the trigger phrases from the action package (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)?

That actually my case, I've a service as a Facebook Messenger ChatBot and recently started developing a Google Home Action for it.

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
  • man in the middle (in my case IBM Cloud Function ) to map JSON between services
  • Share context/state through the conversationToken property

You can find the demo here: Hey Google talk to Watson

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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