Introduction
Welcome to the QVD Inc. Telefony Pre-Call Hook API! You can use our API to understand how to recieve and respond to API requests from our sanitizer box. This allows you to block, manipulate, or log a call before it connects when using our Telefony.
We have sample implementations in Azure Function, Google Function, and AWS Lambda.
Please note you must respond within 10 seconds to the api request before the default outcome is taken
Pre-Call Hook
Azure Function
module.exports = async function(context) {
const { from, to } = context.req.params;
if (to === '+131300000000') {
context.res = {
status: 200,
body: JSON.stringify({
{
"status": "REJECT",
"code": "503",
"reason": "TCPA Time Window Violation"
}
})
}
return;
} else if (to === '+13150000000') {
context.res = {
status: 200,
body: JSON.stringify({
"status": "CHANGE_DESTINATION",
"code": "+13605551212"
})
}
return;
}
context.res = {
status: 200,
body: JSON.stringify({
"status": "PROCEED"
})
}
};
import azure.functions
import json
def main(req: azure.functions.HttpRequest) -> str:
toNumber = req.params.get('to')
fromNumber = req.params.get('from')
if toNumber is "+131300000000":
response = json.dumps({ "status" : "REJECT", "code" : "503", "reason" : "TCPA Time Window Violation" })
return f'{response}'
elif toNumber is "+13150000000"
response = json.dumps({ "status": "CHANGE_DESTINATION", "code": "+13605551212" })
return f'{response}'
response = json.dumps({ "status": "PROCEED" })
return f'{response}'
Google Function
const functions = require('@google-cloud/functions-framework');
functions.http('processCallHook', (req, res) => {
const { from, to } = req.query;
if (to === '+131300000000') {
res.send(
JSON.stringify({
{
"status": "REJECT",
"code": "503",
"reason": "TCPA Time Window Violation"
}
})
);
return;
} else if (to === '+13150000000') {
res.send(
JSON.stringify({
"status": "CHANGE_DESTINATION",
"code": "+13605551212"
})
);
return;
}
res.send(
JSON.stringify({
"status": "PROCEED"
})
);
});
from flask import escape
import functions_framework
import json
@functions_framework.http
def process_call_hook(request):
request_json = request.get_json(silent=True)
request_args = request.args
toNumber = request_args['to']
fromNumber = request_args['from']
if toNumber is "+131300000000":
return json.dumps({"status" : "REJECT", "code" : "503", "reason" : "TCPA Time Window Violation" })
elif toNumber is "+13150000000"
return json.dumps({ "status": "CHANGE_DESTINATION", "code": "+13605551212" })
return json.dumps({ status: "PROCEED" })
AWS Lambda (Assumes API Gateway Integration)
exports.handler = async (event) => {
const { from, to } = event.queryStringParameters;
if (to === '+131300000000') {
return {
"statusCode": 200,
"body": JSON.stringify({
{
"status": "REJECT",
"code": "503",
"reason": "TCP Time Window Violation"
}
})
}
} else if (to === '+13150000000') {
return {
"statusCode": 200,
"body": JSON.stringify({
"status": "CHANGE_DESTINATION",
"code": "+13605551212"
})
}
}
return {
"statusCode": 200,
"body": JSON.stringify({
"status": "PROCEED"
})
}
};
from __future__ import print_function
import boto3
import json
print('Loading function')
def lambda_handler(event, context):
toNumber = event['params']['querystring']['to']
fromNumber = event['params']['querystring']['from']
if toNumber is "+131300000000":
return { statusCode: 200, body: json.dumps({"status" : "REJECT", "code" : "503", "reason" : "TCPA Time Window Violation" }) }
elif toNumber is "+13150000000"
return { statusCode: 200, body: json.dumps({ status: "CHANGE_DESTINATION", code: "+13605551212" }) }
return { statusCode: 200, body: json.dumps({ status: "PROCEED" }) }
Endpoint https://<CUSTOMERS_ENDPOINT>?code=<AUTH_CODE>&from=<FROM_NUMBER>&to=<DESTINATION_NUMBER>
Method POST
URL Parameters
| Key | Description | Example |
|---|---|---|
| code | represents the provided the API key for the endpoint, provided by you | as783asd89 |
| from | The number that is being used to call out from | +13130000000 |
| to | The number that is being called | +13130000000 |
Responses
The body of the response must be in JSON format and follow one of the three formats below. In the event of an invalid body we will fallback to default outcome.
Allow Call
Once this response is given the call will move forward with connecting the caller to the number
| Key | Description | Example |
|---|---|---|
| status | must be the value PROCEED |
PROCEED |
Decline Call
Once this response is given the call will be declined
| Key | Description | Example |
|---|---|---|
| status | must be the value REJECT |
REJECT |
| code | provides the type of decline for the dialer | 503 |
| reason | provides the reason for the decline for the dialer | TCPA Time Window Violation |
Redirect Call
Once this response is given the call will move forward with connecting the caller to the new number
| Key | Description | Example |
|---|---|---|
| status | must be the value REJECT |
REJECT |
| code | the number to call instead with the + and country code must be included |
+13130000000 |
Response Time
Responses must occur within 10 seconds of callout from our sanitizer. In the event it does not respond in time or a non-200 is returned the system will fall back to default outcome configured for your account.
Default Outcomes
Currently there are two configurable default outcomes. Default outcome flow occurs if timeout, bad body, or non-200 status code occurs. Please work with your sales rep on which option you would like to have setup for your account.
-
Continue with Call
-
Reject Call