forked from ringcentral/ringcentral-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_subscription.py
executable file
·44 lines (32 loc) · 1006 Bytes
/
demo_subscription.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
#!/usr/bin/env python
# encoding: utf-8
from multiprocessing import Process
from time import sleep
from ringcentral.subscription import Events
from ringcentral import SDK
from config import USERNAME, EXTENSION, PASSWORD, APP_KEY, APP_SECRET, SERVER
def main():
sdk = SDK(APP_KEY, APP_SECRET, SERVER)
platform = sdk.platform()
platform.login(USERNAME, EXTENSION, PASSWORD)
def on_message(msg):
print(msg)
def pubnub():
try:
s = sdk.create_subscription()
s.add_events(['/account/~/extension/~/message-store'])
s.on(Events.notification, on_message)
s.register()
while True:
sleep(0.1)
except KeyboardInterrupt:
print("Pubnub listener stopped...")
p = Process(target=pubnub)
try:
p.start()
except KeyboardInterrupt:
p.terminate()
print("Stopped by User")
print("Wait for notification...")
if __name__ == '__main__':
main()