我正在使用Node.js库actions-on-google
客户端为actions-on-google
设备类型构建智能家居操作。此操作在GCP中部署为云功能。我可以确认以下内容到目前为止效果良好:
Garage Door
)onSync()
)尽管其他回调(onExecute()
和onSync()
)也能正常工作,但无论如何我们都看不到任何证据表明onExecute()
被调用。在Stackdriver中没有显示任何错误,也没有在Stackdriver中的“ Google Actions”过滤器下生成任何日志。
我们期望onQuery()
在我们询问Google助理诸如车库门是否已打开?]和马特的门是否已关闭?]时运行。onQuery()
以查看呼叫是否挂起
async
headers
以下代码显示了简单的onQuery()
回调。为清楚起见,已删除onQuery()
和onExecute()
代码。
onSync
[我们考虑了对'use strict';
const functions = require('firebase-functions');
const {smarthome} = require('actions-on-google');
const app = smarthome({
jwt: require('./XXXXXXXXX-XXXXXXXXXX.json'),
debug: true,
});
//
// Note: Removed onSync() and onExecute() for clarity
//
app.onQuery(async (body, headers) => {
// Expecting to see these logging statements in
// Stackdriver like we do for onExecute() and
// onSync() ... but nothing ever shows up.
console.info('=== onQuery.body', body);
console.info('=== onQuery.headers', headers);
// We have hardcoded the following ID and a "closed"
// state. It matches a valid device ID to the testing
// account we are using.
return {
requestId: body.requestId,
payload: {
devices: {
'2489e4a92799728292b8d5a8b1c9d177': {
on: true,
online: true,
openPercent: 0,
}
}
}
};
});
exports.smarthome = functions.https.onRequest(app);
的调用中返回的JSON可能缺少特征或某种使其无法正确响应查询意图的可能性,但我们无法识别出任何可能不正确或缺失的东西。这是从onSync()
返回的JSON有效负载:
onSync()
我们希望Google Assistant响应“”车库门已关闭“
概述,我正在使用Node.js库上的Google行动客户端来为Garage Door设备类型构建智能家居操作。此操作在GCP中部署为云功能。我可以确认...
在这里回答我自己的问题,以防其他人遇到此麻烦。我的动作处理SYNC和EXECUTE意图而不是QUERY意图的原因归结为我在SYNC响应中为每个设备分配的默认名称/用户名。
最终,我开始使用以下内容,并且我的动作再次开始按预期响应QUERY的意图: