-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathquick-start.py
executable file
·46 lines (40 loc) · 1.37 KB
/
quick-start.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
#!/usr/bin/env python
from ringcentral import SDK
import os,sys
from dotenv import load_dotenv
load_dotenv()
RECIPIENT = os.environ.get('SMS_RECIPIENT')
rcsdk = SDK( os.environ.get('RC_CLIENT_ID'),
os.environ.get('RC_CLIENT_SECRET'),
os.environ.get('RC_SERVER_URL') )
platform = rcsdk.platform()
try:
platform.login(os.environ.get('RC_USERNAME'),
os.environ.get('RC_EXTENSION'),
os.environ.get('RC_PASSWORD') )
except:
sys.exit("Unable to authenticate to platform. Check credentials.")
def read_extension_phone_number():
try:
resp = platform.get("/restapi/v1.0/account/~/extension/~/phone-number")
jsonObj = resp.json()
except e:
sys.exit("Unable to fetch SMS-enabled phone numbers")
for record in jsonObj.records:
for feature in record.features:
if feature == "SmsSender":
return send_sms(record.phoneNumber)
sys.exit("No SMS-enabled phone number found")
def send_sms(fromNumber):
try:
resp = platform.post('/restapi/v1.0/account/~/extension/~/sms',
{
'from' : { 'phoneNumber': fromNumber },
'to' : [ {'phoneNumber': RECIPIENT} ],
'text' : 'Hello World from Python'
})
jsonObj = resp.json()
except:
sys.exit("Unable to send SMS")
print (jsonObj.messageStatus)
read_extension_phone_number()