actions-on-google / assistant-conversation-nodejs

A developer friendly way to fulfill Actions SDK handlers for the Google Assistant
https://actions-on-google.github.io/assistant-conversation-nodejs
Apache License 2.0
104 stars 27 forks source link

AWS Lambda API Gateway HTTP proxy integration, don't enter the app.handle #4

Open wesleysima opened 4 years ago

wesleysima commented 4 years ago

I am trying to use a lambda function as a webhook and my handler call is not working. The same code works normally in inline cloud functions in the actions console.

Here is my code in lambda:

`exports.handler = async (event) => {

const { conversation, Image, Card, Simple, Suggestion, List  } = require('@assistant/conversation');

const app = conversation({debug: true});

app.handle('start_conversation', conv => {
  let message = 'A wondrous greeting, adventurer! Welcome to the mythical land of  Gryffinberg! Based on your clothes, you are not from around these lands. It looks like you\'re on your way to an epic journey.';
  if (conv.user.lastSeenTime) {
    message = 'A wondrous greeting, adventurer! Welcome back to the mythical land of Gryffinberg!';
  }
  conv.add(message);
});

exports.fulfillment = app

};`

image

Here is my request json.

{ "requestJson": { "handler": { "name": "start_conversation" }, "intent": { "name": "actions.intent.MAIN", "params": {}, "query": "Falar com o app teste-man" }, "scene": { "name": "actions.scene.START_CONVERSATION", "slotFillingStatus": "UNSPECIFIED", "slots": {}, "next": { "name": "start" } }, "session": { "id": "ABwppHGM0ZY2HN8IoKGqbffg3-EEHCMwFvLj0qPrSnJhk6LC68HXLEcm-Hg2iOxda6312YvzaEsI32dB9y0", "params": {}, "typeOverrides": [], "languageCode": "" }, "user": { "locale": "pt-BR", "params": {}, "accountLinkingStatus": "ACCOUNT_LINKING_STATUS_UNSPECIFIED", "verificationStatus": "VERIFIED", "packageEntitlements": [], "lastSeenTime": "2020-07-31T14:27:51Z" }, "home": { "params": {} }, "device": { "capabilities": [ "SPEECH", "RICH_RESPONSE", "LONG_FORM_AUDIO" ] } } }

kgass commented 4 years ago

I also had problems at setting up the Lambda but with the right API Gateway config it works. Do you recive any request on your Lambda?

wesleysima commented 4 years ago

I also had problems at setting up the Lambda but with the right API Gateway config it works. Do you recive any request on your Lambda?

I get my request in lambda, I can see it in the logs, but it doesn't go into the app.handle.

kgass commented 4 years ago

I also had problems at setting up the Lambda but with the right API Gateway config it works. Do you recive any request on your Lambda?

I get my request in lambda, I can see it in the logs, but it doesn't go into the app.handle.

Try to use only this code and config your API Gateway for /fulfillment

const { conversation, Image, Card, Simple, Suggestion, List  } = require('@assistant/conversation');

const app = conversation({debug: true});

app.handle('start_conversation', conv => {
  let message = 'A wondrous greeting, adventurer! Welcome to the mythical land of  Gryffinberg! Based on your clothes, you are not from around these lands. It looks like you\'re on your way to an epic journey.';
  if (conv.user.lastSeenTime) {
    message = 'A wondrous greeting, adventurer! Welcome back to the mythical land of Gryffinberg!';
  }
  conv.add(message);
});

exports.fulfillment = app
frathi commented 4 years ago

This is how we configured our action to use a lambda deployment (which we deploy with serverless):

ActionsOnGoogleFulfillment.yaml

handlers:
- name: hello
httpsEndpoint:
  baseUrl: https://rhi77819jk0.execute-api.eu-central-1.amazonaws.com/dev/fulfillment/
  endpointApiVersion: 2

handler.ts

import { conversation } from "@assistant/conversation"
import * as Handler from "./src/handler"

const app = conversation()
app.handle("hello", Handler.hello)
app.catch(Handler.errorLogger)
exports.intentHandler = app

serverless.yml

service: google-wdr5-assistant-sdk

provider:
  name: aws
  runtime: nodejs12.x
  region: eu-central-1
  stage: ${opt:stage, 'dev'}
  timeout: 25
  environment:
    STAGE: ${self:provider.stage}

package:
  exclude:
    - "**"
  include:
    - "dist/bundle.js"

functions:
  handler:
    handler: dist/bundle.intentHandler
    events:
      - http:
          path: fulfillment
          method: post

Maybe this snippets help you somehow :-)