Call Auth. w/ Vonage - JavaScript
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 14 and 15 with the Business API keys.
- Replace lines 35 and 36 with the caller and callee information.
- Replace line 65 with callee information.
- Replace line 77 with your Vonage JWT.
JavaScript Script
Libraries needed
- axios
// CallAuth.js
// Libraries
const axios = require('axios'); // Install with, npm install axios
// Gets First Orion Auth Token
const getToken = async () => {
try {
const response = await axios.post(
'https://api.firstorion.com/v1/auth',
null,
{
headers: {
'X-SERVICE':'auth',
'X-API-KEY': 'your-api-key',
'X-SECRET-KEY': 'your-secret-key',
'Content-Type': 'application/json'
}
}
);
return response.data.token;
} catch (error) {
console.error('Error:', error);
return {
statusCode: error.response ? error.response.status : 500,
body: JSON.stringify({ error: error.message })
};
}
}
// Create Call Authentication push to First Orion for Call Authentication
// Find out more at: https://developer.firstorion.com/firstorion-public/reference/callauthentication
const push_callauth = async (token) => {
let data = JSON.stringify({
"aNumber": '+15555555555',
"bNumber": '+14155550100'
});
let config = {
method: 'post',
url: 'https://api.firstorion.com/exchange/v1/calls/push',
headers: {
'Authorization': token,
'Content-Type': 'application/json'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
}
// Set payload information and authorization credentials
// Read more at https://developer.vonage.com/en/api/voice#createCall
const createCall = async () => {
let data = JSON.stringify({
"to": [
{
"type": "phone",
"number": "14155550100"
}
],
"answer_url": [
"https://example.com/answer"
]
});
let config = {
method: 'post',
url: 'https://api.nexmo.com/v1/calls/',
headers: {
'Authorization': 'Bearer <Vonage JWT>',
'Content-Type': 'application/json'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
}
// Main function to invoke the Call Authentication push for Call Authentication.
const main = async () => {
const token = await getToken();
const push_callauth = await push_callauth(token);
const vonageCall = await createCall()
console.log("Call Auth Info: " + push_callauth)
console.log("Vonage Call Info: " + vonageCall)
}
main()
Responses
Run the Python script in
fouser@FO-user-pc JavaScript % node CallAuth.js
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