google-cloud-functions - 动作 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 交谈”,我收到的回复是“我们很抱歉,但出了点问题。请再试一次。”
请告诉我,如何解决这个问题。提前致谢
解决方案
问题是您使用的是“actions-on-google”库版本 2,但您的代码是使用版本 1 的对象和函数编写的。两个版本之间发生了一些戏剧性的变化。有关如何升级到新版本的详细信息,请参阅迁移指南,或将 package.json 文件更改为使用版本 1。
推荐阅读
- javascript - 单元组件未在 React 中重新渲染
- java - 如何在 addToSet 运算符中指定用于确定要添加的文档是否重复的键?
- bash - 在 GNU 并行中提取特定路径组件
- nginx - 自定义编译后未安装 Nginx 第三方模块指令
- reactjs - 在未使用的文件中检测到错误时如何防止出现 React 错误覆盖
- python - 背景图像在 CSS 上模糊/像素化
- windows - 如何更改 Brave/Chrome for Windows 上的窗口框架边框宽度?
- linkedin - 如何通过 LinkedIn API 获取学习者进度和所有 LinkedIn 学习路径(包括自定义路径)的课程/视频列表
- javascript - 需要导入一个普通的 javascript 文件来做出反应
- javascript - Javascript 中 Azure Functions (v2.0) 的 VS Code 本地调试:如何仅显示我的 console.log() 消息?