How to use Voicemail Detection
In this guide we will show you how to use voicemail detection for calls. Please ensure you have followed our earlier guide on how to make an outbound call with Bandwidth.
Voicemail detection allows you to see if a call is answered by a person or was sent to Voicemail allowing for better use of automated call routing. Additionally, if you design workflows and processes that are directly impacted by who’s answering the phone.
There are two available methods for voicemail detection, synchronous (sync
) or asynchronous (async
) mode. Depending on your needs, async mode can be used to allow a human to interact with the application to minimize silence experienced by the caller while waiting for answering machine detection to complete. If a subsequent machineDetectionComplete
callback indicates that an answering machine answered the call, the application can respond with instructions to modify the call flow. Use sync
mode if you want your application to wait until machine detection is complete regardless of whether a human or answering machine answered the call.
Async mode
When using the async mode, once the machine detection operation is completed, you will receive a machineDetectionComplete callback.
If async mode is selected, the callbackUrl
needs to be specified. Also, you need to return proper BXML on the answer callback in order for the call to not be hung up until the operation is complete hence this is a required field.
- Request Payload
- cURL
- Java
- C#
- Ruby
- NodeJS
- Python
- PHP
Note: Remember to add authentication for your application if needed!
POST https://voice.bandwidth.com/api/v2/accounts/{accountId}
POST https://voice.bandwidth.com/api/v2/accounts/{accountId}
{
"from": "{FROM_NUMBER}",
"to": "{TO_NUMBER}",
"answerUrl": "http://example.com/answer",
"username": "{BANDWIDTH_USERNAME}",
"password": "{BANDWIDTH:PASSWORD}",
"machineDetection": {
"mode": "async",
"detectionTimeout": 15,
"silenceTimeout": 10,
"speechThreshold": 10,
"speechEndThreshold": 5,
"delayResult": false,
"callbackUrl": "http://example.com/machineDetectionCallback",
}
}
Note: Remember to add authentication for your application if needed!
curl 'https://voice.bandwidth.com/api/v2/accounts/{BW_ACCOUNT_ID}/calls' \
-X POST \
-u '{BANDWIDTH_USERNAME}:{BANDWIDTH:PASSWORD}' \
-H 'Content-Type: application/json' \
-d '{
"from": "{BW_NUMBER}",
"to": "{$USER_NUMBER},
"applicationId": "{APPLICATION_ID}",
"answerUrl": "{ANSWER_URL}",
"username": "{BW_USERNAME}",
"password": "{BW_PASSWORD}",
"machineDetection": {
"mode": "async",
"detectionTimeout": 15,
"silenceTimeout": 5,
"speechThreshold": 5,
"speechEndThreshold": 1,
"machineSpeechEndThreshold": 3,
"delayResult": false,
"callbackUrl": "http://example.com/machineDetectionCallback"
}
}'
import com.bandwidth.BandwidthClient;
import com.bandwidth.http.response.ApiResponse;
import com.bandwidth.voice.models.CreateCallRequest;
import com.bandwidth.voice.models.CreateCallResponse;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class Sample {
public static final String USERNAME = System.getenv("BW_USERNAME");
public static final String PASSWORD = System.getenv("BW_PASSWORD");
public static final String ACCOUNT_ID = System.getenv("BW_ACCOUNT_ID");
public static void main(String[] args) {
String voiceApplicationId = System.getenv("BW_VOICE_APPLICATION_ID");
String to = System.getenv("USER_NUMBER");
String from = System.getenv("BW_NUMBER");
String baseUrl = System.getenv("BASE_CALLBACK_URL");
String answerUrl = baseUrl.concat("/answer");
BandwidthClient client = new BandwidthClient.Builder()
.voiceBasicAuthCredentials(USERNAME, PASSWORD)
.build();
MachineDetectionConfiguration amd = new MachineDetectionConfiguration();
machineDetectionConfig.setMode(ModeEnum.ASYNC);
machineDetectionConfig.setCallbackMethod(CallbackMethodEnum.POST);
amd.setCallbackUrl("http://example.com/machineDetectionCallback");
machineDetectionConfig.setDetectionTimeout(15.0);
machineDetectionConfig.setSilenceTimeout(5.0);
machineDetectionConfig.setSpeechThreshold(5.0);
machineDetectionConfig.setSpeechEndThreshold(1.0);
machineDetectionConfig.setDelayResult(false);
CreateCallRequest request = new CreateCallRequest();
request.setApplicationId(voiceApplicationId);
request.setTo(to);
request.setFrom(from);
request.setAnswerUrl(answerUrl);
request.setMachineDetection(amd);
//remember to add auth for your application if needed!
try {
CompletableFuture<ApiResponse<CreateCallResponse>> completableFuture = client.getVoiceClient().getAPIController().createCallAsync(voiceApplicationId, request);
System.out.println(completableFuture.get().getResult());
} catch (InterruptedException | ExecutionException e) {
System.out.println(e.getMessage());
}
}
}
using System;
using System.Threading.Tasks;
using Bandwidth.Standard;
using Bandwidth.Standard.Exceptions;
using Bandwidth.Standard.Voice.Models;
class Program
{
static async Task Main(string[] args)
{
var username = System.Environment.GetEnvironmentVariable("BW_USERNAME");
var password = System.Environment.GetEnvironmentVariable("BW_PASSWORD");
var accountId = System.Environment.GetEnvironmentVariable("BW_ACCOUNT_ID");
var applicationId = System.Environment.GetEnvironmentVariable("BW_VOICE_APPLICATION_ID");
var to = System.Environment.GetEnvironmentVariable("USER_NUMBER");
var from = System.Environment.GetEnvironmentVariable("BW_NUMBER");
var baseUrl = System.Environment.GetEnvironmentVariable("BASE_CALLBACK_URL");
var answerUrl = string.Concat(baseUrl, "/answer");
MachineDetectionConfiguration amd = new MachineDetectionConfiguration() {
CallbackUrl = "http://example.com/machineDetectionCallback",
Mode = ModeEnum.Async,
CallbackMethod = CallbackMethodEnum.POST,
DetectionTimeout = 15.0,
SilenceTimeout = 5.0,
SpeechThreshold = 5.0,
SpeechEndThreshold = 1.0,
DelayResult = false
};
var client = new BandwidthClient.Builder()
.VoiceBasicAuthCredentials(username, password)
.Build();
var request = new CreateCallRequest()
{
ApplicationId = applicationId,
To = to,
From = from,
AnswerUrl = answerUrl,
MachineDetection = amd
//remember to add auth for your application if needed!
};
try
{
var response = await client.Voice.APIController.CreateCallAsync(accountId, request);
Console.WriteLine(response.Data);
}
catch (ApiException e)
{
Console.WriteLine(e.Message);
}
}
}
require 'bandwidth-sdk'
begin
BW_USERNAME = ENV.fetch('BW_USERNAME')
BW_PASSWORD = ENV.fetch('BW_PASSWORD')
BW_ACCOUNT_ID = ENV.fetch('BW_ACCOUNT_ID')
BW_VOICE_APPLICATION_ID = ENV.fetch('BW_VOICE_APPLICATION_ID')
BW_NUMBER = ENV.fetch('BW_NUMBER')
USER_NUMBER = ENV.fetch('USER_NUMBER')
BASE_CALLBACK_URL = ENV.fetch('BASE_CALLBACK_URL')
rescue
p 'Please set the environmental variables defined in the README'
exit(-1)
end
Bandwidth.configure do |config|
config.username = BW_USERNAME
config.password = BW_PASSWORD
end
calls_api_instance = Bandwidth::CallsApi.new
amd_config = Bandwidth::MachineDetectionConfiguration.new(
mode: Bandwidth::MachineDetectionModeEnum::ASYNC,
callback_url: BASE_CALLBACK_URL + '/machineDetection',
callback_method: Bandwidth::CallbackMethodEnum::POST
)
call_body = Bandwidth::CreateCall.new(
application_id: BW_VOICE_APPLICATION_ID,
to: USER_NUMBER,
from: BW_NUMBER,
answer_url: BASE_CALLBACK_URL + '/answer',
machine_detection: amd_config
)
begin
result = calls_api_instance.create_call(BW_ACCOUNT_ID, call_body)
p result.call_id
rescue Bandwidth::ApiError => e
p e.code
end
import { Client, ApiController, ModeEnum, CallbackMethodEnum } from '@bandwidth/voice';
const BW_USERNAME = process.env["BW_USERNAME"];
const BW_PASSWORD = process.env["BW_PASSWORD"];
const BW_ACCOUNT_ID = process.env["BW_ACCOUNT_ID"];
const BW_VOICE_APPLICATION_ID = process.env["BW_VOICE_APPLICATION_ID"];
const BW_NUMBER = process.env["BW_NUMBER"];
const USER_NUMBER = process.env["USER_NUMBER"];
const VOICE_CALLBACK_URL = process.env["VOICE_CALLBACK_URL"];
const client = new Client({
basicAuthUserName: BW_USERNAME,
basicAuthPassword: BW_PASSWORD
});
const controller = new ApiController(client);
const machineDetection = {
mode: ModeEnum.Async,
callbackUrl: baseUrl + "/callbackDetection",
callbackMethod: CallbackMethodEnum.POST,
detectionTimeout: 15.0,
silenceTimeout: 5.0,
speechThreshold: 5.0,
speechEndThreshold: 1.0,
delayResut: false
};
const makeCall = async function() {
try {
const response = await controller.createCall(BW_ACCOUNT_ID, {
applicationId: BW_VOICE_APPLICATION_ID,
to: USER_NUMBER,
from: BW_NUMBER,
answerUrl: VOICE_CALLBACK_URL,
answerMethod: 'POST',
callTimeout: 30,
machineDetection: machineDetection
//remember to add auth for your application if needed!
});
console.log(response.body);
} catch(error) {
console.error(error);
}
}
makeCall();
from bandwidth.bandwidth_client import BandwidthClient
from bandwidth.voice.models.create_call_request import CreateCallRequest
from bandwidth.exceptions.api_exception import APIException
from bandwidth.voice.models.machine_detection_configuration import MachineDetectionConfiguration
from bandwidth.voice.models.callback_method_enum import CallbackMethodEnum
from bandwidth.voice.models.mode_enum import ModeEnum
import os
BW_USERNAME = os.environ["BW_USERNAME"]
BW_PASSWORD = os.environ["BW_PASSWORD"]
BW_ACCOUNT_ID = os.environ["BW_ACCOUNT_ID"]
BW_VOICE_APPLICATION_ID = os.environ["BW_VOICE_APPLICATION_ID"]
BW_NUMBER = os.environ["BW_NUMBER"]
USER_NUMBER = os.environ["USER_NUMBER"]
VOICE_CALLBACK_URL = os.environ["VOICE_CALLBACK_URL"]
bandwidth_client = BandwidthClient(
voice_basic_auth_user_name=BW_USERNAME,
voice_basic_auth_password=BW_PASSWORD
)
voice_client = bandwidth_client.voice_client.client
machine_detection_parameters = MachineDetectionConfiguration()
machine_detection_parameters.mode = ModeEnum.ASYNC
machine_detection_parameters.callback_url = "http://example.com/machineDetectionCallback"
machine_detection_parameters.callback_method = CallbackMethodEnum.POST
machine_detection_parameters.detection_timeout = 15
machine_detection_parameters.silence_timeout = 5
machine_detection_parameters.speech_threshold = 5
machine_detection_parameters.speech_end_threshold = 1
machine_detection_parameters.delay_result = False
body = CreateCallRequest()
body.application_id = BW_VOICE_APPLICATION_ID
body.to = USER_NUMBER
body.mfrom = BW_NUMBER
body.answer_url = VOICE_CALLBACK_URL
body.machine_detection = machine_detection_parameters
#remember to add auth for your application if needed!
try:
response = voice_client.create_call(BW_ACCOUNT_ID, body)
print(response.body.call_id)
except APIException as e:
print(e.response_code)
require "vendor/autoload.php";
$BW_USERNAME = getenv("BW_USERNAME");
$BW_PASSWORD = getenv("BW_PASSWORD");
$BW_ACCOUNT_ID = getenv("BW_ACCOUNT_ID");
$BW_VOICE_APPLICATION_ID = getenv("BW_VOICE_APPLICATION_ID");
$BW_NUMBER = getenv("BW_NUMBER");
$USER_NUMBER = getenv("USER_NUMBER");
$VOICE_CALLBACK_URL = getenv("VOICE_CALLBACK_URL");
$config = new BandwidthLib\Configuration(
array(
'voiceBasicAuthUserName' => $BW_USERNAME,
'voiceBasicAuthPassword' => $BW_PASSWORD,
)
);
$client = new BandwidthLib\BandwidthClient($config);
$voiceClient = $client->getVoice()->getClient();
$machineDetection = new BandwidthLib\Voice\Models\MachineDetectionConfiguration();
$machineDetection->mode = BandwidthLib\Voice\Models\ModeEnum::ASYNC;
$machineDetection->callbackUrl = "http://example.com/machineDetectionCallback";
$machineDetection->callbackMethod = "POST";
$machineDetection->detectionTimeout = 15.0;
$machineDetection->silenceTimeout = 5.0;
$machineDetection->speechThreshold = 5.0;
$machineDetection->speechEndThreshold = 1.0;
$machineDetection->delayResult = true;
$body = new BandwidthLib\Voice\Models\CreateCallRequest();
$body->from = $BW_NUMBER;
$body->to = $USER_NUMBER;
$body->answerUrl = $VOICE_CALLBACK_URL;
$body->applicationId = $BW_VOICE_APPLICATION_ID;
$body->machineDetection = $machineDetection;
#remember to add auth for your application if needed!
try {
$response = $voiceClient->createCall($BW_ACCOUNT_ID, $body);
print_r($response->getResult()->callId);
} catch (BandwidthLib\APIException $e) {
print_r($e->getResponseCode());
}
Sync mode
When using the sync mode, the answer callback is delayed until the machine detection operation is completed. Also, you will not receive a machineDetectionComplete callback in this case.
The only thing needed to use the sync mode is to set the mode itself, since the default is async.
- Request Payload
- cURL
- Java
- C#
- Ruby
- NodeJS
- Python
- PHP
Note: Remember to add authentication for your application if needed!
POST https://voice.bandwidth.com/api/v2/accounts/{accountId}
POST https://voice.bandwidth.com/api/v2/accounts/{accountId}
{
"from": "{FROM_NUMBER}",
"to": "{TO_NUMBER}",
"answerUrl": "http://example.com/answer",
"username": "{BANDWIDTH_USERNAME}",
"password": "{BANDWIDTH:PASSWORD}",
"machineDetection": {
"mode": "sync",
"detectionTimeout": 15,
"silenceTimeout": 10,
"speechThreshold": 10,
"speechEndThreshold": 5,
"delayResult": false,
}
}
Note: Remember to add authentication for your application if needed!
curl 'https://voice.bandwidth.com/api/v2/accounts/{BW_ACCOUNT_ID}/calls' \
-X POST \
-u '{BANDWIDTH_USERNAME}:{BANDWIDTH:PASSWORD}' \
-H 'Content-Type: application/json' \
-d '{
"from": "{BW_NUMBER}",
"to": "{$USER_NUMBER},
"applicationId": "{APPLICATION_ID}",
"answerUrl": "{ANSWER_URL}",
"username": "{BW_USERNAME}",
"password": "{BW_PASSWORD}",
"machineDetection": {
"mode": "sync",
"detectionTimeout": 15,
"silenceTimeout": 5,
"speechThreshold": 5,
"speechEndThreshold": 1,
"machineSpeechEndThreshold": 3,
"delayResult": false,
}
}'
import com.bandwidth.BandwidthClient;
import com.bandwidth.http.response.ApiResponse;
import com.bandwidth.voice.models.CreateCallRequest;
import com.bandwidth.voice.models.CreateCallResponse;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class Sample {
public static final String USERNAME = System.getenv("BW_USERNAME");
public static final String PASSWORD = System.getenv("BW_PASSWORD");
public static final String ACCOUNT_ID = System.getenv("BW_ACCOUNT_ID");
public static void main(String[] args) {
String voiceApplicationId = System.getenv("BW_VOICE_APPLICATION_ID");
String to = System.getenv("USER_NUMBER");
String from = System.getenv("BW_NUMBER");
String baseUrl = System.getenv("BASE_CALLBACK_URL");
String answerUrl = baseUrl.concat("/answer");
BandwidthClient client = new BandwidthClient.Builder()
.voiceBasicAuthCredentials(USERNAME, PASSWORD)
.build();
MachineDetectionConfiguration amd = new MachineDetectionConfiguration();
machineDetectionConfig.setMode(ModeEnum.SYNC);
machineDetectionConfig.setCallbackMethod(CallbackMethodEnum.POST);
machineDetectionConfig.setDetectionTimeout(15.0);
machineDetectionConfig.setSilenceTimeout(5.0);
machineDetectionConfig.setSpeechThreshold(5.0);
machineDetectionConfig.setSpeechEndThreshold(1.0);
machineDetectionConfig.setDelayResult(false);
CreateCallRequest request = new CreateCallRequest();
request.setApplicationId(voiceApplicationId);
request.setTo(to);
request.setFrom(from);
request.setAnswerUrl(answerUrl);
request.setMachineDetection(amd);
//remember to add auth for your application if needed!
try {
CompletableFuture<ApiResponse<CreateCallResponse>> completableFuture = client.getVoiceClient().getAPIController().createCallAsync(voiceApplicationId, request);
System.out.println(completableFuture.get().getResult());
} catch (InterruptedException | ExecutionException e) {
System.out.println(e.getMessage());
}
}
}
using System;
using System.Threading.Tasks;
using Bandwidth.Standard;
using Bandwidth.Standard.Exceptions;
using Bandwidth.Standard.Voice.Models;
class Program
{
static async Task Main(string[] args)
{
var username = System.Environment.GetEnvironmentVariable("BW_USERNAME");
var password = System.Environment.GetEnvironmentVariable("BW_PASSWORD");
var accountId = System.Environment.GetEnvironmentVariable("BW_ACCOUNT_ID");
var applicationId = System.Environment.GetEnvironmentVariable("BW_VOICE_APPLICATION_ID");
var to = System.Environment.GetEnvironmentVariable("USER_NUMBER");
var from = System.Environment.GetEnvironmentVariable("BW_NUMBER");
var baseUrl = System.Environment.GetEnvironmentVariable("BASE_CALLBACK_URL");
var answerUrl = string.Concat(baseUrl, "/answer");
MachineDetectionConfiguration amd = new MachineDetectionConfiguration() {
Mode = ModeEnum.Sync,
CallbackMethod = CallbackMethodEnum.POST,
DetectionTimeout = 15.0,
SilenceTimeout = 5.0,
SpeechThreshold = 5.0,
SpeechEndThreshold = 1.0,
DelayResult = false
};
var client = new BandwidthClient.Builder()
.VoiceBasicAuthCredentials(username, password)
.Build();
var request = new CreateCallRequest()
{
ApplicationId = applicationId,
To = to,
From = from,
AnswerUrl = answerUrl,
MachineDetection = amd
//remember to add auth for your application if needed!
};
try
{
var response = await client.Voice.APIController.CreateCallAsync(accountId, request);
Console.WriteLine(response.Data);
}
catch (ApiException e)
{
Console.WriteLine(e.Message);
}
}
}
require 'bandwidth-sdk'
begin
BW_USERNAME = ENV.fetch('BW_USERNAME')
BW_PASSWORD = ENV.fetch('BW_PASSWORD')
BW_ACCOUNT_ID = ENV.fetch('BW_ACCOUNT_ID')
BW_VOICE_APPLICATION_ID = ENV.fetch('BW_VOICE_APPLICATION_ID')
BW_NUMBER = ENV.fetch('BW_NUMBER')
USER_NUMBER = ENV.fetch('USER_NUMBER')
BASE_CALLBACK_URL = ENV.fetch('BASE_CALLBACK_URL')
rescue
p 'Please set the environmental variables defined in the README'
exit(-1)
end
Bandwidth.configure do |config|
config.username = BW_USERNAME
config.password = BW_PASSWORD
end
calls_api_instance = Bandwidth::CallsApi.new
amd_config = Bandwidth::MachineDetectionConfiguration.new(
mode: Bandwidth::MachineDetectionModeEnum::SYNC,
detection_timeout: 15.0,
silence_timeout: 5.0,
speech_threshold: 5.0,
speech_end_threshold: 1.0,
callback_url: BASE_CALLBACK_URL + '/machineDetection',
callback_method: Bandwidth::CallbackMethodEnum::POST
)
call_body = Bandwidth::CreateCall.new(
application_id: BW_VOICE_APPLICATION_ID,
to: USER_NUMBER,
from: BW_NUMBER,
answer_url: BASE_CALLBACK_URL + '/answer',
machine_detection: amd_config
)
begin
result = calls_api_instance.create_call(BW_ACCOUNT_ID, call_body)
p result.call_id
rescue Bandwidth::ApiError => e
p e.code
end
import { Client, ApiController, ModeEnum, CallbackMethodEnum } from '@bandwidth/voice';
const BW_USERNAME = process.env["BW_USERNAME"];
const BW_PASSWORD = process.env["BW_PASSWORD"];
const BW_ACCOUNT_ID = process.env["BW_ACCOUNT_ID"];
const BW_VOICE_APPLICATION_ID = process.env["BW_VOICE_APPLICATION_ID"];
const BW_NUMBER = process.env["BW_NUMBER"];
const USER_NUMBER = process.env["USER_NUMBER"];
const VOICE_CALLBACK_URL = process.env["VOICE_CALLBACK_URL"];
const client = new Client({
basicAuthUserName: BW_USERNAME,
basicAuthPassword: BW_PASSWORD
});
const controller = new ApiController(client);
const machineDetection = {
mode: ModeEnum.Sync,
callbackMethod: CallbackMethodEnum.POST,
detectionTimeout: 15.0,
silenceTimeout: 5.0,
speechThreshold: 5.0,
speechEndThreshold: 1.0,
delayResut: false
};
const makeCall = async function() {
try {
const response = await controller.createCall(BW_ACCOUNT_ID, {
applicationId: BW_VOICE_APPLICATION_ID,
to: USER_NUMBER,
from: BW_NUMBER,
answerUrl: VOICE_CALLBACK_URL,
answerMethod: 'POST',
callTimeout: 30,
machineDetection: machineDetection
//remember to add auth for your application if needed!
});
console.log(response.body);
} catch(error) {
console.error(error);
}
}
makeCall();
from bandwidth.bandwidth_client import BandwidthClient
from bandwidth.voice.models.create_call_request import CreateCallRequest
from bandwidth.exceptions.api_exception import APIException
from bandwidth.voice.models.machine_detection_configuration import MachineDetectionConfiguration
from bandwidth.voice.models.callback_method_enum import CallbackMethodEnum
from bandwidth.voice.models.mode_enum import ModeEnum
import os
BW_USERNAME = os.environ["BW_USERNAME"]
BW_PASSWORD = os.environ["BW_PASSWORD"]
BW_ACCOUNT_ID = os.environ["BW_ACCOUNT_ID"]
BW_VOICE_APPLICATION_ID = os.environ["BW_VOICE_APPLICATION_ID"]
BW_NUMBER = os.environ["BW_NUMBER"]
USER_NUMBER = os.environ["USER_NUMBER"]
VOICE_CALLBACK_URL = os.environ["VOICE_CALLBACK_URL"]
bandwidth_client = BandwidthClient(
voice_basic_auth_user_name=BW_USERNAME,
voice_basic_auth_password=BW_PASSWORD
)
voice_client = bandwidth_client.voice_client.client
machine_detection_parameters = MachineDetectionConfiguration()
machine_detection_parameters.mode = ModeEnum.SYNC
machine_detection_parameters.callback_method = CallbackMethodEnum.POST
machine_detection_parameters.detection_timeout = 15
machine_detection_parameters.silence_timeout = 5
machine_detection_parameters.speech_threshold = 5
machine_detection_parameters.speech_end_threshold = 1
machine_detection_parameters.delay_result = False
body = CreateCallRequest()
body.application_id = BW_VOICE_APPLICATION_ID
body.to = USER_NUMBER
body.mfrom = BW_NUMBER
body.answer_url = VOICE_CALLBACK_URL
body.machine_detection = machine_detection_parameters
#remember to add auth for your application if needed!
try:
response = voice_client.create_call(BW_ACCOUNT_ID, body)
print(response.body.call_id)
except APIException as e:
print(e.response_code)
require "vendor/autoload.php";
$BW_USERNAME = getenv("BW_USERNAME");
$BW_PASSWORD = getenv("BW_PASSWORD");
$BW_ACCOUNT_ID = getenv("BW_ACCOUNT_ID");
$BW_VOICE_APPLICATION_ID = getenv("BW_VOICE_APPLICATION_ID");
$BW_NUMBER = getenv("BW_NUMBER");
$USER_NUMBER = getenv("USER_NUMBER");
$VOICE_CALLBACK_URL = getenv("VOICE_CALLBACK_URL");
$config = new BandwidthLib\Configuration(
array(
'voiceBasicAuthUserName' => $BW_USERNAME,
'voiceBasicAuthPassword' => $BW_PASSWORD,
)
);
$client = new BandwidthLib\BandwidthClient($config);
$voiceClient = $client->getVoice()->getClient();
$machineDetection = new BandwidthLib\Voice\Models\MachineDetectionConfiguration();
$machineDetection->mode = BandwidthLib\Voice\Models\ModeEnum::SYNC;
$machineDetection->callbackMethod = "POST";
$machineDetection->detectionTimeout = 15.0;
$machineDetection->silenceTimeout = 5.0;
$machineDetection->speechThreshold = 5.0;
$machineDetection->speechEndThreshold = 1.0;
$machineDetection->delayResult = true;
$body = new BandwidthLib\Voice\Models\CreateCallRequest();
$body->from = $BW_NUMBER;
$body->to = $USER_NUMBER;
$body->answerUrl = $VOICE_CALLBACK_URL;
$body->applicationId = $BW_VOICE_APPLICATION_ID;
$body->machineDetection = $machineDetection;
#remember to add auth for your application if needed!
try {
$response = $voiceClient->createCall($BW_ACCOUNT_ID, $body);
print_r($response->getResult()->callId);
} catch (BandwidthLib\APIException $e) {
print_r($e->getResponseCode());
}
Where to next?
Now that you have learnt to see if the call is answered by voicemail, check out some of the available actions in the following guides: