首页 > 解决方案 > 动作 SDK 不工作

问题描述

我已经更新了我的 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 函数”进行部署 我已经使用“gactions update --action_package action.json --project samplejs6-id”更新了操作 我已经使用“gactions test --action_package action.json”更新了操作测试 - -项目样本js6-id"

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

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

标签: google-cloud-functionsactions-on-google

解决方案


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


推荐阅读