-
Notifications
You must be signed in to change notification settings - Fork 2
/
send_mms.py
51 lines (41 loc) · 1.77 KB
/
send_mms.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
from scgapi.Scg import Scg
import scgapi.MessageRequest
import argparse
def upload_attachment(session, path):
res = scgapi.Attachment.Resource(session)
att = res.create_and_upload(path, type="image/jpeg",
name="attachment", filename="attachment.jpg")
print('Uploaded attachment {}'.format(att.id))
return att
def send_mms(api, config, mdn, senderid, attachment):
# 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)
# Upload the attachment to the server.
# Returns an instance of scgapi.Attachment
att = upload_attachment(session, attachment)
# Send the message
# Note that from_ has a padding underscore due to
# syntax constraints in Python.
reqid = res.create(
from_=senderid,
to=[mdn],
attachments=[att.id],
body="Hello, this is a MMS 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('attachment', help='Path to attachment (jpeg picture)')
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_mms(api=args.api, config=args.auth, mdn=args.mdn,
senderid=args.senderid, attachment=args.attachment)