Backbench Docs
  • Introduction
  • Getting Started
    • BBLANG
    • Node
    • Python
    • Go
  • Backbench Features and UI workflow
  • API Reference
    • BBLANG
    • Node
    • Python
    • Go
  • 3rd Party Integrations
    • Login using Facebook
    • Login using Google
    • Login with Twitter
    • Login using LinkedIn
    • Connection with MongoDB
    • Connection with MySQL
    • Geo Location Integration
    • Integration with AWS S3
    • Integration with Google Cloud Storage
    • Integration with Razorpay
    • Integration with Stripe
    • Integration with Mailchimp
    • Integration with Segment
    • Sending Emails with SendGrid
    • Sending Emails with Mailgun
    • Sending SMS with Twilio
    • Sending Push Notification with Pushwoosh
  • Troubleshooting and support
    • CNAME Support
    • FAQS
    • Error Codes
  • Testing
Powered by GitBook
On this page
  • What You'll Need
  • Prerequisites for the app
  • Frontend
  • Dependencies
  • Backend
  1. 3rd Party Integrations

Sending SMS with Twilio

What You'll Need

Backbench account - Sign Up, the personal account will always remain free to use.

Twilio account - Its free to Sign Up and trial account would be sufficient to try this example. Twilio gives you one number for free to send text messages from. You can only text or call the pre-verified numbers. If you want to test with more numbers, you'll need to verify each one. The restriction is lifted when you upgrade the account.

Prerequisites for the app

  1. Sign In to Backbench account.

  2. Select +, in the upper right corner to create a Bench. For example, say "bench_one" and select CREATE or hit Enter.

Frontend

  1. Select +, in the upper right corner of file manager to create a html file. For example, say "index.html" and select CREATE or hit Enter.

  2. Copy and paste the code module from below.

  3. Select save.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>SMS service</title>
</head>
<body>
<div id="contact">
    <h1>Send an SMS</h1>
    <form action="/tw" method="post">
        <fieldset>
            <label for="name">Name:</label><br>
            <input type="text" id="name" name="name" placeholder="Enter your full name" /><br><br>

            <label for="phnum">Mobile number with country code:</label><br>
            <input type="num" id="num" name="num" placeholder="Enter your number" /><br><br>

            <label for="message">Message:</label><br>
            <textarea id="message" placeholder="Message" name="message"></textarea><br><br>

            <input type="submit" value="Send message" />
        </fieldset>
    </form>
</div>
</body>
</html>

Dependencies

Only for nodejs. Create a module package.json and paste following code.

package.json
{
   "dependencies":{
      "twilio":"2.1.1"
   }
}

Backend

  1. Select +, in the upper right corner to create a Module. For example, say "send_sms.js" and select CREATE or hit Enter.

  2. Copy and paste the code module from below.

  3. Replace ACCOUNTSID with your accountsid(Dashboard).

  4. Replace AUTHTOKEN with your AuthToken(Dashboard).

  5. Replace TWILIO NUMBER with the generated number from Twilio account.

  6. Select save.

sendsms.js

const accountSid = "ACCOUNTSID";
const authToken = "AUTHTOKEN";

// require the Twilio module and create a REST client
const client = require("twilio")(accountSid, authToken); 

module.exports.endpoint= function(req,cb) {
client.messages.create(
 {
    to: req.body.num,
    from: "TWILIO NUMBER",
    body: req.body.message
  }, function (err, message) {
    console.log(message.sid);
    cb(undefined, {b: "SMS sucessfully sent"});
  });
    
   // cb(undefined, req.body)
}; 
sendSMS(message) -> {
bb:log("Request ", message);

bb:http:post({
    url: "<Twillio URL>",
    auth: {
        username: "Username",
        password: "Password"
    },
    form: message
});
}
sendSMS:handler(req) => {
message = "{{smsbody}}" % req.body
response = sendSMS({
    From: "<Mobole Number>",
    To: req.body.to,
    Body: message
})
bb:log(response);
return response.statusMessage;
}

PreviousSending Emails with MailgunNextSending Push Notification with Pushwoosh

Last updated 6 years ago