rrmerugu
rrmerugu

Reputation: 1896

Not able to setup actions-on-google sample using ActionsSDK

I'm trying to setup an assistant app with the following example https://github.com/actions-on-google/actionssdk-say-number-nodejs . I can see that the assistant app endpoint is working fine, because I get back the response I configured to it in my code. But the conversation is not reaching my API, when I reply back to the MAIN intent's question.

Here is the example, whats it is showing enter image description here

I found few places within 7.8 miles is not sent from my API. Am I missing something? I modified the code to make it work as nodejs app using express.js.

Here are the codes

# index.js
'use strict';

process.env.DEBUG = 'actions-on-google:*';
const ActionsSdkApp = require('actions-on-google').ActionsSdkApp;
const express = require('express');
var bodyParser = require('body-parser');

// Constants

// App
const expressApp = express();

expressApp.use(bodyParser.urlencoded({ extended: true }));
expressApp.use(bodyParser.json());
var port = process.env.PORT || 5000;        // set our port
const HOST = '0.0.0.0';

var router = express.Router();

const NO_INPUTS = [
  'I didn\'t hear that.',
  'If you\'re still there, say that again.',
  'We can stop here. See you soon.'
];

function process_request(request, response) {
//exports.sayNumber = functions.https.onRequest((request, response) => {
  const app = new ActionsSdkApp({request, response});

  function mainIntent (app) {
    console.log('mainIntent');
    let inputPrompt = app.buildInputPrompt(true, '<speak>Hi! <break time="1"/> ' +
      'I can read out an ordinal like ' +
      '<say-as interpret-as="ordinal">123</say-as>. Say a number.</speak>', NO_INPUTS);
    app.ask(inputPrompt);
  }

  function rawInput (app) {
    console.log('rawInput');
    if (app.getRawInput() === 'bye') {
      app.tell('Goodbye!');
    } else {
      let inputPrompt = app.buildInputPrompt(true, '<speak>You said, <say-as interpret-as="ordinal">' +
        app.getRawInput() + '</say-as></speak>', NO_INPUTS);
      app.ask(inputPrompt);
    }
  }

  let actionMap = new Map();
  actionMap.set(app.StandardIntents.MAIN, mainIntent);
  actionMap.set(app.StandardIntents.TEXT, rawInput);

  app.handleRequest(actionMap);
};

router.get('/googleBot', function(req, res) {
    console.log("received a get request");
    process_request(req, res)
});
router.post('/googleBot', function(req, res) {
    console.log("received a post request");
    process_request(req, res)
});


expressApp.use('/', router);

expressApp.listen(port, HOST);
//console.log(`Running on http://${HOST}:${PORT}`); 

Here is the action.json

# action.json
{
  "actions": [
    {
      "description": "Default Welcome Intent",
      "name": "MAIN",
      "fulfillment": {
        "conversationName": "conversation_1"
      },
      "intent": {
        "name": "actions.intent.MAIN"
      }
    }
  ],
  "conversations": {
    "conversation_1": {
      "name": "conversation_1",
      "url": "https://<myownsite>.xyz/googleBot",
      "fulfillmentApiVersion": 2
    }
  }
}

I'm running the node.js with node index.js and I have it reverse proxied to https://<myownsite>.xyz/googleBot it works great when I made Curl request.

Request

curl -X POST  -H "Content-Type: application/json"  -H "Google-Actions-API-Version: 2" https://mysitexxx.com/googleBot -d '{"user":{"userId":"<hidden for obvious reasons>","locale":"en-US","lastSeen":"2017-12-11T09:22:58Z"},"conversation":{"conversationId":"1512984211990","type":"NEW"},"inputs":[{"intent":"actions.intent.TEXT","rawInputs":[{"inputType":"KEYBOARD","query":"12"}]}],"surface":{"capabilities":[{"name":"actions.capability.AUDIO_OUTPUT"},{"name":"actions.capability.SCREEN_OUTPUT"}]},"isInSandbox":true,"availableSurfaces":[{"capabilities":[{"name":"actions.capability.AUDIO_OUTPUT"},{"name":"actions.capability.SCREEN_OUTPUT"}]}]}'

and I get back response saying " You said 12" when I use Curl.

Response

{"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":true,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"ssml":"<speak>You said, <say-as interpret-as=\"ordinal\">12</say-as></speak>"}],"noInputPrompts":[{"ssml":"I didn't hear that."},{"ssml":"If you're still there, say that again."},{"ssml":"We can stop here. See you soon."}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]} 

So, am I Missing something here ?

UPDATE

Here is the information from request and response tabs of simulator(on the right side)

