Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin Whinnery kwhinnery

  • Twilio
  • Saint Paul / Minneapolis
View GitHub Profile
View Example.java
// Install the Java helper library from twilio.com/docs/java/install
import java.net.URI;
import java.net.URISyntaxException;
import com.twilio.rest.Twilio;
import com.twilio.rest.creator.api.v2010.account.CallCreator;
import com.twilio.rest.resource.api.v2010.account.Call;
import com.twilio.rest.type.PhoneNumber;
public class Example {
View example.js
var t = new twilio.TwimlResponse();
t.dial((dial) => {
dial.number('+16518675309');
});
View example.js
var accountSid = '{{ YOUR_ACCOUNT_SID }}';
var authToken = '{{ YOUR_AUTH_TOKEN }}';
var LookupsClient = require('twilio').LookupsClient;
var client = new LookupsClient(accountSid, authToken);
var phoneNumber = process.argv[2];
client.phoneNumbers(phoneNumber).get({
type: 'carrier'
}, (error, number) => {
var message = number ? number.national_format + ' is valid' : error;
View one_request.py
# Download the 'Preview Release' version of the Python helper library from
# twilio.com/docs/python/install
from twilio.rest import Client
# Your Account Sid and Auth Token from twilio.com/user/account
account = 'AC421124bfab3052ad108f3e8c7a119cfb'
token = 'AUTH_TOKEN'
client = Client(account, token)
# Delete the service
View actual.js
// Load user year data
$.ajax('/ga/users').then(function(data) {
// Populate raw numbers
var usersYearFormatted = humanize.numberFormat(data.usersThisYear, 0);
var usersQuarterFormatted = humanize.numberFormat(data.usersThisQuarter,
0);
$('.users-year').text(usersYearFormatted);
$('.users-quarter').text(usersQuarterFormatted);
// Populate progress bar
$quarterGoal = $('.progress.current-goal .progress-bar');
View index.js
var http = require('http');
var express = require('express');
var bodyParser = require('body-parser');
var KeenClient = require('keen-js');
// 1.) create an authenticated Keen analytics client
var keen = new KeenClient({
projectId: 'your project ID here',
writeKey: 'your write key here'
});
View conversations.js
var client = new Twilio.Conversations.Client('token');
var convo = client.conversation('myCall');
convo.display('#them', '#me').then(function() {
console.log('now your local media is showing, as is theirs!');
}).catch(function(err) {
console.log('oops, something bad happened')
});
convo.on('participantJoined', function(participant) {
View sample.js
var client = new Twilio.IPMessaging.Client('token');
// Creates a reference to a channel that may or may not exist
var channel = client.channel('general');
// If there's such a thing as an online/offline channel, this serves as the way the channel
// gets updated when it's reconnected from an offline state. It could also serve as a way
// to get updated when the channel information is initially fetched from the server
//
// Fired when:
@kwhinnery
kwhinnery / sample_one.js
Last active Feb 19, 2016
Twilio IP Messaging is intended to help developers build chat applications, and is in public beta. Given the following options, which interface would you prefer to initialize the Twilio IP Messaging SDK and execute a few basic tasks? Vote here: https://twitter.com/kevinwhinnery/status/700445163672510468
View sample_one.js
var client = new Twilio.IPMessaging.Client('token');
var channel = client.getOrCreateChannelByUniqueName('general');
channel.join();
channel.listMessages().then(function(messages) {
console.log(messages);
}).catch(function(err) {
console.log(err);
});
View sync.js
var map = client.sync.map('uniqueName');
map.set('foo', { bar: 42 }).then(function() {
console.log('set it!');
}).catch(function(err) {
console.log('dang it, dont have access');
});
// same as above...
map.set('foo', { bar: 42 }, function(err) {