Skip to content

Functions ​

With this guide you will learn how to master Functions in uContact, which allow you to create custom developments and enhance the use of the platform through automations.

What are they? ​

Functions are processes that run automatically when a condition is met or a request is received. They can be triggered in three ways:

  • Webhook: When an external service sends data to uContact.
  • Event: When an internal action occurs on the platform.
  • Scheduler: When a programmed date/time or interval is reached.
Scheduler availability

The Scheduler type is only offered to system administrators.

How to create a function? ​

  1. Go to Automations inside the Administrator menu and then click on Functions.

  2. Click the New button located in the top right corner.

  3. Choose the type of function you want to create.

Types of functions ​

In uContact there are three types of functions, each designed to automate actions in a different way.

Webhook ​

Integrates uContact with other applications or external services by receiving data into the platform. Webhooks are triggered by making a GET, POST, PUT or DELETE request to a specific route.

  • Enabled: Turns the Webhook on or off. A disabled Webhook doesn't run.
  • Name: Unique name associated with the Webhook. It is part of the Webhook URL, so it only accepts letters, numbers, -, _ and ., without spaces.
  • URL: The Webhook URL. It is generated when the Webhook is created and appears when you edit it; click the copy icon to copy it.
  • Description: Short text explaining the purpose of the Webhook and what data it processes.

How are they created? ​

  1. Select the Webhook type and optionally add a description that explains the Webhook's purpose. Then click Save.
  2. Once created, the Flow Designer will automatically open, where you can build the custom logic you need.
  3. After you finish designing the flow, click the Deploy button and the flow will be ready to use. If you have any questions about how to use the Flow Designer, you can check the following guide.

Only requests with the following Content-Type are accepted:

  • application/json
  • application/x-www-form-urlencoded

Execution route ​

https://<instance>.ucontactcloud.com/api/webhook/<webhookName>

Replace <instance> with the name of your instance without .ucontactcloud.com. For example, if the instance is https://marketing.ucontactcloud.com and the webhook is called leads:

https://marketing.ucontactcloud.com/api/webhook/leads

Available variables ​

When a webhook flow is executed, global variables are created and available from JavaScript containing request information:

METHOD ​
  • Type: String
  • Description: HTTP method used (GET, POST, PUT, DELETE).
BODY ​
  • Type: Object
  • Description: Request body if application/json.
  • Example:
json
{ "name": "Daniel", "age": 23 }
FORM_PARAMS ​
  • Type: Object
  • Description: Request body if application/x-www-form-urlencoded.
  • Example:
json
{ "param1": "value1", "param2": "value2" }
HEADERS ​
  • Type: Object
  • Description: Headers sent in the request.
  • Example:
json
{
  "Accept": "*/*",
  "Cache-Control": "no-cache",
  "Connection": "close",
  "User-Agent": "PostmanRuntime/7.26.8"
}
QUERY_PARAMS ​
  • Type: Object
  • Description: Parameters sent via URL (key=value).
  • Example:
https://instance.ucontactcloud.com/api/webhook/test?phone=123123&name=John

Generates:

json
{ "phone": "123123", "name": "John" }

What can you do in the flow? ​

Inside a Webhook flow, you can execute all available actions in the Flow Designer, for example:

  • Query the database.
  • Execute uContact API methods.
  • Use any Flow Designer activity.
  • And more!
