Last active
August 11, 2021 22:44
-
-
Save sboily/3f188e3b661e7f9b847bbd96060aa13a to your computer and use it in GitHub Desktop.
conference_events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from wazo_websocketd_client import Client as Websocket | |
from wazo_auth_client import Client as Auth | |
username = '' | |
password = '' | |
wazo_domain = '' | |
client_id = '' | |
def notify(handler, msg): | |
print(msg) | |
def conference_joined(handler): | |
message = "Participant {} has joined the conference!" | |
notify(handler, message) | |
def conference_left(handler): | |
message = "Participant {} has left the conference!" | |
notify(handler, message) | |
def get_refresh_token(): | |
token_data = auth.token.new('wazo_user', access_type='offline', client_id=client_id) | |
refresh_token = token_data['refresh_token'] | |
return token_data['refresh_token'] | |
def get_token(): | |
token_data = auth.token.new('wazo_user', expiration=3600, refresh_token=refresh_token, client_id=client_id) | |
return token_data['token'] | |
def session_expired(data): | |
token_data = auth.token.new('wazo_user', expiration=3600, refresh_token=refresh_token, client_id=client_id) | |
token = token_data['token'] | |
ws.update_token(token) | |
auth = Auth(wazo_domain, username=username, password=password, verify_certificate=False) | |
refresh_token = get_refresh_token() | |
ws = Websocket(wazo_domain, token=get_token(), verify_certificate=False, debug=False) | |
ws.on('conference_participant_joined', conference_joined) | |
ws.on('conference_participant_left', conference_joined) | |
ws.on('auth_session_expire_soon', session_expired) | |
ws.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment