So I tried to setup my own Google Action, so when I use the Google Assistant and ask for the specific Action, a request should get send to the URL i specified as the fulfillment URL where my Node.js Server runs.
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));
});
I setup the node.js server using Heroku and it seems to work fine, specified the URL correctly as the fulfillment URL, but when I say "Talk to 'Smart home control'(the name/invocation for the action) nothing special happens. Can anybody help me with this?
This is my server but it doesn't seem to receive anything...