-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsend_sms.py
37 lines (29 loc) · 1.22 KB
/
send_sms.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
from scgapi.Scg import Scg
import scgapi.MessageRequest
import argparse
def send_sms(api, config, mdn, senderid):
# Construct an instance of the authentication object
# with authentication data from a json file (auth.json)
auth = scgapi.AuthInfo(config=config)
# Prepare a session to the server.
scg = Scg()
# Prepare a session to the server.
session = scg.connect(auth, api)
# Get a MessageRequest resource
res = scgapi.MessageRequest.Resource(session)
# Send the message
# Note that from_ has a padding underscore due to
# syntax constraints in Python.
reqid = res.create(
from_=senderid,
to=[mdn],
body="Hello, this is a SMS message.")
print('Sent message request {}'.format(reqid))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('senderid', help='Sender-id to send from')
parser.add_argument('mdn', help='GSM number to send to')
parser.add_argument('--api', help='URL to the API server', default=None)
parser.add_argument('--auth', help='Location of json auth file', default='auth.json')
args = parser.parse_args()
send_sms(api=args.api, config=args.auth, mdn=args.mdn, senderid=args.senderid)