Call Auth. w/ Vonage - Python
Pre-requisites
- First Orion Branded Communications agreement
- Access to First Orion Customer Portal
- Vetted and Approved Business
- Ability to originate phone calls from configured phone numbers in calling platform
- Understanding of current calling platform and environment to integrate required API
Generate First Orion API Keys
See the API Credentials Page for more information. API Credential Page
Example
Prepare
- Replace lines 13 and 14 with the Business API keys.
- Replace lines 26 and 27 with the caller and callee information.
- Replace line 53 with callee information.
- Replace line 62 with your Vonage JWT.
Python Script
Libraries needed
- json, requests, os
# CallAuth.py
import json
import requests
import os
def get_token():
url = "https://api.firstorion.com/v1/auth"
headers = {
'X-SERVICE': 'auth',
'content-type': 'application/json',
'X-API-KEY': 'your-api-key',
'X-SECRET-KEY': 'your-secret-key'
}
response = requests.request("POST", url, headers=headers)
data = response.json()
return data['token']
def push_precall(token):
url = "https://api.firstorion.com/exchange/v1/calls/push"
payload = json.dumps({
"aNumber": "+15555555555",
"bNumber": "+14155550100"
})
headers = {
'Authorization': token,
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
data = response.json()
value = {
'statusCode': response.status_code,
'body': data['body']['message']
}
# Return JSON Object
return json.loads(json.dumps(value))
# Set payload information and authorization credentials
# Read more at https://developer.vonage.com/en/api/voice#createCall
def createCall():
url = "https://api.nexmo.com/v1/calls/"
payload = json.dumps({
"to": [
{
"type": "phone",
"number": "14155550100"
}
],
"answer_url": [
"https://example.com/answer"
]
})
headers = {
'Authorization': 'Bearer <Vonage JWT>',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
data = response.json()
# Return JSON Object
return data
# Makes the pre-call push.
token = get_token()
precall = push_precall(token)
vonageCall = createCall()
print("Call Auth Info: " + precall)
print("Twilio Call Info: "+ vonageCall)
Responses
Run the Python script in
fouser@FO-user-pc Python % python3 CallAuth.py
Call Auth Info:
{
"body": {
"message": "Ok"
}
}
Vonage Call Info:
{
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356",
"status": "completed",
"direction": "outbound",
"conversation_uuid": "CON-f972836a-550f-45fa-956c-12a2ab5b7d22"
}
Updated 2 days ago