metriasfenx.blogg.se

Api . ai actions
Api . ai actions










  1. Api . ai actions how to#
  2. Api . ai actions code#

Here we allow the user to find another bus if the want. Would you like to find another?”)Īsk is used when you want the microphone to be left open. The other function is ask assistant.ask(“The next ” + busNumber + “ will arrive in “ + prd.prdctdn + “ minutes. Since the bus is here, the person should run out and we should just close their microphone. Tell is used when you want to immediately close the microphone after it is done speaking. The first is tell assistant.tell(“Quick, the “ + busNumber + “ is here!”) Here we see two more uses of the ApiAiAssistant. findBus loops through all the results until it finds a bus that is heading the right direction. parseData does exactly that and just reads in the JSON, returning that there are no busses found for any errors or if the API simply does not return any predictions for the next bus arrival. We also get a first look at our ApiAiAssistant with grabbing our arguments var busNumber = assistant.getArgument(‘busnumber’) var busDirection = assistant.getArgument(‘direction’).toLowerCase() Here we are using default http package provided by node to handle parsing the JSON response. In function responseHandler we do our setup of hitting the CTA’s API. For now we will hardcode the bus stop but in our next lesson we’ll add finding our devices location to get bus stop closest. All you need to do is input your apiKey and a default bus stop and it should be good to go.

Api . ai actions how to#

(Please Note: I am not a javascript developer so feel free to tell me how to improve these). Create any bucket and set the function to execute as “findBus”.įor the source I’ve provided both our index.js and package.json files in a gist.

api . ai actions

Our trigger needs to be an HTTP trigger and you should get a URL. (As a note: the Google Home will only wait about 5 seconds for a response so we need to make sure our requests are fast).

api . ai actions

The default 256mb of memory should be more than enough and the 60 second timeout is perfect. So let’s go ahead and setup our endpoint.įirst pick any name for your route, and if you would like you can choose to change the region. This allows us to upload our node script and get up to 2 million requests for free. I found that the Google Cloud Platform works perfectly for this, specifically the Google Cloud Functions feature. Next up we need somewhere to host our script. Be sure to take note of the provided CTA apikey after you sign up as you will need that for the code.

Api . ai actions code#

This tutorial should work with minor tweaks for other transit systems but my code will use the CTA. As a Chicagoan I am going to use the Chicago Transit Authority’s Bus Tracker API. It provides helpful tools for parsing arguments and letting the action know how to respond.įirst we need to set up a few things.

api . ai actions api . ai actions

The ApiAiAssistant is a Node.js plugin that allows you to simplify building reading and sending back data with API.AI. The requirements for how the data going in and out should look can be seen here but were going to use a helpful tool provided by Google called the ApiAiAssistant. If not, head back there and get started creating, or if you just want to learn how to do webhooks with API.AI, this is the place to start.Ī webhook is a tool to allow you to link your conversation action to an API and have it provide the results for the conversation. Hopefully you’ve read my last entry about setting up a conversation action.












Api . ai actions