-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwillioTextBot.py
72 lines (56 loc) · 1.73 KB
/
TwillioTextBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# testTwillio.py
from twilio.rest import Client
import emoji
# TWILLIO SENDER INFORMATION
ACCOUNT_SID = '<your-account-sid>'
AUTH_TOKEN = '<your-account-authToken>'
SENDER_PHONE_NUMBER = '<your-sender-phone-number>'
def main():
phone_numbers = get_phone_numbers()
twilioCli = Client(ACCOUNT_SID, AUTH_TOKEN)
msg = get_message()
for i in range(len(phone_numbers)):
try:
# Send message
message = twilioCli.messages.create(
body=msg,
from_=SENDER_PHONE_NUMBER,
to=phone_numbers[i])
except:
print('Error, returning')
break
# Log the msg send
print('Sent message #' + str(i+1) + ' sid = ' + str(message.sid) + '; message sent to ' + str(message.to))
def normalize(el):
return el.replace(' ','').replace('(','').replace(')','').replace('-','').replace('+1','')
def get_phone_numbers():
phone_numbers = [
'+1(123)-456-7890',
'+1(123)-456-7890',
'+1(123)-456-7890',
'+1 (123) 456-7890',
'+1(123)-456-7890',
'123)456-7890',
]
phone_numbers = list(set(list(map(normalize, phone_numbers))))
return phone_numbers
def get_message():
# Adding emoji's to text messages
msgTop = \
str(chr(int('1F334', 16)))*10 + '\n' + \
str(chr(int('1F48E', 16))) + \
' MESSAGE TITLE ' + \
str(chr(int('1F48E', 16))) + '\n' + \
str(emoji.emojize(":palm_tree:"))*10
msg = msgTop + """
Insert
Your
Multiline
Message
Or maybe a link: https://bit.ly/3shY6wt
""" + str(chr(int('1F3A9', 16)))
return msg
if __name__ == '__main__':
print('BEGIN')
main()
print('END PROGRAM')