Skip to content

Python script to send mass text to list of phone numbers in excel sheet using Twilio API

Notifications You must be signed in to change notification settings

pconwell/mass_text

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This is a very basic and simple script to send out a mass number of text (SMS) messages. The texts will be sent at a rate of approximately 1 SMS per second, so if you send 100 SMS messages it will take approximately 100 seconds.

You will need a Twilio account and API keys. Additionally, there is a small charge for each text sent (somewhere around 1,000 SMS per $10).

The script in full can be viewed here. Below, you can see the break down of each step in the script. As you will see, there is not much to it. You will spend more time setting up python (assuming it's not already intalled on your computer) and registering your Twilio account than you will altering and running this script.

Environment

  • Python 3.6
  • Microsoft Excel (will be changed to csv in future version)
  • Twilio account

Code

Import necessary libraries

from twilio.rest import TwilioRestClient
import openpyxl

Enter your Twilio API credentials here. You can get these from your Twilio account settings page

# put your own credentials here

AUTH_SID = '1a2B3c4D' # put your own credentials here
TEST_SID = '1a2B3c4D' # put your own credentials here

AUTH_TOKEN = '1a2B3c4D' # put your own credentials here
TEST_TOKEN = '1a2B3c4D' # put your own credentials here

Turn test mode on or off. Turning test mode on will use the test API keys

test_mode = True

Variables used for the message

position = 'Position'
shift = 'dayshift'
poc = 'Point of Contact'

Sets SID and TOKEN to either production or test keys depepding on if test_mode is set to True or False above

 if test_mode == False:
   token = AUTH_TOKEN
   sid = AUTH_SID
 else:
   token = TEST_TOKEN
   sid = TEST_SID

Set connection to Twilio

client = TwilioRestClient(sid, token)

Connect to and read a column of phone numbers from excel

wb = openpyxl.load_workbook("phone.xlsx")
sheet = wb.get_sheet_by_name(str(position))
col = sheet['B']

Iterate over each phone number in column and send text (or if test_mode == True print phone number to console)

for cell in col:
    if test_mode == True:
        print(cell.value)
    elif test_mode == False:
        client.messages.create(
            to = cell.value,
            from_ = '6155551234', # put your own Twilio phone number here
            body = f'Need {position} to work {shift} today. If you can work, please call {poc}')

About

Python script to send mass text to list of phone numbers in excel sheet using Twilio API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages