Skip to content

Instantly share code, notes, and snippets.

View savelee's full-sized avatar

Lee Boonstra savelee

View GitHub Profile
@savelee
savelee / index.js
Created April 8, 2020 11:22
Client-side Example - Streaming to Dialogflow
//1)
const startRecording = document.getElementById('start-recording');
const stopRecording = document.getElementById('stop-recording');
let recordAudio;
//2)
const socketio = io();
const socket = socketio.on('connect', function() {
startRecording.disabled = false;
});
@savelee
savelee / index.js
Created March 23, 2020 14:29
getValidationResult Dialogflow
const dialogflow = require('dialogflow');
const client = new dialogflow.v2beta1.AgentsClient({
// optional auth parameters.
});
client.getValidationResult({})
.then(responses => {
const response = responses[0];
@savelee
savelee / index.js
Created March 11, 2020 11:19
Speech Adaptation in Dialogflow
const uuid = require('uuid');
const df = require('dialogflow').v2beta1;
const sessionId = uuid.v4();
const sessionClient = new df.SessionsClient();
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
let request = {
session: sessionPath,
queryInput: {
@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": "pizzabot@example.com",
"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>