npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

twilio-meteor

v1.1.0

Published

Twilio Meteor API Bindings

Downloads

3

Readme

Twilio Meteor API bindings

This smart package exposes the official Twilio Meteor API from the node.js npm package: http://twilio.github.io/twilio-node/

This Meteor package is licensed under the MIT license.

This uses version 1.1.4 of the Twilio node.js package and the new meteor 0.6.5.1 npm bindings.

To Install

mrt add moment
mrt add twilio-meteor

moment is required for Twilio date conversion internals.

To get started, replace ACCOUNT_SID, AUTH_TOKEN with your Twilio credentials and use some of the examples below:

####Send an SMS text message


  twilio = Twilio(ACCOUNT_SID, AUTH_TOKEN);
  twilio.sendSms({
    to:'+16515556677', // Any number Twilio can deliver to
    from: '+14506667788', // A number you bought from Twilio and can use for outbound communication
    body: 'word to your mother.' // body of the SMS message
  }, function(err, responseData) { //this function is executed when a response is received from Twilio
    if (!err) { // "err" is an error received during the request, if any
      // "responseData" is a JavaScript object containing data received from Twilio.
      // A sample response from sending an SMS message is here (click "JSON" to see how the data appears in JavaScript):
      // http://www.twilio.com/docs/api/rest/sending-sms#example-1
      console.log(responseData.from); // outputs "+14506667788"
      console.log(responseData.body); // outputs "word to your mother."
    }
});

####Place a phone call, and respond with TwiML instructions from the given URL

  twilio = Twilio(ACCOUNT_SID, AUTH_TOKEN);
  twilio.makeCall({
    to:'+16515556677', // Any number Twilio can call
    from: '+14506667788', // A number you bought from Twilio and can use for outbound communication
    url: 'http://www.example.com/twiml.xml' // A URL that produces an XML document (TwiML) which contains instructions for the call
  }, function(err, responseData) {
    //executed when the call has been initiated.
    console.log(responseData.from); // outputs "+14506667788"
  });

####Loop through a list of SMS messages sent from a given number


  twilio = Twilio(ACCOUNT_SID, AUTH_TOKEN);
  twilio.listSms({
    from:'+16512223333'
  }, function (err, responseData) {
    responseData.smsMessages.forEach(function(message) {
        console.log('Message sent on: '+message.dateCreated.toLocaleDateString());
        console.log(message.body);
    });
  });

####Here are a few examples of how to process incoming Voice calls and SMS messages via the Meteor router.

This code is from a production site, feedvenue.com

twilioRawIn is a collection to store the raw input for later.


Meteor.Router.add('/api/twiml/voice', 'POST', function() {
	var rawIn = this.request.body;
	console.log(rawIn);
	if (Object.prototype.toString.call(rawIn) == "[object Object]") {
		twilioRawIn.insert(rawIn);
	}

	var question = {};
	if (rawIn.Body) {
		question.inputQuestion = rawIn.Body;
		question.source = "sms";
	} else if (rawIn.TranscriptionText) {
		question.inputQuestion = rawIn.TranscriptionText;
		question.source = "voicemail";
	} else {
		return;
	}
	question.inputName = rawIn.From;
	    		
	var toOrig = rawIn.To;
	toOrig = toOrig.replace(/\+1/g, "");
	var toPretty = '('+toOrig.substr(0,3)+') '+toOrig.substr(3,3)+'-'+toOrig.substr(6,10);
	var eventDetails = Events.findOne({phone: toPretty});

	if (_.size(eventDetails) == 0) {
		return;
	} else {
		question.slug = eventDetails.slug;
	}

    Meteor.call('questionCreate', question, function(error, res) {

    });

	var xml = '<Response><Say voice="man">Please speak your question after the tone. You may hang up when you\'re finished</Say><Record maxLength="180" transcribe="true" transcribeCallback="https://feedvenue.com/api/twiml/transcribe" /></Response>';
    return [200, {"Content-Type": "text/xml"}, xml];
});


Meteor.Router.add('/api/twiml/sms', 'POST', function() {
	var rawIn = this.request.body;
	if (Object.prototype.toString.call(rawIn) == "[object Object]") {
		twilioRawIn.insert(rawIn);
	}

	var question = {};
	if (rawIn.Body) {
		question.inputQuestion = rawIn.Body;
		question.source = "sms";
	} else if (rawIn.TranscriptionText) {
		question.inputQuestion = rawIn.TranscriptionText;
		question.source = "voicemail";
	} else {
		return;
	}
	question.inputName = rawIn.From;
	    		
	var toOrig = rawIn.To;
	toOrig = toOrig.replace(/\+1/g, "");
	var toPretty = '('+toOrig.substr(0,3)+') '+toOrig.substr(3,3)+'-'+toOrig.substr(6,10);
	var eventDetails = Events.findOne({phone: toPretty});

	if (_.size(eventDetails) == 0) {
		return;
	} else {
		question.slug = eventDetails.slug;
	}

    Meteor.call('questionCreate', question, function(error, res) {

    });

	var xml = '<Response><Sms>Thank you for submitting your question!</Sms></Response>';
    return [200, {"Content-Type": "text/xml"}, xml];
});

Meteor.Router.add('/api/twiml/transcribe', 'POST', function() {
	var rawIn = this.request.body;
	if (Object.prototype.toString.call(rawIn) == "[object Object]") {
		twilioRawIn.insert(rawIn);
	}

	var question = {};
	if (rawIn.Body) {
		question.inputQuestion = rawIn.Body;
		question.source = "sms";
	} else if (rawIn.TranscriptionText) {
		question.inputQuestion = rawIn.TranscriptionText;
		question.source = "voicemail";
	} else {
		return;
	}
	question.inputName = rawIn.From;
	    		
	var toOrig = rawIn.To;
	toOrig = toOrig.replace(/\+1/g, "");
	var toPretty = '('+toOrig.substr(0,3)+') '+toOrig.substr(3,3)+'-'+toOrig.substr(6,10);
	var eventDetails = Events.findOne({phone: toPretty});

	if (_.size(eventDetails) == 0) {
		return;
	} else {
		question.slug = eventDetails.slug;
	}

    Meteor.call('questionCreate', question, function(error, res) {

    });

    return [200, {"Content-Type": "application/json"}, "ok"];
});

For more examples, check out the official Twilio node.js quickstart section: http://twilio.github.io/twilio-node/#quickstart