Jaysonvdw Jaysonvdw - 1 year ago 93
Javascript Question

Meteor Twilio SMS functionality issue and animate percentile JS query

Please see attached and kindly assist. Trying to add SMS functionality to a project but I'm getting a "Twilio is not defined error". What am I missing? Also, in terms of the code for the send button, where to I add my user ID, inside the Meteor call?

Then, as a completely unrelated query, with reference to the animated percentile code example, I was wondering if one could use different kinds of custom classes for this effect, say, a glass that appears to "fill up" based on % completeness out of a 100%. Further, could one state that multiple conditions had to be met before this percentage changes? i.e. X amount of forms filled out and X types of tasks assigned to another user in like a project management type app? (hope I'm being clear enough on this)

Your assistance is appreciated.

Example A

Example B

Example C

Answer Source

Twilio developer evangelist here.

Quick bit of StackOverflow advice first. It's best to stick to one question per question. I'm not sure of the percentcircle question you're asking, but I can help with Twilio! I'd recommend editing this question to just the Twilio one and asking the other question in a new question on SO.

Anyway, onto helping you!

Meteor doesn't play nicely with normal npm modules, so you can't just require the Twilio npm module. However, you are in luck as sending an SMS with Twilio is pretty straightforward without the library too.

This code is adapted from Chris Hranj's blog post on the Twilio site about creating a group messaging app with Twilio and Meteor. It uses the HTTP module from Meteor to make a POST request to the Twilio API. Chris also recommends keeping your Twilio credentials in the environment so that they don't get exposed by your Meteor front end.

Meteor.startup(function() {
    'sendSMS': function(phoneNumber, message) {
        'https://api.twilio.com/2010-04-01/Accounts/' +
        process.env.TWILIO_ACCOUNT_SID + '/SMS/Messages.json', {
          params: {
            From: process.env.TWILIO_NUMBER,
            To: phoneNumber,
            Body: message
          // Set your credentials as environment variables
          // so that they are not loaded on the client
            process.env.TWILIO_ACCOUNT_SID + ':' +
        // Print error or success to console
        function (error) {
          if (error) {
          else {
              console.log('SMS sent successfully.');

Check out the post for more details.