Skip to content

Instantly share code, notes, and snippets.

Avatar

Lee Boonstra savelee

View GitHub Profile
@savelee
savelee / simpleserver.js
Created Apr 8, 2020
Dialogflow Streaming
View simpleserver.js
// 1)
sessionId = uuid.v4();
// 2)
sessionClient = new df.SessionsClient();
sessionPath = sessionClient.sessionPath(projectId, sessionId);
// 3)
request = {
session: sessionPath,
queryInput: {
// 4)
@savelee
savelee / simpleserver.js
Created Apr 8, 2020
Server - streaming to Dialogflow
View simpleserver.js
//1
io.on('connect', (client) => {
//2
client.on('message', async function(data) {
const dataURL = data.audio.dataURL.split(',').pop();
let fileBuffer = Buffer.from(dataURL, 'base64');
//3 ...
});
@savelee
savelee / index.js
Created Apr 8, 2020
Client - Streaming to Dialogflow
View index.js
// 1)
timeSlice: 4000,
// 2)
// as soon as the stream is available
ondataavailable: function(blob) {
// 3
// making use of socket.io-stream for bi-directional
// streaming, create a stream
@savelee
savelee / index.js
Created Apr 8, 2020
Client - Streaming to Dialogflow
View index.js
// 1)
stopRecording.onclick = function() {
// recording stopped
startRecording.disabled = false;
stopRecording.disabled = true;
// stop audio recorder
recordAudio.stopRecording(function() {
// after stopping the audio, get the audio data
recordAudio.getDataURL(function(audioDataURL) {
@savelee
savelee / index.js
Created Apr 8, 2020
Client-side Example - Streaming to Dialogflow
View index.js
//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 Mar 23, 2020
getValidationResult Dialogflow
View index.js
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 Mar 11, 2020
Speech Adaptation in Dialogflow
View index.js
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 Mar 2, 2020
Sanity Cloud Function package.json
View 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",
View simpleresponse.js
export default {
name: 'simpleresponse',
title: 'Simple Response',
type: 'document',
fields: [
{
name: 'title',
title: 'Title',
type: 'string'
},
@savelee
savelee / schema.js
Last active Mar 2, 2020
schema.json Sanity Dialogflow
View schema.js
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