forked from ringcentral/ringcentral-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_multipart_mixed.py
executable file
·40 lines (31 loc) · 1.14 KB
/
demo_multipart_mixed.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
#!/usr/bin/env python
# encoding: utf-8
import urllib
from config import USERNAME, EXTENSION, PASSWORD, APP_KEY, APP_SECRET, SERVER, MOBILE
from ringcentral import SDK
def main():
sdk = SDK(APP_KEY, APP_SECRET, SERVER)
platform = sdk.platform()
platform.login(USERNAME, EXTENSION, PASSWORD)
# Step 1. Get an answering rule ID
answering_rules = platform.get('/account/~/extension/~/answering-rule').json().records
last_answer_rule_id = answering_rules[-1].id
print 'Answering rule ID: ' + last_answer_rule_id
# Step 2. Update greeting audio file
binary = (
'test.mp3',
urllib.urlopen('https://freesound.org/data/previews/85/85785_14771-lq.mp3').read(),
'audio/mpeg'
)
builder = sdk.create_multipart_builder()
builder.set_body({
'type': 'Voicemail',
'answeringRule': { 'id': last_answer_rule_id }
})
builder.add(binary)
builder.set_multipart_mixed(True)
request = builder.request('/account/~/extension/~/greeting')
response = platform.send_request(request)
print 'Updated greeting audio: ' + response.json().uri
if __name__ == '__main__':
main()