我正在使用actions sdk v2库构建一个google操作。
当我使用简单的conv.ask和conv.close方法时,我能够使对话起作用。但是,当我向处理链中添加异步方法时,我就面临问题。我正在使用
"actions-on-google": "^2.4.1",
"firebase-admin": "^6.0.0",
"firebase-functions": "^2.1.0",
在每三次失败的尝试之后,第四次尝试就通过了。看起来上一个请求占用了我的firebase云功能!
对实现的第一个请求工作得很好,随后的请求失败,并显示“typeerror:standard不是google/dist/framework/express.js上的/srv/node_modules/actions的函数”
severity: "ERROR"
textPayload: "TypeError: standard is not a function
at /srv/node_modules/actions-on-google/dist/framework/express.js:27:13
at omni (/srv/node_modules/actions-on-google/dist/assistant.js:44:53)
at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:57:9)
at /worker/worker.js:700:7
at /worker/worker.js:684:9
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)"
我知道,当处理链中有异步函数时,应该将promise返回给intent处理程序。我正在做。但随后的请求仍然失败。
const app = actionssdk();
// ... app code here
app.middleware((conv) => {
console.log('Conversation in Middleware:', conv);
conv.hasScreen =
conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT');
conv.hasAudioPlayback =
conv.surface.capabilities.has('actions.capability.AUDIO_OUTPUT');
});
// Welcome Intent
app.intent('actions.intent.MAIN', (conv, input) => {
// conv.ask('How are you');
console.log('Conversation: ' + JSON.stringify(conv), conv);
console.log('actions.intent.MAIN', input)
return new Promise((resolve, reject) => {
processIntents({conv: conv, input:input}).then(r => {
console.log('Passing response from the handler!', r);
for(let a of r) {
conv.ask(a);
}
resolve();
}).catch(e => reject(e));
});
});
// React to a text intent
app.intent('actions.intent.TEXT', (conv, input) => {
console.log('actions.intent.TEXT', input)
// conv.ask('How are you');
console.log('Conversation: ' + JSON.stringify(conv), conv);
console.log('actions.intent.TEXT', input)
return new Promise((resolve, reject) => {
processIntents({conv: conv, input:input}).then(r => {
console.log('Passing response from the handler!', r);
for(let a of r) {
conv.ask(a);
}
resolve();
}).catch(e => reject(e));
});
});
// React to list or carousel selection
app.intent('actions.intent.OPTION', (conv, params, option) => {
// conv.ask('How are you');
console.log('actions.intent.OPTION', {input: conv.input, option: option, params:params})
console.log('Conversation: ' + JSON.stringify(conv), conv);
console.log('actions.intent.OPTION', option)
return new Promise((resolve, reject) => {
processIntents({conv: conv, params: params, option: option}).then(r => {
console.log('Passing response from the handler!', r);
for(let a of r) {
conv.ask(a);
}
resolve();
}).catch(e => reject(e));
});
});
app.intent('', (conv) => {
// conv.ask('How are you');
console.log('Empty Intent for direct WEB requests / ALEXA requests', conv);
let input = ((conv.request.originalRequest ||{}).result ||{}).resolvedQuery;
return new Promise((resolve, reject) => {
processIntents({conv: conv, input: input}).then(r => {
//TODO: send raw HTTP Response
//TODO: Yet to figure out how this can be done@!
resolve();
}).catch(e => reject(e));
});
});
const processIntents = (args) => {
let conv = args["conv"];
let params = args["params"];
let option = args["option"];
let input = args["input"];
// Async Function here that responds with a Promise
// Based on the request, it will send either array of responses to use in conv.ask calls
// OR send response JSON body that can be sent to Amazon Alexa / WEB requests
return Promise.resolve(response);
}
exports.apiaifns = functions.https.onRequest(app);
我正在发送来自
processIntents
方法并在响应时遍历数组。
我已经尝试了很多可能的排列和组合,但是仍然没有成功。
更新:使用google云函数而不是firebase的gcf进行测试
更新了我的应用程序代码,使其成为一个快速应用程序,并以相同的名称部署到gcfs。现在情况是
更糟的
. 只有云功能部署后的第一个请求成功,所有后续请求失败,错误与之前相同!
以下是我对函数的更新:
const express = require('express')
const bodyParser = require('body-parser')
var morgan = require('morgan')
.
.
.
const expressApp = express().use(bodyParser.json())
expressApp.use(morgan('dev'))
expressApp.post('/fulfillment', app)
exports.apiaifns = expressApp;
我还将actio调用url更改为“
https://us-central1-my-project.cloudfunctions.net/apiaifns/fulfillment
“
这简直把我逼疯了,我找不到问题的原因!请帮助。