Call Auth. w/ Vonage - Python

Pre-requisites

  1. First Orion Branded Communications agreement
  2. Access to First Orion Customer Portal
  3. Vetted and Approved Business
  4. Ability to originate phone calls from configured phone numbers in calling platform
  5. 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

  1. Replace lines 13 and 14 with the Business API keys.
  2. Replace lines 26 and 27 with the caller and callee information.
  3. Replace line 53 with callee information.
  4. 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"
}