Skip to content

Instantly share code, notes, and snippets.

View vernig's full-sized avatar
🏗️
Building great stuff at Twilio (::)

gVerni vernig

🏗️
Building great stuff at Twilio (::)
View GitHub Profile
var maxBackoff = 5000;
var expBackoffLogs = [];
function tryWithTimeout(testFunction, argument, timeout) {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, timeout);
}).then(() => {
expBackoffLogs.push(
@vernig
vernig / conference-with-amd.js
Created December 23, 2020 16:10
Twilio conference with AsyncAMD
const accountSid = process.env.ACCOUNT_SID;
const authToken = process.env.AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client
.conferences('test-conference')
.participants.create({
from: '+447723487719',
to: 'client:worker_client',
waitUrl: 'https://my.website.com/dialtone.mp3', // Link to dialtone mp3
class StudioResponsesParser {
constructor(twilioAccountSid, twilioAuthToken, studioFlowSid) {
this.twilioClient = require('twilio')(twilioAccountSid, twilioAuthToken);
this.setFlowSid(studioFlowSid);
}
setFlowSid(studioFlowSid) {
this.studioFlowSid = studioFlowSid;
this.studioFlow = this.twilioClient.studio.v1.flows(studioFlowSid);
}
@vernig
vernig / incoming-message.js
Created May 11, 2020 09:52
Incoming Message function
const fetch = require('node-fetch');
const dialogflow = require('dialogflow');
const projectId = '<Dialogflow JSON project_id>';
const dfConfig = {
credentials: {
private_key: '<Dialogflow JSON private_key>',
client_email: '<Dialogflow JSON client_email>'
}
}
@vernig
vernig / simple-sms.js
Last active April 6, 2020 18:52
Simple messaging with alphanumeric
const accountSid = '<your account sid>';
const authToken = '<your auth token>';
const client = require('twilio')(accountSid, authToken);
client.messages
.create({body: 'Hi there!', from: 'leitha', to: '<your destination number>'})
.then(message => console.log(message.sid));
@vernig
vernig / gist:a53d5c8394840c9e08f039fc5ebc1aef
Created April 6, 2020 18:49
Simple messaging with alphanumeric
const accountSid = '<your account sid>';
const authToken = '<your auth token>';
const client = require('twilio')(accountSid, authToken);
client.messages
.create({body: 'Hi there!', from: 'leitha', to: '<your destination number>'})
.then(message => console.log(message.sid));
@vernig
vernig / conversations-webhook.js
Created December 17, 2019 18:31
Create a new Salesforce using Twilio Conversation
function (request, response) {
// Check if the event is `onConvesrationAdd`. This is the event that fires when a new conversation is created
if (event.EventType === 'onConversationAdd') {
// Creating a POST to Salesforce case API
fetch("https://um1.salesforce.com/services/data/v39.0/sobjects/Case", {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": "<Your SF token>"
},