Request

{
  "request": {
    "conversationToken": "",
    "debugLevel": 1,
    "inputType": "KEYBOARD",
    "locale": "en-US",
    "mockLocation": {
      "city": "Mountain View",
      "coordinates": {
        "latitude": 37.421980615353675,
        "longitude": -122.08419799804688
      },
      "formattedAddress": "Googleplex, Mountain View, CA 94043, United States",
      "zipCode": "94043"
    },
    "query": "Talk to my test app",
    "surface": "PHONE"
  },
  "response": {},
  "debug": {},
  "errors": []
}

Response

this part is null; I don't see anything, but still simulator UI says "Hi! I can read out an ordinal number like 123. Speak or say a number."

UPDATE2

request Welcome message posted with actions.intent.TEXT as requested in the comments

curl -X POST  -H "Content-Type: application/json"  -H "Google-Actions-API-Version: 2" https://mysitexyz.com/googleBot -d '{ "conversationToken": "{}", "expectUserResponse": true, "expectedInputs": [ { "inputPrompt": { "initialPrompts": [ { "textToSpeech": "<speak>Welcome</speak>" } ], "noInputPrompts": [] }, "possibleIntents": [ { "intent": "actions.intent.TEXT" } ], "speechBiasingHints": [ ] } ] }'

response

Action Error: no matching intent handler for: null

Request with MAIN intent .

curl -X POST  -H "Content-Type: application/json"  -H "Google-Actions-API-Version: 2" https://mysitezyx.com/googleBot -d '{"user":{"userId":"<hidden for obvious reasons>","locale":"en-US","lastSeen":"2017-12-11T09:22:58Z"},"conversation":{"conversationId":"1512984211990","type":"NEW"},"inputs":[{"intent":"actions.intent.MAIN","rawInputs":[{"inputType":"KEYBOARD","query":"Welcome"}]}],"surface":{"capabilities":[{"name":"actions.capability.AUDIO_OUTPUT"},{"name":"actions.capability.SCREEN_OUTPUT"}]},"isInSandbox":true,"availableSurfaces":[{"capabilities":[{"name":"actions.capability.AUDIO_OUTPUT"},{"name":"actions.capability.SCREEN_OUTPUT"}]}]}'

response

{"conversationToken":"{\"state\":null,\"data\":{}}","expectUserResponse":true,"expectedInputs":[{"inputPrompt":{"initialPrompts":[{"ssml":"<speak>Hi! <break time=\"1\"/> I can read out an ordinal number like <say-as interpret-as=\"ordinal\">123</say-as>. Speak or say  a number.</speak>"}],"noInputPrompts":[{"ssml":"I didn't hear that."},{"ssml":"If you're still there, say that again."},{"ssml":"We can stop here. See you soon."}]},"possibleIntents":[{"intent":"actions.intent.TEXT"}]}]}

Upvotes: 0

Views: 773

Answers (2)

rrmerugu
rrmerugu

Reputation: 1896

After a couple of days of struggle and help form @shortQuestion, we have finally come to a conclusion that this issue is because of some permission issue. And turns out I use google business email and our admin didn't enable few Activity Controls especially Web & App Activity. Just turn on Web & App Activity in https://myaccount.google.com/activitycontrols and ask your admin to enable the Web & App activity for you/all the people who need access to assistant test.

Too bad that Google didn't throw this error at any point of time.

Upvotes: 0

shortQuestion
shortQuestion

Reputation: 493

So I rebuild your case I just use the nodejs express boilerplate from webstorm instead of exact your code.

I fixed some problems inside so this github is working: voice google home action boilerplate

If you have questions just ask.

The only point where i had only the welcome intent but not the other intents working was when i created everything b ut forgot to click on change version in google action console after i updated the action.json and run gaction.exe:

update action json version

After I fixed that i got a lot of error 500 from my server until i changed the line

 app.buildInputPrompt(true, '<speak>Hi! <break time="1"/> ' +
      'I can read out an ordinal like ' +
      '<say-as interpret-as="ordinal">123</say-as>. Say a number.</speak>', NO_INPUTS);

to

 app.buildInputPrompt(false, '<speak>Hi! <break time="1"/> ' +
      'I can read out an ordinal like ' +
      '<say-as interpret-as="ordinal">123</say-as>. Say a number.</speak>');

After this i had to fix some bugs caused by myself and now is all working.

Update: So the problem in the end was solved by using another google account. Probably cause of some google cloud permission settings. Not fully sure with it. But if some have same problems, checkout your permissions and accout rules.

Upvotes: 1

Related Questions