动作 SDK 不工作
action SDK not working
我已经更新了我的 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"。建议输入 "Talk to Dairy team" 。如果我输入 "Talk to Dairy team" ,我得到的响应是 "We're sorry, but something went wrong. Please try again."
请告诉我如何解决此问题。提前致谢
问题是您使用的是 "actions-on-google" 库版本 2,但您的代码是使用版本 1 的对象和函数编写的。两个版本之间发生了一些戏剧性的变化。有关如何升级到新版本或更改 package.json 文件以使用版本 1 的详细信息,请参阅 migration guide。
我已经更新了我的 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"。建议输入 "Talk to Dairy team" 。如果我输入 "Talk to Dairy team" ,我得到的响应是 "We're sorry, but something went wrong. Please try again."
请告诉我如何解决此问题。提前致谢
问题是您使用的是 "actions-on-google" 库版本 2,但您的代码是使用版本 1 的对象和函数编写的。两个版本之间发生了一些戏剧性的变化。有关如何升级到新版本或更改 package.json 文件以使用版本 1 的详细信息,请参阅 migration guide。