Skip to content

Instantly share code, notes, and snippets.

View savelee's full-sized avatar

Lee Boonstra savelee

View GitHub Profile
@savelee
savelee / package.json
Created March 2, 2020 18:26
Sanity Cloud Function package.json
{
"name": "dialogflowFirebaseFulfillment",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
@savelee
savelee / simpleresponse.js
Created March 2, 2020 18:25
Dialogflow Sanity
export default {
name: 'simpleresponse',
title: 'Simple Response',
type: 'document',
fields: [
{
name: 'title',
title: 'Title',
type: 'string'
},
@savelee
savelee / schema.js
Last active March 2, 2020 18:24
schema.json Sanity Dialogflow
import createSchema from 'part:@sanity/base/schema-creator'
import schemaTypes from 'all:part:@sanity/base/schema-type'
import simpleResponse from './simpleresponse'
// Then we give our schema to the builder and provide the result to Sanity
export default createSchema({
// We name our schema
name: 'dialogflow',
// Then proceed to concatenate our document type
// to the ones provided by any plugins that are installed
@savelee
savelee / index.js
Last active March 2, 2020 18:28
Dialogflow & Sanity Headless CMS
const functions = require('firebase-functions');
const sanityClient = require('@sanity/client');
const {
WebhookClient,
Payload
} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
const client = sanityClient({
@savelee
savelee / json.json
Created February 21, 2020 13:23
Custom Payload Hangouts example
{
"hangouts": {
"header": {
"title": "Pizza Bot Customer Support",
"subtitle": "[email protected]",
"imageUrl": "https://goo.gl/aeDtrS"
},
"sections": [
{
@savelee
savelee / AudioBufferSourceNode.js
Last active February 17, 2020 13:46
A best practice for streaming audio from a browser microphone to Dialogflow or Google Cloud STT by using websockets.
function playOutput(arrayBuffer){
let audioContext = new AudioContext();
let outputSource;
try {
if(arrayBuffer.byteLength > 0){
console.log(arrayBuffer.byteLength);
audioContext.decodeAudioData(arrayBuffer,
function(buffer){
audioContext.resume();
outputSource = audioContext.createBufferSource();
@savelee
savelee / index.html
Created December 6, 2019 17:20
A best practice for streaming audio from a browser microphone to Dialogflow or Google Cloud STT by using websockets.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>RecordRTC over Socket.io</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="https://www.WebRTC-Experiment.com/RecordRTC.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
@savelee
savelee / index.js
Last active October 28, 2019 11:07
simple tv guide feed
const TVGUIDE_WEBSERVICE = 'https://tvguide-f36xvzb5da-ew.a.run.app/channel';
const { WebhookClient } = require('dialogflow-fulfillment');
const rp = require('request-promise');
const moment = require('moment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.tvguide = function(request, response){
var agent = new WebhookClient({ request, response });
@savelee
savelee / feed.js
Created May 28, 2019 08:29
tvguide feed
'use strict';
const local = {
"1": [{
"titel": "Journaal",
"datum_start": "2018-07-26 15:00:00"
}, {
"titel": "Journaal",
"datum_start": "2018-07-26 15:20:00"
}, {
@savelee
savelee / chatserver-node.js
Last active August 18, 2022 09:40
Example Dialogflow implementation, branching on parameters and returning text strings
require('dotenv').config() //load environemnt vars
const projectId = process.env.GCLOUD_PROJECT; //your project name
const uuidv1 = require('uuid/v1');
const sessionId = uuidv1();
const languageCode = 'en-US';
const server = require('http').createServer((request, response) => {
response.writeHead(200, {"Content-Type": "text/html"});