JISHNU T U
JISHNU T U

Reputation: 186

how to use 'actions-on-google' libray in aws lambda

In actions-on-google , both the request and response object need to provide as input to this library. but in lambda function, only the request object exists.

So how can i override it ?

in aws lambda the format is

exports.handler = function (event, context, callback) { // event is the request object , the response is provided using the callback() functon 
}     

the actions-on-google object is created as :

const DialogflowApp = require('actions-on-google').DialogflowApp;
const app = new DialogflowApp({ request: request, response: response });

Upvotes: 3

Views: 2391

Answers (2)

Jan König
Jan König

Reputation: 440

To get a Google Action to work on AWS Lambda, you need to do 2 things:

  • Code your app in a way that it's executable on Lambda
  • Create an API Gateway to your Lambda Function which you can then use for Dialogflow Fulfillment

I believe the first setp can't be done off-the-shelf with the Actions SDK. If you're using a framework like Jovo, you can create code that works for both Amazon Alexa and Google Assistant, and host it on AWS Lambda.

You can find a step by step tutorial about setting up a "Hello World" Google Action, host it on Lambda, and create an API Gateway here: https://www.jovo.tech/blog/google-action-tutorial-nodejs/

Disclaimer: I'm one of the founders of Jovo. Happy to answer any further questions.

Upvotes: 3

shortQuestion
shortQuestion

Reputation: 493

This is only a half answer: Ok, so I dont think I can tell you how to make the action on google sdk correct working on AWS Lambda. Maybe its easy, I just dont know and need to read everything to know it.

My, "easy to go", but at the end you will maybe have more work solution, would be just interprete the request jsons by yourself and responde with a message as shown below

This here would be a extrem trivial javascript function to create a extrem trivial JSON response.

Parameters: Message is the string you would like to add as answer. Slots should be an array that can be used to bias the speech recognition. (you can just give an empty array to this function if you dont want to bias the speech).

And State is any kind of serilizable javascript object this is for your self to maintain states or something else It will be transfered between all the intents.

This is an standard response on an speech request. You can add other plattforms than speech for this, by adding different initial prompts please see the JSON tabs from the documentation: https://developers.google.com/actions/assistant/responses#json

function answerWithMessage(message,slots,state){
      let newmessage = message.toLowerCase();
      let jsonResponse = {
            conversationToken: JSON.stringify(state),
            expectUserResponse: true,
            expectedInputs: [
                {
                    inputPrompt: {
                        initialPrompts: [
                            {
                                textToSpeech: newmessage
                            }
                        ],
                        noInputPrompts: []
                    },
                    possibleIntents: [
                        {
                            intent: "actions.intent.TEXT"
                        }
                    ],
                  speechBiasingHints: slots
                }
            ]
        };
      return JSON.stringify(jsonResponse,null, 4);
    }

Upvotes: 1

Related Questions