Skip to main content

How to Trigger a VoiceAgent Call from a HubSpot

Automate VoiceAgent calls from HubSpot

V
Written by Valeriia Volobrinskaia
Updated today

You can automatically trigger a CloudTalk VoiceAgent call using HubSpot Workflows. This guide shows you how to set up the trigger, pass contact data into CloudTalk, and view enrollment results in HubSpot.

User level: Agent


Before you start

You will need:

  • A CloudTalk VoiceAgent already created

  • CloudTalk API credentials (API Key and Secret)

  • A HubSpot account with access to Workflows

  • Contact properties that include at least a phone number

Create a HubSpot Workflow Trigger

  1. Open HubSpot > Workflows.

  2. Create a new Contact-based workflow.

  3. Choose a trigger type, for example:

    • Property value changed

    • List membership changed
      (Custom fields are also supported.)

  4. Optional: Enable Re-enrollment if you want the same contact to be called multiple times whenever the conditions are met.

Add the Custom Code Action

After setting your trigger:

  1. Click + Add action

  2. Select Data ops > Custom code

  3. Configure the action:

    • Language: Node.js 20.x

    • Secrets: Leave empty

    • Properties to include in code:

      • phone (required)

      • Additional fields as needed, such as name or contactId

These properties become event.inputFields[...] inside the script.

Paste the Code Snippet

const axios = require('axios');
exports.main = async (event, callback) => {
const phone = event.inputFields['phone'];
const name = event.inputFields['name'];
const contactId = event.inputFields['contactId'];

try {
// Convert hs_object_id to integer
const contactIDint = parseInt(contactId, 10);

// Check if conversion was successful
if (isNaN(contactIDint)) {
throw new Error('Invalid hs_object_id: not a number');
}

// Prepare request body
const data = {
call_number: phone,
voice_agent_id: "67eba86558ba995b89e05e08",
call_properties: {
system_prompt: {
variables: {
name: name
}
},
output: {
variables: {
contactID: contactIDint
}
}
}
};

// Send POST request
const response = await axios.post('https://api.cloudtalk.io/v1/voice-agent/calls', data, {
headers: {
'Authorization': 'Basic {{ Auth Header}}',
'Content-Type': 'application/json'
}
});

// Log success and return
console.log('Call triggered successfully:', response.data);
callback({
outputFields: {
status: 'Call triggered successfully'
}
});
} catch (error) {
console.error('Error triggering call:', error.message);
callback({
outputFields: {
status: `Error: ${error.message}`
}
});
}
};

This script:

  • Sends a POST request to the CloudTalk VoiceAgent API

  • Passes the contact’s phone number

  • Optionally passes variables such as first name or Record ID

  • Receives the VoiceAgent output back to your selected endpoint in CloudTalk

Generate the Authorization Header

CloudTalk uses Basic Authentication for API requests.
To generate your encoded value:

  1. Enter your CloudTalk API Key and CloudTalk API Secret
    (found in your CloudTalk Company Settings).

  2. Copy the generated header. It will look similar to: Basic XXXXXXXXX

Replace {{ Auth Header }} in the script with this value.

Publish and Test the Workflow

  1. Save the custom code step.

  2. Click Review and publish.

  3. Decide whether the workflow should:

    • Only run for new contacts matching conditions, or

    • Also run for contacts that already match when the workflow is activated.

  4. Trigger the workflow by updating a property or list membership for a test contact.

Check Enrollment History

To confirm your VoiceAgent call was triggered:

  1. Open the workflow

  2. Go to Performance history > Enrollment history

  3. Find your test contact in the list

You should see the contact enrolled and the action Call triggered successfully if everything worked.

You're all set!

Your HubSpot workflow will now automatically trigger a CloudTalk VoiceAgent call whenever a contact meets your chosen conditions.


If you have any further questions, please do not hesitate to reach out to our Support team, we are always happy to help!

Did this answer your question?