You can automatically trigger a CloudTalk VoiceAgent call from Salesforce using Flow Builder with an HTTP Callout, backed by an Apex class. This guide shows you how to set up the connection, add the call action, and confirm the call was initiated.
User level: Admin
Before you start
You will need:
A CloudTalk VoiceAgent already created (note the VoiceAgent ID)
CloudTalk API credentials (API Key and Secret)
Salesforce Enterprise edition or above (Flow Builder with HTTP Callout)
A phone field available on your Contact or Lead records, in
E.164format (for example,+14155550100)
Set up the integration
Create the Named Credential
First, create an External Credential to store your CloudTalk API key securely:
Go to Setup > Security > Named Credentials > External Credentials.
Click New External Credential:
Label: CloudTalk API
Name: CloudTalk_API
Authentication Protocol: Basic
Click Save, then under Principals click New:
Choose a name and set Identity Type to Named Principal.
Enter your CloudTalk API Key ID as the username and API Secret as the password.
Click Save.
Next, create the Named Credential that points to CloudTalk:
Go to Setup > Security > Named Credentials > Named Credentials.
Click New Named Credential:
Label: CloudTalk
Name: CloudTalk
URL:
https://api.cloudtalk.ioExternal Credential: CloudTalk API
Under Callout Options, enable Generate Authorization Header and Allow Formulas in HTTP Body.
Click Save.
Finally, grant yourself access to the credential:
Go to Setup > Permission Sets, open (or create) a permission set assigned to you, then go to External Credential Principal Access > Edit, add your
CloudTalk_APIprincipal, and Save.
Create the Apex class
Go to Setup > Apex Classes > New.
Paste the code below, replace
YOUR_VOICE_AGENT_IDon line 3 with your VoiceAgent ID, and Save.
public with sharing class CloudTalkVoiceAgent {
private static final String VOICE_AGENT_ID = 'YOUR_VOICE_AGENT_ID';
@InvocableMethod(label='Start CloudTalk Voice Agent Call' description='Triggers a CloudTalk voice agent call')
public static void invoke(List<Request> requests) {
for (Request r : requests) {
startCall(r.callNumber);
}
}
@future(callout=true)
public static void startCall(String callNumber) {
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:CloudTalk/v1/voice-agent/calls');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setBody(JSON.serialize(new Map<String, Object>{
'call_number' => callNumber,
'voice_agent_id' => VOICE_AGENT_ID
}));
HttpResponse res = new Http().send(req);
System.debug('CloudTalk status: ' + res.getStatusCode());
}
public class Request {
@InvocableVariable(label='Call Number' required=true)
public String callNumber;
}
}Build the Flow
Go to Setup > Process Automation > Flows > New Flow.
Select Record-Triggered Flow.
Configure the trigger (Object: Contact or Lead; When: a record is created or a field changes).
Add a condition to filter records, for example only when the phone field is not empty.
Click + > Action and search for "Start CloudTalk Voice Agent Call".
Set the Call Number input value to
{!$Record.Phone}.Click Save and Activate the Flow.
call_number and voice_agent_id are the only required fields. You can optionally add call_properties, such as system prompt variables (data the VoiceAgent uses during the call) and output variables (data passed back to your endpoint after the call), depending on your VoiceAgent configuration. Learn what to include.
Test and verify
Create or update a record that meets your trigger conditions.
Check Setup > Debug Logs or the Flow interview details for execution.
Confirm in CloudTalk that the VoiceAgent call was initiated.
You're all set! 🚀 Your Salesforce Flow will now automatically trigger a CloudTalk VoiceAgent call whenever a record meets your chosen conditions.
Troubleshooting
Unauthorized callout: ensure
api.cloudtalk.iois added in Remote Site Settings.401 Unauthorized: verify the credentials stored in the External Credential principal.
400 Bad Request: confirm the phone number is in E.164 format (for example,
+14155550100).Flow not triggering: confirm the record satisfies all entry conditions and the Flow is active.
Need help or have a question? Reach out through our Support portal. We're here for you.






