我正在使用Actions SDK V2库构建Google Action。
当我使用普通的conv.ask和conv.close方法时,我可以使对话正常进行。但是,当我在处理链中添加异步方法时,我面临着问题。我正在使用
"actions-on-google": "^2.4.1",
"firebase-admin": "^6.0.0",
"firebase-functions": "^2.1.0",
每3次失败尝试恰好在第4次尝试通过之后。看起来之前的请求正在占用我的Firebase云功能!
第一个履行请求的请求工作正常,随后的请求失败,并显示“ TypeError:标准不是/srv/node_modules/actions-on-google/dist/framework/express.js的函数”
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 Cloud Functions代替GCF for Firebase进行测试 更新了我的应用代码,使其成为快速应用,并以相同的名称部署到GCF。现在的情况是更糟。部署Cloud Function后,只有第一个请求成功,并且所有后续请求都失败,并具有与以前相同的错误!
这是我对该功能的更新:
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更改为“ WebSocket Sniffer”
这有点使我发疯,而我找不到导致该问题的原因!请帮助。