Capture Calls
Making a Capture call with Dialvox.ai allows you to engage in interactive communication by capturing digits input by the user during the call. This feature is particularly useful for conducting surveys or collecting user feedback over the phone. Here's how you can initiate a Capture call by posting data to the Dialvox.ai API:
Prerequisites
Before making a Capture call, ensure that you have:
- A valid API key from Dialvox.ai.
- The recipient's correct phone number in international format.
- The text you want to convert to speech for the initial prompt and closing remarks.
Making a Capture Call
To make a Capture call, you need to POST
the following JSON data to the Dialvox.ai API URL:
https://api.dialvox.ai/requests/capture
{
"text": "This text will be played when the call is answered",
"text2": "This text will be played after digit is inserted",
"digits": "1",
"language": "en-US",
"phone_number": "005535987654321",
"api_key": "YOUR_API_KEY"
}
Replace YOUR_API_KEY
with your actual API key.
JSON Fields Explanation
text
: The initial prompt message for the recipient.text2
: The closing message after digit capture.digits
: The number of digits expected from the user. For instance,"1"
if you expect a single digit response.language
: The language code for the text-to-speech engine. For example, "pt-BR" for Brazilian Portuguese.phone_number
: The recipient's phone number in international format.api_key
: Your unique API key that authenticates your requests with Dialvox.ai.
Available Languages
Currently, Dialvox supports the following languages for Capture calls:
en-US
- English (United States)es-ES
- Spanish (Spain)de-DE
- German (Germany)pt-BR
- Portuguese (Brazil)en-IN
- English (India)fr-FR
- French (France)hi-IN
- Hindi (India)
Making the HTTP Request
You can use any HTTP client to make the POST
request. Here's are a few examples on how to make the requests
CURL on CMD
curl -X POST "https://api.dialvox.ai/requests/play" \
-H "Content-Type: application/json" \
-d '{
"text": "This text will be played when the call is answered",
"text2": "This text will be played after digit is inserted",
"digits": "1",
"language": "en-US",
"phone_number": "005535987654321",
"api_key": "YOUR_API_KEY"
}'
JavaScript Axios
const axios = require('axios');
const data = {
text: "This text will be played when the call is answered",
text2: "This text will be played after digit is inserted",
digits: "1",
language: "en-US",
phone_number: "005535987654321",
api_key: "YOUR_API_KEY"
};
axios.post('https://api.dialvox.ai/request/capture', data)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error(error);
});
Python Requests
import requests
import json
data = {
"text": "This text will be played when the call is answered",
"text2": "This text will be played after digit is inserted",
"digits": "1",
"language": "en-US",
"phone_number": "005535987654321",
"api_key": "YOUR_API_KEY"
}
response = requests.post('https://api.dialvox.ai/request/capture', json=data)
print(response)
Go native http
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
data := map[string]string{
"text": "This text will be played when the call is answered",
"text2": "This text will be played after digit is inserted",
"digits": "1",
"language": "en-US",
"phone_number": "005535987654321",
"api_key": "YOUR_API_KEY",
}
jsonData, err := json.Marshal(data)
if err != nil {
panic(err)
}
resp, err := http.Post("https://api.dialvox.ai/request/capture", "application/json", bytes.NewBuffer(jsonData))
if err != nil {
panic(err)
}
defer resp.Body.Close()
}
Flutter(Dart) http
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<void> makePlaybackCall() async {
final url = Uri.parse('https://api.dialvox.ai/request/capture');
final headers = {'Content-Type': 'application/json'};
final body = jsonEncode({
'text': 'This text will be played when the call is answered',
'text2':'This text will be played after digit is inserted',
'digits':'1'
'language': 'en-US',
'phone_number': '005535987654321',
'api_key': 'YOUR_API_KEY'
});
try {
final response = await http.post(url, headers: headers, body: body);
if (response.statusCode == 200) {
print('Playback call successful: ${response.body}');
} else {
print('Playback call failed: ${response.body}');
}
} catch (e) {
print('Error occurred while making playback call: $e');
}
}
Java HttpClient
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
public class DialvoxApiExample {
public static void main(String[] args) {
HttpClient client = HttpClient.newHttpClient();
String json = """
{
"text": "This text will be played when the call is answered",
"text2": "This text will be played after digit is inserted",
"digits": "1",
"language": "en-US",
"phone_number": "005535987654321",
"api_key": "YOUR_API_KEY"
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.dialvox.ai/request/capture"))
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(json))
.build();
client.sendAsync(request, BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
}
Note: Always handle your API key with care to avoid exposing it in public or insecure contexts.