How to use the actions-on-google.smarthome function in actions-on-google

To help you get started, we’ve selected a few actions-on-google examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github actions-on-google / smart-home-nodejs / src / index.ts View on Github external
expressApp.use(morgan('dev'))
expressApp.use(bodyParser.json())
expressApp.use(bodyParser.urlencoded({extended: true}))
expressApp.set('trust proxy', 1)

Auth.registerAuthEndpoints(expressApp)

let jwt
try {
  jwt = require('./smart-home-key.json')
} catch (e) {
  console.warn('Service account key is not found')
  console.warn('Report state and Request sync will be unavailable')
}

const app = smarthome({
  jwt,
  debug: true,
})

// Array could be of any type
// tslint:disable-next-line
async function asyncForEach(array: any[], callback: Function) {
  for (let index = 0; index < array.length; index++) {
    await callback(array[index], index, array)
  }
}

async function getUserIdOrThrow(headers: Headers): Promise {
  const userId = await Auth.getUser(headers)
  const userExists = await Firestore.userExists(userId)
  if (!userExists) {
github googlecodelabs / smarthome-washer / washer-start / functions / index.js View on Github external
access_token: '123access',
      refresh_token: '123refresh',
      expires_in: secondsInDay,
    };
  } else if (grantType === 'refresh_token') {
    obj = {
      token_type: 'bearer',
      access_token: '123access',
      expires_in: secondsInDay,
    };
  }
  response.status(HTTP_STATUS_OK)
    .json(obj);
});

const app = smarthome({
  debug: true,
});

app.onSync((body) => {
  // TODO: Implement full SYNC response
  return {};
});

const queryFirebase = async (deviceId) => {
  const snapshot = await firebaseRef.child(deviceId).once('value');
  const snapshotVal = snapshot.val();
  //TODO: Define device states to return
  return {};
};

// eslint-disable-next-line
github openhab / openhab-google-assistant / functions / index.js View on Github external
* http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */

/**
 * Main entry point for incoming intents from Google Assistant.
 *
 * @author Mehmet Arziman - Initial contribution
 * @author Michael Krug - Rework
 *
 */
const OpenHAB = require('./openhab.js').OpenHAB;
const ApiHandler = require('./apihandler.js').ApiHandler;
const config = require('./config.js');
const app = require('actions-on-google').smarthome();

app.onDisconnect(() => {
	return {};
});

app.onExecute(async (body, headers) => {
	const authToken = headers.authorization ? headers.authorization.split(' ')[1] : null;
	const apiHandler = new ApiHandler(config, authToken);
	const payload = await new OpenHAB(apiHandler).handleExecute(body.inputs[0].payload.commands).catch(() => ({
		errorCode: 'actionNotAvailable',
		status: 'ERROR',
		commands: []
	}));

	return {
		requestId: body.requestId,
github benjefferies / gogo-garage-opener / google-actions / functions / index.js View on Github external
const { smarthome } = require("actions-on-google");
const functions = require("firebase-functions");
const axios = require("axios").default;
const jwtDecode = require('jwt-decode');

const app = smarthome();

function getAccessToken(headers) {
  const authorization = headers.authorization;
  console.log(`Authorization header: ${authorization}`);
  return authorization.substr(7);
}

function getRS(accessToken) { 
  const decoded = jwtDecode(accessToken);
  const rs = decoded['aud'][0]
  console.log(`Got rs: ${rs}`)
  return rs
}

function getUserInfo(accessToken) { 
  const decoded = jwtDecode(accessToken);
github googlecodelabs / smarthome-washer / washer-done / functions / index.js View on Github external
access_token: '123access',
      refresh_token: '123refresh',
      expires_in: secondsInDay,
    };
  } else if (grantType === 'refresh_token') {
    obj = {
      token_type: 'bearer',
      access_token: '123access',
      expires_in: secondsInDay,
    };
  }
  response.status(HTTP_STATUS_OK)
    .json(obj);
});

const app = smarthome({
  debug: true,
});

app.onSync((body) => {
  return {
    requestId: body.requestId,
    payload: {
      agentUserId: '123',
      devices: [{
        id: 'washer',
        type: 'action.devices.types.WASHER',
        traits: [
          'action.devices.traits.OnOff',
          'action.devices.traits.StartStop',
          'action.devices.traits.RunCycle',
        ],