为Google智能家居Action配置Node.js服务器后无响应求助
问题:Google Action调用无响应,服务器未收到请求
我搭建了一个专属Google Action,希望通过Google Assistant调用时,请求能发送到我设置为fulfillment URL的Heroku部署Node.js服务器。服务器运行正常,fulfillment URL也已正确配置,但说出“Talk to 'Smart home control'(我的Action调用名称)”时没有任何反应,服务器也没收到请求,求排查解决。
我的Node.js服务器代码:
const express = require('express'); const app = express(); app.post('/smarthome', express.json(), (req, res) => { console.log("SOMETHING ARRIVED!!! YEEEEEES!"); console.log(req.body); const intent = req.body.inputs[0].intent; switch (intent) { case 'action.devices.EXECUTE': const commands = req.body.inputs[0].payload.commands; const responseCommands = []; for (const command of commands) { for (const execution of command.execution) { if (execution.command === 'action.devices.commands.OnOff') { const on = execution.params.on; if (on) { console.log('Turning on the light'); } else { console.log('Turning off the light'); } responseCommands.push({ ids: [command.devices[0].id], status: 'SUCCESS', states: { on: on, online: true, }, }); } } } res.send({ requestId: req.body.requestId, payload: { commands: responseCommands, }, }); break; } }); app.listen(process.env.PORT || 3000, () => { console.log('Server is listening on port ' + (process.env.PORT || 3000)); });
排查解决步骤
- 纠正触发方式:你的代码是针对智能家居设备控制的逻辑,但“Talk to [Action名称]”是触发普通对话Action的指令,智能家居Action不支持这种触发方式。应该使用类似“Turn on the bedroom light”这类直接控制设备的指令。
- 确认Action类型:在Google Actions Console中,必须创建Smart Home Action类型,而非Custom Action。类型错误会导致触发逻辑完全不匹配,请求无法送达服务器。
- 补充设备同步逻辑:智能家居Action必须先完成设备同步流程,Google Assistant才能识别你的设备。你的代码仅处理了
EXECUTE意图,缺少action.devices.SYNC意图的处理,这会导致设备无法被发现,自然无法触发请求。示例SYNC逻辑如下:case 'action.devices.SYNC': res.send({ requestId: req.body.requestId, payload: { agentUserId: 'unique-user-id', devices: [ { id: 'light-1', type: 'action.devices.types.LIGHT', traits: ['action.devices.traits.OnOff'], name: { name: 'Bedroom Light' }, willReportState: false, roomHint: 'Bedroom' } ] } }); break; - 校验fulfillment URL路径:确保控制台中设置的URL是
https://<你的Heroku域名>/smarthome,路径必须与代码中的/smarthome路由完全匹配。 - 查看Action交互日志:在Actions Console的“测试”页面,查看“交互日志”,这里会显示请求是否发送、是否存在错误返回,是定位问题的关键依据。
- 补充核心意图处理:至少需要实现
SYNC、QUERY、EXECUTE三个核心意图,才能完成基本的智能家居设备交互流程。
内容的提问来源于stack exchange,提问作者RickMorpheus
相关产品推荐
相关产品推荐

