Skip to content

Instantly share code, notes, and snippets.

@ggarber
Created September 28, 2016 18:02
Show Gist options
  • Save ggarber/3b8f2adea7ac262e181a18ddc657cb1d to your computer and use it in GitHub Desktop.
Save ggarber/3b8f2adea7ac262e181a18ddc657cb1d to your computer and use it in GitHub Desktop.
import requests
import jwt
import time
import sys
import json
from opentok import OpenTok, MediaModes
API_KEY = ""
API_SECRET = ""
ot = OpenTok(API_KEY, API_SECRET)
session_id = ot.create_session(media_mode=MediaModes.routed).session_id
token = jwt.encode({"scope": "call.create", "iss": API_KEY, "ist": "project", "exp": int(time.time()) + 3600}, API_SECRET);
data = {
'sessionId': session_id,
'token': ot.generate_token(session_id),
'sip': {
'uri': 'sip:aaa@domain.com;transport=tls',
'auth': {
'username': 'blah',
'password': 'blah'
}
}
}
headers = {
'Content-Type': 'application/json',
'X-OPENTOK-AUTH': token
}
res = requests.post("https://api.opentok.com/v2/project/" + API_KEY + "/dial", headers=headers, data=json.dumps(data))
print res.status_code, res.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment