Skip to content

Instantly share code, notes, and snippets.

View cweems's full-sized avatar

Charlie Weems cweems

View GitHub Profile
/*
This function takes a phone number and conversations SID
as inputs and checks if there is an existing session
defined between the recipient's number and the proxy address.
If there is an existing session, it queries phone numbers and
picks a new proxy address.
@param string address - the user's phone number (urlencoded)
@param string conversationSid - the SID of the conversation
{
"providers" : [ {
"guid" : "74c9ead1-2f83-44f1-b90b-6e84483811d8",
"name" : "SAFEWAY PHARMACY #691",
"address1" : "1444 Shattuck Pl",
"address2" : "",
"city" : "Berkeley",
"state" : "CA",
"zip" : "94709",
"phone" : "510-542-5242",
terraform {
required_providers {
twilio = {
source = "RJPearson94/twilio"
version = ">= 0.2.1"
}
}
}
provider "twilio" {
@cweems
cweems / twilio_cli_write_messages_to_csv.sh
Last active January 4, 2021 22:39
Use the Twilio CLI to write all message logs to a .csv
twilio api:core:messages:list --properties="sid,from,to,body,status,direction" \
| while read -r row ; do
echo "$row" >> data.tsv
done
<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
<actionCalls>
<name>Remind_to_Book_Appt_1</name>
<label>Remind to Book Appt 1</label>
<locationX>175</locationX>
<locationY>570</locationY>
<actionName>TwilioSF__TwilioSendSMS</actionName>
<actionType>apex</actionType>
<inputParameters>
@cweems
cweems / Twilio_Flex_Outbound_SMS.js
Created December 6, 2020 02:49
Twilio Flex Outbound SMS - Example Twilio Function Backend
const TokenValidator = require('twilio-flex-token-validator').functionValidator;
exports.handler = TokenValidator(function(context, event, callback) {
const accountSid = context.ACCOUNT_SID;
const authToken = context.AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
const response = new Twilio.Response();
response.appendHeader('Access-Control-Allow-Origin', '*');
response.appendHeader('Access-Control-Allow-Methods', 'OPTIONS POST GET');
function requestHandler(request, response) {
try {
local agentStatus = http.urldecode(request.body).WorkerActivityName;
server.log(agentStatus);
local ledState = (agentStatus == "Available") ? false : true;
device.send("set.led", ledState);
exports.handler = function(context, event, callback) {
var Airtable = require('airtable');
var base = new Airtable({apiKey: ''}).base('');
base('Table 1').create([
{
"fields": {
"Phone Number": event.phone,
"Question 1": event.question1,
"Question 2": event.question2,
{
ToCountry: 'US',
ToState: 'CA',
SmsMessageSid: 'SMXXXXXXX',
NumMedia: '0',
ToCity: '',
FromZip: '10001',
SmsSid: 'SMXXXXXXXX',
OptOutType: 'STOP',
FromState: 'CA',
Adams
Alamosa
Arapahoe
Archuleta
Baca
Bent
Boulder
Broomfield
Chaffee
Cheyenne