动作SDK无法正常工作

时间:2018-05-30 09:51:01

标签: google-cloud-functions actions-on-google

我已将index.js更新如下

'use strict';
const functions = require('firebase-functions');
const admin     = require('firebase-admin');
const {actionssdk} = require('actions-on-google');
const app = actionssdk({debug: true});


 exports.dairyProduct = functions.https.onRequest((request, response) => {
    console.log("request-------------->",request);
    console.log("response----------------->",response);

    function handleMainIntent(app) {
        console.log("Inside Main Intent");
        app.ask("Main Indent "+app.getRawInput());
     }
    function handleTextIntent() {
        console.log("Inside Main Intent");
        app.tell("First Text Indent");
    }
    let app = new ActionsSdkApp({request, response});
    let actionMap = new Map();
    console.log("app---------->",app);
    actionMap.set(app.StandardIntents.MAIN, handleMainIntent)
    actionMap.set(app.StandardIntents.TEXT, handleTextIntent);
    app.ask("This sample application is developing by Thirumani Selvam.M ");
    console.log("actionMap---------->",actionMap);
    app.handleRequest(actionMap);
 });

我更新了action.json

    {
  "actions": [
    {
      "description": "Default Welcome Intent",
      "name": "MAIN",
      "fulfillment": {
        "conversationName": "testapp"
      },
      "intent": {
        "name": "actions.intent.MAIN",
        "trigger": {
          "queryPatterns": [
            "Talk to Dairy Product"
          ]
        }
      }
    }
  ],
  "conversations": {
    "testapp": {
      "name": "testapp",
      "url": "https://us-central1-samplejs6-id.cloudfunctions.net/dairyProduct",
      "fulfillmentApiVersion": 2,
      "inDialogIntents": [
        {
          "name": "actions.intent.CANCEL"
        }
      ]
    }
  },
  "locale": "en"
}

我的package.json代码

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "actions-on-google": "^2.0.1",
    "firebase-admin": "~5.12.0",
    "firebase-functions": "^1.0.1"
  },
  "devDependencies": {
    "eslint": "^4.12.0",
    "eslint-plugin-promise": "^3.6.0"
  },
  "private": true
}

我使用“firebase deploy --only functions”进行部署 我使用“gactions update --action_package action.json --project samplejs6-id”更新了操作 我使用“gactions test --action_package action.json --project samplejs6-id”更新了操作测试

我没有在firebase日志中收到错误。 我已经在gactions中将标题和名称更新为“Dairy team”。它建议输入“与乳品团队交谈”。如果我输入“与乳品团队交谈”,我会收到回复,“我们很抱歉,但出了点问题。请再试一次。”

请告诉我,如何解决此问题。提前致谢

1 个答案:

答案 0 :(得分:1)

问题在于您使用的是“action-on-google”库版本2,但您的代码是使用版本1对象和函数编写的。这两个版本之间发生了一些戏剧性的变化。有关如何升级到新版本的详细信息,请参阅migration guide,或将package.json文件更改为使用版本1.