Let’s first start by saying how the standard recipe works for provide a fulfillment of an Amazon Alexa Skill and a dialogFlow assistant using Actions on Google.
The common way to deploy an Alexa Skill fulfillment code is to deploy it on an AWS Lambda function, then provide the ARN (Amazon Resource Name) on the Skill dashboard panel.
The same could be said when we want to make use of Google’s environment.
The standard way is to host our fulfillment using the equivalent Firebase set of tools.
But this is not always practical, especially if we wanna have the same Skill working both for the Alexa and Google Assistant enabled devices.
In our case, we begin with developing a Skill that works for Alexa and then we wanted to replicate that using Google devices (in particular a Google Home mini) but didn’t want to maintain (and pay for) 2 separate cloud services. We wanna keep only AWS and use it for both. In a phrase, to have the best of both worlds!
As you can see from the Fulfillment Webhook on Google’s dialogFlow when you want to host your function using a cloud service the recommended step is to deploy your code using a Firebase Function, but since we wanted to use just AWS the trick is to mask one of that using another service from AWS called API Gateway, since you can’t just place an ARN (Amazon Resource Name) since a URL is mandatory.
We assumed that you have your AWS Lambda function deployed and ready.
We’ve been using the NodeJS actions-on-google SDK to build rich-responses and simplify the process of creating JSON responses. More info here: https://github.com/actions-on-google/actions-on-google-nodejs
Remember that you have to place at the bottom of your lambda function this piece of code where app is the NodeJS action-on-google import package.
Here are the steps:
- Go to the API Gateways on AWS services https://console.aws.amazon.com/apigateway/home and create a new API.
- Then click on the “Actions” button and create a POST method (since this is the one used by Google) and select a previously created Lambda function from the dropdown.
- Proceed to give permission for the Lambda function to be accessible.
- Click on the Create Resource from the Actions button, and type a descriptive name (in our example, we typed fulfillment), and the click on “Create Resource”.
- Then we’ll have to create a POST method for the resource
- Then we’ll have to click on the “Deploy API” button so its available.
- After that it opens up the Deploy API dialog. We put as Deployment Stage the default “[New Stage]” and leave out the Stage name as “beta”. You can leave the other fields as blanks.
- Copy the API URL that you just obtained from deploying.
- Head back to the dialogFlow site where you have configured your project https://console.dialogflow.com and place the above API Gateway link into the URL field.
- That’s it! Hope that this helps you. Happy coding!