Webhook Response!
If the SetWebhookResponse activity is not used in the flow, the response is HTTP 200 with the standard API envelope, whose result field contains an echo of the received request (method, path, headers and, when applicable, body/formParams/queryParams). SetWebhookResponse sets the status code, but the body is also wrapped: {status, param: Webhook's response, result: body} when the body is a JSON object, or {status, param, message: body} otherwise. The headers configured in the activity are not applied to the response.

Example ​

A company wants that every time someone completes a form on their website (with name, email, and phone), that data is automatically saved in uContact as a new lead to be called using an Outbound Hub.

  • The website form makes a POST request to the webhook configured in uContact: https://marketing.ucontactcloud.com/api/webhook/leads.
  • In the webhook flow, the received BODY is processed:
json
{ 
  "name": "María Pérez", 
  "email": "maria@example.com", 
  "phone": "59891234567",
  "product": "Credit card"
}
  • With that data, the flow adds the lead into the desired Outbound Hub using uContact’s Leads API. Learn more about uContact APIs in the following guide.

Events ​

Executes actions automatically when an event occurs on the platform.

  • Enabled: Turns the function on or off. A disabled function doesn't run.
  • Name: Unique name associated with the event. It only accepts letters, numbers, -, _ and ., without spaces.
  • Event: Internal uContact action that will trigger the function: Agent logged, Disposition, AgentRingNoAnswer, Agent break, Finish interaction, Assign interaction or New recording.
    • What are these events?
      Learn more about the events and the information each one sends by visiting the following guide.
  • URL: Required. External endpoint to which the event information will be sent via POST. It must be a domain (for example https://monitoring.com/api): IP addresses and localhost are not accepted.
  • Description: Optionally explains what the function will do when triggered and in which cases it is used.

How it works ​

When you create an Event function, uContact creates its flow with a WebService activity that sends the event (BODY) via POST to the configured URL. You can use it as is or edit the flow in the Flow Designer to run your own logic (for example, filtering events or changing the body before sending it).

The function only runs while it is enabled and deployed.

Available variables ​

When an event flow is executed, global variables are created and available from JavaScript containing the event information:

BODY ​
  • Type: Object
  • Description: Event payload, already parsed as a JavaScript object. The shape depends on the event type. See the events reference for the full payload of each event.
  • Example (AgentLog):
json
{
  "event": "AgentLog",
  "date": "2025-08-11 14:32:00",
  "agent": "juanperez",
  "isLogin": true
}
URL ​
  • Type: String
  • Description: External endpoint configured for the event. Useful when the flow needs to forward the event payload to that URL.
Important!

Since BODY is a JavaScript object, if you want to send it as the body in a WebService activity, use ${JSON.stringify(BODY)} in the body field.

Example ​

A company wants that every time a user logs in to uContact, that event is recorded in an external monitoring system.

  • An event is created in uContact of type Agent logged.
  • Every time it occurs, uContact triggers a POST to the configured URL, for example: https://monitoring.com/api/agent-activity.
  • The body sent is the AgentLog event payload:
json
{
  "event": "AgentLog",
  "date": "2025-08-18 09:30:00",
  "agent": "jlopez",
  "isLogin": true
}
  • The external system receives the data and stores a record in its database to later display it in the activity dashboard.

Scheduler ​

Automates tasks that run on a scheduled basis. The form has three tabs: Basic, Configuration and Schedule.

Basic ​

  • Enabled: Indicates whether the task is enabled or not; by default it is enabled. If disabled, it will not run.

  • Name: Unique name associated with the Scheduler.

  • Type: Action to execute when the scheduler is triggered:

    • SQL Script: Executes a script or SQL query on the database.
    • Shell Script: Executes a command or script in the server terminal.
    • Export: Runs a SQL query and generates a CSV file with the result, which is sent to an external server (SFTP) and/or by email.
  • Description: Indicates what task will be performed, the purpose, and any important details.

Warning!

Remember that Schedulers run on the server, so it is not recommended to execute very heavy tasks during production hours. It is advisable to run these tasks outside of peak hours to avoid stability issues while users are working.

Configuration ​

In this tab, you must configure the necessary setup depending on the type of task you selected.

  • SQL Script: Write the SQL statement you want to execute in the database.
  • Shell Script: Write the commands to execute in the server console.
  • Export: Write the SQL statement to obtain the information you want to export. Then choose how to deliver the CSV file:
    • Export to external server: Uploads the file to an SFTP server. Complete Host, Port, Username, Path and Filename, and authenticate with Password and/or Auth key file.
    • Send to email: Sends the file by email. Complete Email, Subject and, optionally, CC and CCO (blind copy).
Important!

A task can't be saved enabled without a script. If you try, uContact shows the message "Cannot save. The Script field is required when the task is enabled." and takes you to the Configuration tab.

Schedule ​

In this tab you select the Timezone (required) in which the schedule is interpreted, and the task execution frequency. The frequency is configured in five tabs: Minutes, Hours, Days of Month, Month and Days of Week. It is not necessary to change all of them; you can combine them according to your specific needs.

Minutes ​
  • Every minute: The task will run every minute.
  • Every x minutes: Allows you to select a specific interval in minutes for task execution.
  • Select minutes: Allows you to select specific minutes at which the task will run.
Hours ​
  • Every hour: The task will run every hour.
  • Every x hours: Allows you to select a specific interval in hours for task execution.
  • Select hours: Allows you to select specific hours at which the task will run.
Days of Month ​
  • Every day: The task will run every day of the month.
  • Select days: Allows you to select specific days of the month on which the task will run.
Month ​
  • Every month: The task will run every month.
  • Select month: Allows you to select specific months in which the task will run.
Days of Week ​
  • Every day: The task will run every day of the week.
  • Select days: Allows you to select specific weekdays on which the task will run.

How to verify the configuration? ​

As you make changes, two boxes below the tabs show the result: Expression shows the cron expression, and Explain shows a description of the execution frequency in words.


Examples of execution ​

Below you will find some examples of task execution frequencies to try out. Each one details the option to choose in each tab.

Task that runs every day at 00:00 ​

  • Minutes: Select minutes → 0
  • Hours: Select hours → 0
  • Days of Month: Every day
  • Month: Every month
  • Days of Week: Every day

Expression: 0 0 * * *

Task that runs every hour every Monday ​

  • Minutes: Select minutes → 0
  • Hours: Every hour
  • Days of Month: Every day
  • Month: Every month
  • Days of Week: Select days → Monday

Expression: 0 * * * 1

Task that runs on the first day of the month at 09:00 ​

  • Minutes: Select minutes → 0
  • Hours: Select hours → 9
  • Days of Month: Select days → 1
  • Month: Every month
  • Days of Week: Every day

Expression: 0 9 1 * *

Task that runs every 15 minutes ​

  • Minutes: Every x minutes → 15
  • Hours: Every hour
  • Days of Month: Every day
  • Month: Every month
  • Days of Week: Every day

Expression: */15 * * * *

Task that runs every 2 hours, from Monday to Friday ​

  • Minutes: Select minutes → 0
  • Hours: Every x hours → 2
  • Days of Month: Every day
  • Month: Every month
  • Days of Week: Select days → Monday, Tuesday, Wednesday, Thursday and Friday

Expression: 0 */2 * * 1,2,3,4,5

Practical example ​

A supervisor wants to receive every day at 9:00 AM a file with the interactions handled the previous day.

  • A Scheduler function is created called daily_interactions_report with type Export, with the SQL query that gets the previous day's interactions.
  • In Configuration, Send to email is checked with the supervisor's email.
  • In Schedule, the supervisor's Timezone is selected and the task is scheduled to run every day at 9:00 AM.
  • Every day, the generated CSV file is sent to the supervisor's email.