无法使用 ActionsSDK 设置 actions-on-google 示例

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

我正在尝试使用以下示例设置助手应用 https://github.com/actions-on-google/actionssdk-say-number-nodejs。我可以看到助手应用端点工作正常,因为我取回了我在代码中配置的响应。 但是当我回复主要意图的问题时,对话没有到达我的 API

这是例子,它显示了什么

I found few places within 7.8 miles 不是从我的 API 发送的。我错过了什么吗?我使用 express.js.

修改了代码以使其作为 nodejs 应用程序工作

这是代码

# 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}`); 

这是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
    }
  }
}

我是 运行 和 node index.js 的 node.js 并且我将它反向代理到 https://<myownsite>.xyz/googleBot 当我发出 Curl 请求时它工作得很好。

请求

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"}]}]}'

当我使用 Curl 时,我收到回复说“你说的是 12”。

回应

{"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"}]}]} 

那么,我是不是漏掉了什么?

更新

这是来自模拟器请求和响应选项卡的信息(在右侧)

请求

{
  "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": []
}

回应

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."

更新2

请求 根据评论

中的要求与 actions.intent.TEXT 一起发布欢迎消息
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": [ ] } ] }'

回应

Action Error: no matching intent handler for: null

主要意图请求 .

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"}]}]}'

回应

{"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"}]}]}

所以我重建你的案例我只是使用 webstorm 的 nodejs express 样板而不是精确的你的代码。

我修复了内部的一些问题,所以这个 github 可以正常工作:voice google home action boilerplate

如果您有任何问题,请尽管提问。

我只有欢迎意图而没有其他意图的唯一一点是当我创建了所有内容但忘记在更新 action.json 操作控制台后单击 google 操作控制台中的更改版本] 和 运行 gaction.exe:

在我修复之后,我的服务器出现了很多错误 500,直到我更改了行

 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.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>');

在此之后我不得不修复一些由我自己引起的错误,现在一切正常。

更新: 所以最后问题是通过使用另一个google帐户解决的。可能是某些 google 云权限设置的原因。不太确定。但如果有人有同样的问题,请检查您的权限和帐户规则。

经过几天的斗争和@shortQuestion 的帮助,我们终于得出结论,这个问题是因为一些权限问题。结果我使用 google 企业电子邮件,而我们的管理员没有启用少数 Activity Controls,尤其是 Web & App Activity。只需在 https://myaccount.google.com/activitycontrols 中打开 Web & App Activity 并让您的管理员为 you/all 需要访问助手测试的人启用网络和应用程序 activity。

太糟糕了,Google 没有在任何时候抛出这个错误。