Skip to content

Instantly share code, notes, and snippets.

@bdm1981
bdm1981 / voicemail_to_email.js
Created September 23, 2022 13:08
Twilio Studio Record Voicemail Callback
exports.handler = function (context, event, callback) {
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(context.SG_API_KEY);
let client = context.getTwilioClient();
client
.transcriptions(event.TranscriptionSid)
.fetch()
@bdm1981
bdm1981 / comfort.js
Created December 27, 2019 16:52
Twilio Comfort Noise Example
const express = require("express");
const router = express.Router();
const twilio = require("twilio");
const axios = require("axios");
require("dotenv").config();
const client = new twilio(process.env.ACCOUNT_SID, process.env.AUTH_TOKEN);
router.post("/calls", (req, res, next) => {
console.log("inbound call: ", req.body);
@bdm1981
bdm1981 / emailtosms.js
Created November 22, 2019 15:59
Sendgrid email to twilio SMS
const express = require("express");
const bodyParser = require("body-parser");
const multer = require("multer");
const upload = multer();
const app = express();
require("dotenv").config();
const client = require("twilio")(
process.env.ACCOUNT_SID,
process.env.AUTH_TOKEN
@bdm1981
bdm1981 / mediaStreams-DialogFlow.js
Created October 28, 2019 14:14
Twilio Media Streams & DialogFlow Example
const WebSocket = require("ws");
const express = require("express");
const app = express();
const uuid = require("uuid");
const server = require("http").createServer(app);
const wss = new WebSocket.Server({ server });
const bodyParser = require("body-parser");
require("dotenv").config();
const client = require("twilio")(
@bdm1981
bdm1981 / notifications.js
Created October 9, 2019 19:49
Twilio Flex Notification Snippet
manager.strings.incomingCall = "Incoming call from: {{from}}";
flex.Notifications.registerNotification({
id: "incomingCall",
content: "incomingCall",
timeout: 0,
backgroundColor: "#1a76d2",
icon: "IncomingCallBold",
actions: [
@bdm1981
bdm1981 / call-forwarder
Created September 20, 2019 00:53
Twilio call forwarding
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
let numberList = [
{ trackingNumber: "+1XXXXXXXXXX", destination: "+1XXXXXXXXXX" },
{ trackingNumber: "+1XXXXXXXXXX", destination: "+1XXXXXXXXXX" }
];
let match = numberList.find(numbers => numbers.trackingNumber == event.To);
@bdm1981
bdm1981 / twilioLogParser.js
Created July 3, 2019 21:04
Twilio log parser example
exports.handler = function(context, event, callback) {
let client = context.getTwilioClient();
let promises = [];
client.monitor.alerts
.list({ limit: 20 })
.then(alerts => {
let matchedAlerts = [];
alerts.forEach(a => {
@bdm1981
bdm1981 / flex-TOD-Holiday
Last active July 5, 2019 16:16
Flex TOD & Holiday Routing
exports.handler = function(context, event, callback) {
// With timezone:
// In Functions/Configure, add NPM name: moment-timezone, version: 0.5.14
// Timezone function reference: https://momentjs.com/timezone/
let moment = require("moment-timezone");
// timezone needed for Daylight Saving Time adjustment
let timezone = event.timezone || "America/Chicago";
console.log("+ timezone: " + timezone);
@bdm1981
bdm1981 / sendgrid-S3-Attachments.js
Created June 6, 2019 11:57
Twilio Sendgrid nodejs SDK + S3 file attachments
const sgMail = require("@sendgrid/mail");
const AWS = require("aws-sdk");
require("dotenv").config();
// AWS Config
AWS.config.update({
accessKeyId: process.env.aws_access_key_id,
secretAccessKey: process.env.aws_secret_access_key
});
@bdm1981
bdm1981 / VoicemailToEmail
Last active March 29, 2019 20:00
Twilio Voicemail to Email via SendGrid
exports.handler = function(context, event, callback) {
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(context.SG_API_KEY);
let spam = 0;
if(event.AddOns){
const addOns = JSON.parse(event.AddOns);
if (('nomorobo_spamscore' in addOns.results)) {
spam = addOns.results.nomorobo_spamscore.result.score;
}