View simpleserver.js
// 1) | |
sessionId = uuid.v4(); | |
// 2) | |
sessionClient = new df.SessionsClient(); | |
sessionPath = sessionClient.sessionPath(projectId, sessionId); | |
// 3) | |
request = { | |
session: sessionPath, | |
queryInput: { | |
// 4) |
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 ... | |
}); | |
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 |
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) { |
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; | |
}); |
View index.js
const dialogflow = require('dialogflow'); | |
const client = new dialogflow.v2beta1.AgentsClient({ | |
// optional auth parameters. | |
}); | |
client.getValidationResult({}) | |
.then(responses => { | |
const response = responses[0]; |
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: { |
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' | |
}, |
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 |