Making POST requests in google actions without Inline Cloud Functions - actions-on-google

I want to make a simple post request in google actions to a self hosted web server and I cant seem to figure out how to do that. I cant find much in the documentation and I dont have access to inline cloud functions either.

What you're looking for is sometimes known as a webhook or a handler or handling fulfillment in the documentation.
You'll configure the overall Action with a single webhook URL. For specific Intents (in Dialogflow) or as part of a Handler when in a scene in Action Builder, you can specify when the webhook should be called. It will be called with a JSON body that is specific to Actions on Google (and differs if you're using Action Builder or Dialogflow) and expects a JSON response in a specific format.
For details about all of this, consult the documentation for webhooks in either Action Builder or Dialogflow.

Related

Dynamically create skills for Actions on Google via an exposed API?

Is there an API exposed for Actions on Google, similar to what Dialogflow offers with their API? The only API-like flow I have found through my research is this webhook flow API, but that only deals with conversation requests, prompts, and responses, which I have already handled.
Ideally I'd like to be able to dynamically create "agents" and their conversation flows without having to use the AoG console, similar to what Amazon offers with Alexa SMAPI.
There's not a full API to do everything that you want end-to-end. Some parts, like Dialogflow and fulfillment, can be automated, but it will still require some manual work in the Actions Console.
I had a conversation with another developer on this subject once. As a workaround, which is admittedly hacky, they decided to use the Puppeteer library to programmatically control a browser instance to fill in fields and click buttons.
That may not necessarily work when the console changes, and isn't a good substitute for an API, but it may work for you.
Yes you can do it using Google Dialogflow REST API
Here are APIs for the agent :
There are many more APIs available for different operations.

DialogFlow Fulfilment connecting to REST APIs

I want to use Dialogflow fulfillment to connect to an external webservice / API. One way of doing that is to use the custom webhook feature (not the inline web hook). However, when using the custom web hook it seems that you are limited to creating just one even though you may have many intents and you may want to call many endpoints. Is there a way to link to more custom webhooks (API endpoints)?
If you can only set up one web hook then your webserivce will always receive a Post request from Dialogflow and will then need to interpret the body of the request i.e. based on the intent parameter. Just wondering is there a better way to work with REST webservices with Dialogflow.
The other potential option is to use the inline web hook and then put logic in there to call specific endpoints, however, that might get a bit messy.
You can only setup one fulfillment that will handle the processing for all the Intents you've enabled. This can be either the built-in one through the fulfillment editor or at a webhook URL you specify.
That webhook is expected to delegate the actual processing to an Intent Handler of some sort. The Dialogflow node.js fulfillment library has a way to register what handler you want for each Intent name, or you can switch on the Intent name, the Action name, or any other field provided to you in your code.
In the library, you'll typically make the REST calls from an appropriate Intent handler which will take the parameters provided and craft the call. If you are using Javascript, make sure you are handling the call asynchronously and return a Promise.
I recommend a webhook because it gives you more control than the inline editor does. The inline editor is really just a webhook under the covers using Firebase Cloud Functions. Even putting it yourself in a Cloud Function gives you better control over it.
There may be costs depending where you host it, however Firebase has a free tier that is sufficient for testing and light operation. Once your Action is published, you are also eligible for a monthly cloud credit from Google.

Integration of dialogflow and google actions

I am trying to integrate with google assistant/google home using Dialogflow and we are hitting some issues.
The issue is the following.
I have a google actions project that I have created which is linked to a corresponding dialogflow project. I have enabled the v2 APIs on both the dialogflow project and the integration of the dialogflow project and the google actions project.
The dialogflow project has intents that call a webhook for fulfillment. We have a service setup that responds to the webhook APIs. This service returns responses in V2 format including rich messages (like card, quick_replies, and carousel_select) under the key fulfillmentMessages:
However it appears that when dialogflow forwards this information to the google actions, it is not passing any of this information. On the other hand if I include a key called fulfillMentText in my service response, then dialogflow will forward that information to google actions as
[{"simpleResponse":{"textToSpeech":"Nice to meet you, Bob!"}}]}
It is not clear to me based on reading available docs, what I need to do so that dialogflow will also propagate the contents of fulfillmentMessages to google actions.
Thank you in advance.
The message objects for Actions on Google are different than the generic ones available for the other platforms Dialogflow supports. You need to also send the Actions on Google compatible messages in order to have them visible for the Assistant.
If you're using the dialogflow-fulfillment library, you can import the actions-on-google objects and add them to to the response and the library will handle them.
Don't worry about mixing the rich media types - only those that are appropriate for each platform will show.

Retrieve Google Smart Home events in Dialogflow fulfillment service

I am trying to forward Google Smart Home events to my Dialogflow fulfillment service. I am creating 3 intents with no input or output contexts set, no training phases and with the following events:
action_devices_SYNC
action_devices_EXECUTE
action_devices_QUERY
See also https://imgur.com/a/4eN9S.
Is that correct? I can't find confirmation in the docs, so that's why I am asking it here.
reasoning
The reason why I asked about connecting Google Smart Home with my Dialogflow endpoint is that I already have that endpoint in place. I hoped I could do something similar as in https://stackoverflow.com/a/49119822/9038652, where I bound a Dialogflow intent to the actions_intent_OPTION event.
There isn't a reason to use Dialogflow to do smart home fulfillment, and it's actually not possible.
Dialogflow is great for taking unstructured user utterances and making sense of them. However, with smart home, Google handles all of the NLU and parsing. You, as the integration, will just receive a JSON request and will be expected to provide a JSON response.
So you will skip using Dialogflow and instead just build your webhook to parse the intents and give a valid response.
Dialogflow's service does not have a way to take in an intent name and expose a single endpoint URL that can be called by the Google Assistant. It also does not have integration with an OAuth server to do the account linking step.

Dialogflow: when to use response.json() vs DialogflowApp

I started writing a dialogflow fulfillment extending https://dialogflow.com/docs/getting-started/basic-fulfillment-conversation. They don't use DialogflowApp and just call response.json().
However, I also found https://developers.google.com/actions/reference/nodejs/DialogflowApp where fulfillment is done with the DialogflowApp.
When do you use each? and why does the Dialogflow Key Concepts and Basic Fulfillment document not mention to DialogflowApp at all?
The first route (sending response directly) doesn't seem to have a way to deal with permissions and push/daily notifications, while DialogflowApp does.
Will the documentation for sending responses directly be extended to handle permissions? What is the best practice?
Thanks.
If you're using Actions on Google, go with the Actions on Google client library and DialogflowApp. This only supports Actions on Google.
If you are using other integrations that work with Dialogflow, such as Slack, then you should use the fulfillment library and documentation provided by Dialogflow.