Showing posts with label Twilio. Show all posts
Showing posts with label Twilio. Show all posts

Thursday, July 20, 2017

Simple SMS response for your Django App using Twilo




Twilio allows software developers to programmatically make and receive phone calls and send and receive text messages using its web service APIs.
On this guide we will set up our Django project to send text messages using Twilio.

We will assume that the Django project is already created.

Let's get to work!

1. Create a Twilio account at the Twilio Official page


2. Get a phone number to send messages. To do that we will login with our Twilio account and get one from the console section (you can get the first one for free).


3. Install the twilio-python library on our Django project by typing the following command on the terminal:

$ Pip install twilio
Almost there...

The last thing we have to do is include the code in the view that will be in charge of sending the message:

from twilio.rest import Client
account = "ACXXXXXXXXXXXXXXXXX"
token = "YYYYYYYYYYYYYYYYYY"
client = Client(account, token)

message = client.messages.create(to="+12316851234", from_="+15555555555",
                                 body="Hello there!")
Things to take into account:


  • Your account SID and token are written on your account’s Console section. You should save those fields on your environment variables so that you won’t have that sensible information exposed in your code.

  • You may have to give permissions to send SMS outside the US. Check if the country where you are trying to send a text message is enabled on the SMS Geographic permissions section.

  • The from_ field must be filled up with the number you got for your twilio account.

And that’s it!!
Just call that view from a URL and there you go. Start sending messages!



References: