0

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...

eng
  • 443
  • 1
  • 4
  • 10

1 Answers1

0

“Talk to Smart Home” might not be a correct way to invoke an action. (Please provide the documentation and some sample utterances to the developer)

Also, we have the nodejs sample app in GitHub that the developer can take as a reference: https://github.com/google-home/smart-home-nodejs

The recommended approach we have for developers is to start with the introductory codelab for smart home (that uses a Firebase backend). Once they get the project fully working there, they can replace the backend piece with their own, and try to get the same functionality working. https://developers.home.google.com/codelabs/smarthome-washer