Skip to content

Instantly share code, notes, and snippets.

@dtolb
Last active February 27, 2024 13:33
Show Gist options
  • Save dtolb/2ee434b288f040cf2b57 to your computer and use it in GitHub Desktop.
Save dtolb/2ee434b288f040cf2b57 to your computer and use it in GitHub Desktop.
MMS Examples

MMS Examples

MMS & SMS Curl

MMS no DLR cURL

curl -v -X POST https://api.catapult.inetwork.com/v1/users/{user-id}/messages \
	-u {token}:{secret} \
	-H "Content-type: application/json" \
	-d '{"from": "+12018994225", "to": "+12223334444", "text": "Hello there from Bandwidth!", "media":["https://s3.amazonaws.com/bwdemos/logo.png"]}'

Add DLR to SMS messages

NOTE THAT MMS AND DLR ARE NOT COMPATABLE

  • Add receiptRequested and callbackUrl
  • Use Request Bin to see status as example
curl -v -X POST https://api.catapult.inetwork.com/v1/users/{user-id}/messages \
	-u {token}:{secret} \
	-H "Content-type: application/json" \
	-d '{"from": "+12018994225", "to": "+19197891146", "text": "Hello there from Bandwidth!", "receiptRequested":"all", "callbackUrl":"http://requestb.in/1hfrdc31"}'

requestbin

MMS & SMS Node

  • Uses the Node SDK
  • NPM Install
  • npm install --save node-bandwidth
  • set the client object or globally

Init client

 //Using client directly
 var client = new bandwidth.Client("userId", "apiToken", "apiSecret");

 //Or you can use default client instance.
 //Do that only once
 bandwidth.Client.globalOptions.apiToken = "token";
 bandwidth.Client.globalOptions.apiSecret = "secret";
 bandwidth.Client.globalOptions.userId = "userId";

Send basic SMS

var message = {
	from: "+19195551212",
	to: "+191955512142",
	text: "Test"
};
bandwidth.Message.create(message, function(err, message){
	//Traditional call back style
	if (err) {
		console.log(err);
	}
	else {
		console.log(message);
	}
});

Promisify message

npm install --save bluebird

var Promise = require("bluebird");
var bandwidth = require("node-bandwidth");
Promise.promisifyAll(bandwidth.Message);

bandwidth.Client.globalOptions.apiToken = "token";
bandwidth.Client.globalOptions.apiSecret = "secret";
bandwidth.Client.globalOptions.userId = "userId";

var message = {
	from: "+19195551212",
	to: "+191955512142",
	text: "Test"
};

bandwidth.Message.createAsync(message)
.then(function (message) {
	console.log(message);
})
.catch(function (err) {
	console.log(err);
})

Adding DLR to SMS

  • Be sure to add callbackUrl!
var message = {
	from: "+19195551212",
	to: "+191955512142",
	text: "Test",
	receiptRequested: "all",
	callbackUrl: "http://requestb.in"
};
bandwidth.Message.create(message, function(err, message){
	//Traditional call back style
	if (err) {
		console.log(err);
	}
	else {
		console.log(message);
	}
});

Sending MMS

  • Either Catapult media URL or valid media URL
var message = {
	from: "+19195551212",
	to: "+191955512142",
	text: "Test",
	media: ["https://s3.amazonaws.com/bwdemos/logo.png"]
};
bandwidth.Message.create(message, function(err, message){
	//Traditional call back style
	if (err) {
		console.log(err);
	}
	else {
		console.log(message);
	}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment