Google Home links to Local Host through localtunnel

nodejs localhost

Google home request -> index.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var express = require('express'),
app = express(),
bodyparser = require('body-parser'),
assistant = require('./assistant.js'),
util = require('util');
app.use(bodyparser.json())

// GET method route
app.all('/', function (req, res) {
console.log('index.js/');
assistant.assistantHandler(req,res)
})

app.all('/test', function(req,res) {
console.log('index.js/test');
res.send('helloworld')
})

app.listen(3000)

index.js -> Google actions sdk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';

const ActionsSdkApp = require('actions-on-google').ActionsSdkApp;

exports.assistantHandler = (req, res) => {
console.log('assistantHandler');
const app = new ActionsSdkApp({
request: req,
response: res
});
var str = 'Sorry. I don\'t understand what you say';

// Create functions to handle requests here
function mainIntent(app) {
console.log('assistant.js/mainIntent');
voiceResponse('welcome')
}

function respond(app) {
console.log('assistant.js/respond');

if (app.getRawInput() == 'hello') {
str = 'hello'
}
voiceResponse(str)
}

function voiceResponse(strIn) {
let inputPrompt = app.buildInputPrompt(false,strIn);
app.ask(inputPrompt);
}

let actionMap = new Map();
actionMap.set(app.StandardIntents.MAIN, mainIntent);
actionMap.set(app.StandardIntents.TEXT, respond);

app.handleRequest(actionMap);
}

localtunnel

acquire the URL to access localhost : https://localtunnel.github.io/www/
-> installation: npm install -g localtunnel
-> running: lt --port 8000
-> copy the url

Google Actions SDK

  1. Apply for account: https://developers.google.com/actions/sdk/
    -> Add project
    -> fill the form
    -> get the update code as follow

    `gactions update --action_package PACKAGE_NAME --project PROJECT_NAME`
    
  2. gactions Cli : https://developers.google.com/actions/tools/gactions-cli
    -> download
    -> Run chmod +x gactions to make the binary executable
    -> get the actions json sample gactions init
    -> change the actions:add the url in the json file
    -> update

    `gactions update --action_package PACKAGE_NAME --project PROJECT_ID`
    
  3. test google actions:https://developers.google.com/actions/tools/simulator


more on http://searchfor.space