-
Notifications
You must be signed in to change notification settings - Fork 0
/
TelstraSMS.py
executable file
·45 lines (33 loc) · 929 Bytes
/
TelstraSMS.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
import requests, json
consumerKey = '########################'
consumerSecret = '####################'
# Get an access token from telstra
def getToken():
url = 'https://api.telstra.com/v1/oauth/token'
headers = {
"Content-Type" : "application/x-www-form-urlencoded"
}
data = {
'client_id' : consumerKey,
'client_secret' : consumerSecret,
'grant_type' : 'client_credentials',
'scope' : 'SMS'
}
# Send the request
token = requests.post(url, headers=headers, data=data)
# return the token received
return token.json()['access_token']
# send an sms
def sendSMS(number, message, accessToken):
url = 'https://api.telstra.com/v1/sms/messages'
headers = {
"Content-Type" : "application/json",
"Authorization" : "Bearer " + accessToken
}
data = {
'to' : number,
'body' : message
}
message = requests.post(url, headers=headers, data=json.dumps(data))
# return the message id
return message