Skip to content

Instantly share code, notes, and snippets.

@dtolb
dtolb / BWLinks.md
Last active January 19, 2016 14:31
Bandwidth Links
@dtolb
dtolb / outbound.cs
Created January 22, 2016 21:46
Create outbound call
var c = await Call.Create(Client, new Dictionary<string, object>
{
{"from", PhoneNumberForCallbacks},
{"to", call.From},
{"callbackUrl", BaseUrl + Url.Action("CatapultFromCallback")},
{"tag", call.To}
});
@dtolb
dtolb / speak.cs
Created January 22, 2016 21:47
Speak Sentence
private async Task ProcessCatapultFromEvent(AnswerEvent ev)
{
// "from" number answered a call. speak him a message
var call = new Call { Id = ev.CallId };
call.SetClient(Client);
var contact = DbContext.Contacts.FirstOrDefault(c => c.PhoneNumber == ev.Tag);
if (contact == null)
{
throw new Exception("Missing contact for number " + ev.Tag);
}
@dtolb
dtolb / NewCall.cs
Created January 22, 2016 21:48
2nd Outbound Leg
private async Task ProcessCatapultFromEvent(SpeakEvent ev)
{
if (ev.Status != "done") return;
//a messages was spoken to "from" number. calling to "to" number
var c = await Call.Create(Client, new Dictionary<string, object>
{
{"from", PhoneNumberForCallbacks},
{"to", ev.Tag},
{"callbackUrl", BaseUrl + Url.Action("CatapultToCallback")},
{"tag", ev.CallId}
@dtolb
dtolb / Bridge.cs
Created January 22, 2016 21:48
Create Bridge
private async Task ProcessCatapultToEvent(AnswerEvent ev)
{
//"to" number answered a call. Making a bridge with "from" number's call
var b = await Bridge.Create(Client, new[] {ev.CallId, ev.Tag}, true);
Debug.WriteLine(string.Format("BridgeId is {0}", b.Id));
}
@dtolb
dtolb / s_and_o.cs
Created January 22, 2016 21:49
Search then Order
//reserve a phone numbers for callbacks if need
var numbers = await AvailableNumber.SearchLocal(catapult, new Dictionary<string, object> { { "state", "NC" }, { "city", "Cary" }, { "quantity", 1 } });
phoneNumber = numbers.First().Number;
await PhoneNumber.Create(catapult, new Dictionary<string, object> { { "number", phoneNumber } });
}
@dtolb
dtolb / sendmessage.js
Created January 25, 2016 21:23
SendMessage
module.exports.sendMessage = function (message) {
var bwClient = new bandwidth.Client(
config.catapult.user_id,
config.catapult.api_token,
config.catapult.api_secret
);
var buildMessage = function (message) {
var fromNumber = config.bandcast_number;
var outMessage = [];
@dtolb
dtolb / callback.js
Last active January 26, 2016 19:55
Callback Handler
module.exports.event = function (req, res, next) {
var hasBody = (typeof req.body !== 'undefined' && req.body !== null);
res.sendStatus(201); //Immediately respond to request
if (hasBody) {
var hasEvent = (typeof req.body.eventType !== 'undefined');
if (hasEvent) {
if (req.body.eventType === 'sms') {
logger.debug('Starting broadcast event');
bandcast.handleMessage({
fromNumber: req.body.from,
@dtolb
dtolb / SimpleOut.js
Last active January 26, 2016 19:23
Simple SendMessage.js
bandwidth.Message.create(
{
from: "+19195551212",
to: "+191955512142",
text: "Test"
},
function(err, message){
console.log(err);
console.log(message);
});
@dtolb
dtolb / number.php
Last active February 8, 2016 14:52
Number order PHP
<?php
/*
Ordering a phone number from bandwidth (http://bit.ly/1QQtoCF)
Information pulled from http://bit.ly/1okTYuf
*/
// Be sure to update the user id, token, and secret
$url = "https://{YOUR_TOKEN}:{YOUR_SECRET}@api.catapult.inetwork.com/v1/users/{YOUR_USERID}/phoneNumbers";
// Be sure that the number is available
$data = array(