Skip to content

Instantly share code, notes, and snippets.

@netomarin
netomarin / sphero.js
Created February 14, 2019 20:56
Basic Sphero connection demo using their JavaScript API
var sphero = require("sphero"),
sprk = sphero("EA:FE:34:55:2A:E0"); // change BLE address accordingly
sprk.connect(function() {
// roll Sphero in a random direction, changing direction every second
setInterval(function() {
var direction = Math.floor(Math.random() * 360);
sprk.roll(150, direction);
}, 1000);
});
@netomarin
netomarin / index.js
Last active November 11, 2018 00:44
Basic AoG fulfillment to add a donation to a Firestore collection
'use strict';
const {dialogflow} = require('actions-on-google');
const admin = require('firebase-admin');
const functions = require('firebase-functions');
const app = dialogflow({debug: true});
admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
@netomarin
netomarin / index.js
Created October 29, 2018 19:38
Sample code for the blog post Handling Action’s No Match errors in Dialogflow: Three strikes and you’re out
// Copyright 2018, Google, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@netomarin
netomarin / index.js
Created October 11, 2018 18:12
Daily update entity setup
app.intent('setup_price_update', (conv, {cryptocurrency}) => {
const intent = conv.arguments.get('UPDATE_INTENT');
conv.ask(new RegisterUpdate({
intent: intent,
arguments: [
{
name: 'cryptocurrency',
textValue: cryptocurrency,
},
],
@netomarin
netomarin / index.js
Created October 11, 2018 18:12
Daily updates finish setup
app.intent('finish_price_update_setup',
(conv, params, registered) => {
if (registered && registered.status === 'OK') {
conv.close(`Ok, I'll start giving you daily updates.`);
} else {
conv.close(`Ok, I won't give you daily updates.`);
}
});
@netomarin
netomarin / index.js
Created October 11, 2018 18:11
Daily update setup
app.intent('setup_price_update', (conv) => {
const intent = conv.arguments.get('UPDATE_INTENT');
conv.ask(new RegisterUpdate({
intent: intent,
}));
});
@netomarin
netomarin / index.js
Created October 11, 2018 18:10
Suggestion chip for daily update
conv.ask('The price of one ' + base + " is " +
Number(price).toFixed(2) + " " + target);
// Suggestion max length is 25 characters
conv.ask(new Suggestions(['Warn me a 10% price drop',
'Send me Daily Updates']));
@netomarin
netomarin / index.js
Created October 11, 2018 18:09
Finish push notification setup
app.intent('finish_exchange_rate_setup_push', (conv, params) => {
if (conv.arguments.get('PERMISSION')) {
//const userID = conv.user.id;
const userID = conv.arguments.get('UPDATES_USER_ID');
// code to save intent and userID in your db
conv.close(`Ok, I'll start alerting you.`);
} else {
conv.close(`Ok, I won't alert you.`);
}
});
@netomarin
netomarin / index.js
Created October 11, 2018 18:08
Update permission - back-end fulfillment
app.intent('exchange_rate_setup_push', (conv) => {
conv.ask(new UpdatePermission({intent: 'cryptocurrency_price'}));
});
@netomarin
netomarin / index.js
Created October 11, 2018 18:08
Suggestion chip for Push Notification
conv.ask('The price of one ' + base + " is " +
Number(price).toFixed(2) + " " + target);
// Suggestion max length is 25 characters
conv.ask(new Suggestions('Warn me a 10% price drop'));