Skip to content

Instantly share code, notes, and snippets.

Avatar

Lee Boonstra savelee

View GitHub Profile
@savelee
savelee / 000-default-le-ssl.conf
Last active Jun 26, 2020
SSL / mutual TLS examples
View 000-default-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
@savelee
savelee / .dockerignore
Last active Jun 17, 2020
Dialogflow Fulfillment in Cloud Run
View .dockerignore
Dockerfile
README.md
node_modules
npm-debug.log
@savelee
savelee / index.js
Last active Jun 17, 2020
Webhook Example
View index.js
'use strict';
const functions = require('firebase-functions');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
function handleRequest(map, request){
let intent;
if(request.body && request.body.queryResult && request.body.queryResult.intent){
intent = request.body.queryResult.intent.displayName;
}
@savelee
savelee / index.js
Last active Jun 17, 2020
Actions on Google libary
View index.js
'use strict';
const {
dialogflow,
BasicCard,
Button,
Image,
Suggestions
} = require('actions-on-google');
@savelee
savelee / index.js
Last active Jun 17, 2020
Dialogflow Fulfillment Library
View index.js
'use strict';
const functions = require('firebase-functions');
const { WebhookClient, Card, Suggestion } = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
@savelee
savelee / gist:e2877fa44a0747344dde4d49c0e1039d
Last active Apr 28, 2020
Installing FreePBX15 with Asterisk 16 on Compute Engine
View gist:e2877fa44a0747344dde4d49c0e1039d
## Create Compute
$ gcloud beta compute --project=dialogflow-ivr instances create "freepbx" --zone "us-central1-a" --machine-type=n1-standard-1 --subnet=default --network-tier=PREMIUM --maintenance-policy=MIGRATE --service-account=293782603063-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --image=centos-7-v20200420 --tags "http-server","https-server" --image-project=centos-cloud --boot-disk-size=40GB --boot-disk-type=pd-standard --boot-disk-device-name=instance-1 --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
## Edit the VM, add the following metadata label:
startup-script : sudo ufw ssh
## SSH into the machine
$ gcloud compute ssh <instancename> --project=p
@savelee
savelee / index.js
Created Apr 8, 2020
Client - Text to Speech - Streaming
View index.js
// 1)
function playOutput(arrayBuffer){
let audioContext = new AudioContext();
let outputSource;
try {
if(arrayBuffer.byteLength > 0){
// 2)
audioContext.decodeAudioData(arrayBuffer,
function(buffer){
// 3)
@savelee
savelee / simpleserver.js
Created Apr 8, 2020
Speech to Text - Streaming
View simpleserver.js
// 1)
async function transcribeAudioStream(audio, cb) {
// 2)
const recognizeStream = speechClient.streamingRecognize(request)
// 3)
.on('data', function(data){
console.log(data);
cb(data);
})
// 4)
@savelee
savelee / simpleserver.js
Created Apr 8, 2020
Speech to Text - Streaming
View simpleserver.js
// 1)
speechClient = new speech.SpeechClient();
// 2)
request = {
config: {
sampleRateHertz: sampleRateHertz,
encoding: encoding,
languageCode: languageCode
},
@savelee
savelee / simpleserver.js
Created Apr 8, 2020
Dialogflow - Streaming
View simpleserver.js
// 1)
async function detectIntentStream(audio, cb) {
// 2)
const stream = sessionClient.streamingDetectIntent()
.on('data', function(data){
// 3)
if (data.recognitionResult) {
console.log(
`Intermediate transcript:
${data.recognitionResult.transcript}`
You can’t perform that action at this time.