Twilio Textbot


Twilio is an example of a powerful, all purpose messaging API on the web. Its used by thousands of prefessional developers to add messaging - phone calls and text messages - into their apps. For this project, you will send text messages from a web page. You will need to setup user accounts on Twilio and also on Webscript.io, because Twilio will not accept messages directly from a web browser.
NOTE: To get a text, your mobile number will first need to be verified for this Twilio test account.

Here is an example of a finished project


Directions
  1. Create a webform page with 2 input fields, one for a name and one for a message and a “Send” button.”

  2. Add a function that runs when you click the input field. Have it send parameters in a GET URL query to a web script. This looks something like:
    window.location="http://youraccount.webscript.io/showmessage?name=value1&message=value2"

  3. Setup a WebScript account on www.webscript.io.

  4. Create a new Lua script, called something like showmessage. This script should grab the query URL parameters. Here is an example:

    output = "Hello "..request.query.name.." your message is "..request.query.message
    return output.


    Save your script.

  5. Go back to the textbot.html page and modify the URL query to match your twlio account. Test the page to make sure its sending properly. Here is a working example.

  6. Next, setup a twilio account on www.twilio.com.

  7. Get an ACCOUNT SID, and AUTH TOKEN. Buy a Phone Number you can send from. Send a test text message from the twilo dashboard.

  8. Authorize phones that can receive test SMS messages under "Verified Caller IDs"

  9. Go back to WebScript and create a new script called sendtwilio, or similar. Include:
    
    local twilio = require('twilio')
    local ACCOUNTSID =  xxxx 
    local AUTHTOKEN =  yyyy
    local response = twilio.sms(. . .)
    
    
    Look up Lua Twilio script for details.

  10. Update your textbot.html page to send a GET URL query to the new sendtwilio script, with the parameters needed to send a text - number and message.

  11. Test and finish the project till it looks perfect to you.
Have fun and good luck!


(c) 2017 by Code Craft Academy