0

I'm testing Actions for Google, so I created some simple Sinatra application which looks something like:

    require 'sinatra'
    require 'json'

    post '/google_assistant_api' do
      content_type :json

      case intent_name
      when "input_welcome"
        decorated_response
      when "Recipe name"
        basic_card
      end
    end

    private

      def decorated_response
        {
          source: "test source",
          speech: "speech",
          display_text: "something"
        }.to_json
      end

      def intent_name
        parsed_request["queryResult"]["intent"]["displayName"]
      end

      def parsed_request
        @parsed_request ||= JSON.parse(request.body.read)
      end

      def basic_card
       {
         "fulfillmentText": "ACTIONS_ON_GOOGLE",
         "fulfillmentMessages": [
           {
             "platform": "PLATFORM_UNSPECIFIED",
             "text": {
               "text": [
                 "string text"
               ]
             },
             "image": {
               "imageUri": "https://avatars3.githubusercontent.com/u/119195?
s=400&v=4"
             },
             "basicCard": {
               "title": "title string",
               "subtitle": "subtitle",
               "formattedText": "formatted text",
               "image": {
                 "imageUri": "https://avatars3.githubusercontent.com/u/119195"
               },
               "buttons": []
             }
           }
         ],
         "source": "source string"
       }.to_json
      end

Please note that I'm using V2 of the API and testing using google assistant:

enter image description here

I tried many other response formats based on https://gist.github.com/manniru/f52af230669bd3ed2e69ffe4a76ab309 with no luck. I keep getting:

Sorry! there was no response from the Agent. Please try later.

enter image description here

Is there anyone who tried non nodejs response with luck? I would appreciate any sample response as the simple response seems to be working, however as for the basic card I'm having no luck.

Eki Eqbal
  • 5,779
  • 9
  • 47
  • 81

1 Answers1

1

Dialogflow's v2 API uses a different format for webhook requests and responses which is documented here:

  1. Dialogflow v2 Webhook Request
  2. Dialogflow v2 Webhook Response

It appears that your code is using the old format.

mattcarrollcode
  • 3,429
  • 16
  • 16
  • Thanks, my issue with the response part. I used the response as described in the official document but still getting the same issue. I used https://gist.github.com/eqbal/311e775946543ad25319ce9a64578da6. Do you have any working sample response that you tried? – Eki Eqbal Dec 13 '17 at 20:11
  • 2
    Please update your question with the v2 response you reference in your gist. You need to change `platform` from `PLATFORM_UNSPECIFIED` to `ACTIONS_ON_GOOGLE ` as documented here [0] to work with the Google Assistant. You'll also need to use Action on Google responses described here [1] which include `simpleResponses`, `basicCard`, `suggestions`, `linkOutSuggestion`, `listSelect`, and `carouselSelect`. [0] https://dialogflow.com/docs/reference/api-v2/rest/v2beta1/projects.agent.intents#Platform [1]https://dialogflow.com/docs/reference/api-v2/rest/v2beta1/projects.agent.intents#Message – mattcarrollcode Dec 13 '17 at 20:13
  • Thanks for your detailed response here. I updated `platform` and I'm still getting the same response. the action triggers the webhook api but looks like it never reach `dialogflow`. Do you have a sample working example so I can use as a starting point? – Eki Eqbal Dec 13 '17 at 20:51
  • I'm experiencing a similar issue (see https://stackoverflow.com/questions/48211405/what-json-response-format-to-use-for-v2beta1-fulfillment-webhook), where the #2 page you give (Dialogflow v2 Webhook Response) does not mention the "speech" field as per my error message "Cannot find field: speech in message google.cloud.dialogflow.v2beta1.WebhookResponse". Can you (@matthewayne) shed any light on this? – Colin G Jan 11 '18 at 16:32