Skip to main content

Triggering a VoiceAgent Call from Salesforce

Trigger CloudTalk VoiceAgent calls directly from Salesforce using Flow Builder and an Apex HTTP callout

V
Written by Valeriia Volobrinskaia

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.164 format (for example, +14155550100)

Set up the integration

Create the Named Credential

First, create an External Credential to store your CloudTalk API key securely:

  1. Go to Setup > Security > Named Credentials > External Credentials.

  2. Click New External Credential:

    • Label: CloudTalk API

    • Name: CloudTalk_API

    • Authentication Protocol: Basic

  3. 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:

  1. Go to Setup > Security > Named Credentials > Named Credentials.

  2. Click New Named Credential:

    • Label: CloudTalk

    • Name: CloudTalk

    • URL: https://api.cloudtalk.io

    • External Credential: CloudTalk API

    • Under Callout Options, enable Generate Authorization Header and Allow Formulas in HTTP Body.

  3. Click Save.

Finally, grant yourself access to the credential:

  1. 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_API principal, and Save.

Create the Apex class

  1. Go to Setup > Apex Classes > New.

  2. Paste the code below, replace YOUR_VOICE_AGENT_ID on 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

  1. Go to Setup > Process Automation > Flows > New Flow.

  2. Select Record-Triggered Flow.

  3. Configure the trigger (Object: Contact or Lead; When: a record is created or a field changes).

  4. Add a condition to filter records, for example only when the phone field is not empty.

  5. Click + > Action and search for "Start CloudTalk Voice Agent Call".

  6. Set the Call Number input value to {!$Record.Phone}.

  7. 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

  1. Create or update a record that meets your trigger conditions.

  2. Check Setup > Debug Logs or the Flow interview details for execution.

  3. 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.io is 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.

Did this answer your question?