---
title: "Functions"
description: "A non-technical overview of Functions in RevCent, focused on how hosted JavaScript code can run from account events, schedules, URLs, webhooks, Email Templates, AI Assistants, AI Voice Agents, and Payment Profile flows to support custom automation and integrations."
type: "feature"
company: "RevCent"
canonical: "https://revcent.com/documentation/markdown/ecosystem/feature/Function.md"
relationships:
  - name: "Event"
    url: "https://revcent.com/documentation/markdown/ecosystem/feature/Event.md"
  - name: "Email Template"
    url: "https://revcent.com/documentation/markdown/ecosystem/feature/EmailTemplate.md"
  - name: "AI Assistant"
    url: "https://revcent.com/documentation/markdown/ecosystem/feature/AIAssistant.md"
  - name: "AI Voice Agent"
    url: "https://revcent.com/documentation/markdown/ecosystem/feature/AIVoiceAgent.md"
technical_links:
  web_app: "https://kb.revcent.com/en/integrations/functions"
  api:
    section: "https://revcent.com/docs/api/v2#section-functions"
    operations:
      - name: "Get Functions"
        operation_id: "GetFunctions"
        operation: "https://revcent.com/docs/api/v2#operation-GetFunctions"
        schema: "https://revcent.com/documentation/files/api/operation/GetFunctions.json"
      - name: "Create A Function"
        operation_id: "CreateFunction"
        operation: "https://revcent.com/docs/api/v2#operation-CreateFunction"
        schema: "https://revcent.com/documentation/files/api/operation/CreateFunction.json"
      - name: "Get A Function"
        operation_id: "GetFunction"
        operation: "https://revcent.com/docs/api/v2#operation-GetFunction"
        schema: "https://revcent.com/documentation/files/api/operation/GetFunction.json"
      - name: "Edit A Function"
        operation_id: "EditFunction"
        operation: "https://revcent.com/docs/api/v2#operation-EditFunction"
        schema: "https://revcent.com/documentation/files/api/operation/EditFunction.json"
      - name: "Trigger A Function"
        operation_id: "TriggerFunction"
        operation: "https://revcent.com/docs/api/v2#operation-TriggerFunction"
        schema: "https://revcent.com/documentation/files/api/operation/TriggerFunction.json"
      - name: "Delete A Function"
        operation_id: "DeleteFunction"
        operation: "https://revcent.com/docs/api/v2#operation-DeleteFunction"
        schema: "https://revcent.com/documentation/files/api/operation/DeleteFunction.json"
  mcp:
    overview: "https://revcent.com/documentation/markdown/mcp/operation/OverviewFunction.md"
    operations:
      - name: "Get Functions"
        operation_id: "GetFunctions"
        markdown: "https://revcent.com/documentation/markdown/mcp/operation/GetFunctions.md"
        available_via_ai: true
      - name: "Create A Function"
        operation_id: "CreateFunction"
        markdown: "https://revcent.com/documentation/markdown/mcp/operation/CreateFunction.md"
        available_via_ai: true
      - name: "Get A Function"
        operation_id: "GetFunction"
        markdown: "https://revcent.com/documentation/markdown/mcp/operation/GetFunction.md"
        available_via_ai: true
      - name: "Edit A Function"
        operation_id: "EditFunction"
        markdown: "https://revcent.com/documentation/markdown/mcp/operation/EditFunction.md"
        available_via_ai: true
      - name: "Trigger A Function"
        operation_id: "TriggerFunction"
        markdown: "https://revcent.com/documentation/markdown/mcp/operation/TriggerFunction.md"
        available_via_ai: true
      - name: "Delete A Function"
        operation_id: "DeleteFunction"
        markdown: "https://revcent.com/documentation/markdown/mcp/operation/DeleteFunction.md"
        available_via_ai: true
---

# Functions

Functions are RevCent's hosted custom-code feature.

A Function lets a RevCent user write custom JavaScript code and have RevCent execute that code when a configured trigger occurs. The code is hosted and run by RevCent, so the business can add custom behavior without hosting a separate application server.

Conceptually:

```text
Function = hosted JavaScript code
Trigger = what causes the Function to run
Event data = the item, request, or context the Function receives
Callback = how the Function ends and returns success or error
```

Functions are useful when a RevCent account needs custom logic, custom integrations, dynamic customer communication, AI workflow control, or custom payment-flow behavior that is not fully covered by standard settings.

---

## Why Functions Are a Feature

Functions are a feature because they are configurable, reusable pieces of RevCent account behavior.

A user can create a Function, choose when it runs, write JavaScript logic, configure environment variables, select dependencies, and connect the Function to other RevCent features.

Functions are not individual commerce records like Sales, Transactions, or Shipping records. They are account-level automation components that can act on those records when triggered.

---

## Technical Links

| Area | Link |
|---|---|
| Web App | `https://kb.revcent.com/en/integrations/functions` |
| API | `https://revcent.com/docs/api/v2#section-functions` |
| MCP | `https://revcent.com/documentation/markdown/mcp/operation/OverviewFunction.md` |

---

## Core Purpose

Functions allow ecommerce businesses to run custom logic inside RevCent.

Common purposes include:

- reacting to account events,
- sending data to third-party systems through HTTP/API calls,
- receiving data from third-party systems through Function URLs or Webhooks,
- generating custom Email Template data,
- exposing a controlled URL endpoint,
- receiving webhook POSTs,
- running scheduled jobs,
- giving AI Assistants and AI Voice Agents approved custom tools,
- filtering whether an AI Assistant or AI Voice Agent should proceed,
- generating dynamic AI Voice Agent pre-agent context,
- running custom logic inside a Payment Profile flow,
- transforming data before sending it elsewhere,
- using environment variables and Function Values for reusable configuration.

---

## How Functions Are Created

A Function can be created from the RevCent web app or through RevCent API/MCP operations.

At minimum, a Function needs a name. After creation, the user configures the Function details, trigger, code, environment variables, dependencies, and any trigger-specific settings.

Important setup points:

- A RevCent account may need Functions access enabled first.
- The Function name should clearly describe what the Function does.
- The description should explain the trigger, purpose, dependencies, and high-impact behavior.
- Newly created Functions need time to provision before they are editable or runnable.
- If a newly created Function returns a `still provisioning` error, wait at least 30 seconds and try again.
- If it still returns `still provisioning`, wait at least 30 more seconds and retry.

---

## Function Status

Functions have an enabled or disabled status.

A disabled Function should not be treated as active automation. It can be safely configured, reviewed, and tested before enabling.

Best practice:

```text
Create important Functions disabled first.
Review trigger, code, dependencies, and secrets.
Then enable when ready.
```


---

## Trigger Types

The Function trigger determines what causes the Function to run and what kind of data appears in `event.data`.

| Trigger | Purpose |
|---|---|
| Account Event | Runs when a selected RevCent event occurs. |
| Schedule | Runs on a fixed schedule using a five-part cron expression. |
| URL | Runs when a generated Function URL receives a request and returns the Function response. |
| Webhook | Runs when a generated webhook URL receives a POST request and returns a static OK response. |
| Email Template | Runs while compiling an Email Template and returns custom data. |
| API/AI | Runs when triggered by API/MCP, an AI tool call, an AI filter, or an AI Voice Agent pre-agent workflow. |
| Payment Profile | Runs during an existing Payment Profile flow. |

---

## Account Event Trigger

The Account Event trigger runs a Function automatically when a selected RevCent account event occurs.

This is useful for workflows like:

- sale created,
- customer created or updated,
- customer card created,
- subscription renewed,
- trial expired,
- shipping record updated,
- chargeback created,
- fraud detection created,
- transaction created,
- pending refund created,
- note created,
- invoice created.

Account Event Functions receive event-specific information in `event.data`.

Common fields include:

```javascript
event.data.event_date
event.data.event_id
event.data.event_notations
event.data.event_trigger
event.data.item_type
event.data.item_id
event.data.item_event
event.data.item_details
```

The `item_details` object is the detailed RevCent record related to the event.

Account Event Functions can also be filtered by selected Campaigns or shops, depending on configuration.

---

## Schedule Trigger

The Schedule trigger runs a Function using a standard five-part cron expression.

The Function receives an empty string in `event.data`.

Example schedule data:

```javascript
event.data === ""
```

Schedule notes:

- The cron expression uses five parts: minute, hour, day of month, month, day of week.
- Intervals cannot be less than 10 minutes apart.
- Scheduled Functions are checked every 10 minutes, so exact-minute execution may vary by up to 10 minutes.
- Only standard five-part cron expressions are supported.
- Shortcut syntax such as `@daily` is not supported.
- A timezone can be selected for the cron expression.

---

## URL Trigger

The URL trigger creates a Function URL that can be called with GET or POST.

This trigger is useful when an external or internal system needs to request immediate custom logic and receive the Function's response.

Important behavior:

- The Function URL is publicly accessible unless protected by the Function code and/or IP restrictions.
- `event.data` contains the request body as a string when a body is present.
- `context.source` includes request details such as method, content type, IP address, headers, and URL parameters.
- The caller receives the Function response returned through `callback`.

Security guidance:

- Validate secrets, signatures, headers, or URL parameters.
- Use IP restrictions where appropriate.
- Do not return sensitive data unless the request is authenticated.
- Do not rely only on obscurity of the generated URL.

---

## Webhook Trigger

The Webhook trigger creates a webhook URL that accepts POST requests.

This trigger is useful when a third-party system needs to send data to RevCent and does not need a custom response body from the Function.

Important behavior:

- Only POST requests are processed.
- `event.data` contains the webhook request body as a string.
- The Function should parse the body based on `context.source.content_type`.
- RevCent returns a static OK response to the sender.
- The webhook URL is publicly accessible unless protected by the Function code and/or IP restrictions.

Static webhook response:

```json
{
  "result": "OK"
}
```

Security guidance:

- Verify signatures.
- Validate shared secrets.
- Use IP restrictions where appropriate.
- Treat inbound data as untrusted until validated.
- Use idempotency checks when a sender may retry requests.

---

## Email Template Trigger

The Email Template trigger runs a Function while an Email Template is being compiled.

The Function can return a JSON object that becomes available to the Email Template as `custom_data`.

This is useful for:

- custom receipt text,
- customer-specific messaging,
- conditional support details,
- dynamic product-related content,
- external enrichment before email rendering,
- computed template values.

The Function receives item-specific details in:

```javascript
event.data.item_details
```

The Function must return a valid JSON object.

Correct:

```javascript
callback(null, {
  support_email: "support@example.com",
  customer_message: "Thank you for your order."
});
```

Incorrect:

```javascript
callback(null, "support@example.com");
```

The Email Template can then use returned values through `custom_data`.

Example:

```handlebars
{{custom_data.support_email}}
```

---

## API/AI Trigger

The API/AI trigger lets a Function be run directly through API/MCP or by RevCent AI systems.

API/AI Functions can be used as:

- direct API-triggered Functions,
- direct MCP-triggered Functions,
- AI Assistant system tool calls,
- AI Voice Agent system tool calls,
- AI Assistant filter Functions,
- AI Voice Agent filter Functions,
- AI Voice Agent pre-agent Functions.

The source type is visible in:

```javascript
context.source.type
```

Common source types:

```text
api_call
tool_call
filter_function
pre_agent_function
```

---

## Functions in AI Assistant Steps

A Function can be triggered from an AI Assistant step through system tools available to the assistant, such as `TriggerFunction`.

This allows an AI Assistant to run approved custom logic while the assistant is executing a workflow.

Examples:

- parse or transform data,
- call a third-party endpoint,
- add structured metadata to an item,
- notify an external system,
- return a result for the assistant to use in the next step.

When used as a normal AI tool call, custom arguments can be configured so the AI generates values for the Function based on argument names and descriptions.

Custom arguments are available at:

```javascript
event.data.custom_arguments
```

Important distinction:

```text
Normal AI tool call Function = performs custom logic inside a step.
Filter Function = decides whether the AI workflow should run at all.
```

Do not confuse these two uses.

---

## Filter Functions for AI Assistants and AI Voice Agents

A filter Function is a Function used before an AI Assistant or AI Voice Agent proceeds.

The main purpose is to save tokens, prevent unnecessary AI runs, and enforce eligibility rules before AI starts.

A filter Function receives item context in:

```javascript
event.data.item_type
event.data.item_id
event.data.item_details
```

A filter Function must return exactly one of these strings:

```javascript
callback(null, 'pass');
```

or:

```javascript
callback(null, 'fail');
```

Meaning:

- `pass` means the AI Assistant or AI Voice Agent can proceed.
- `fail` means the AI Assistant or AI Voice Agent should not proceed.

A filter Function is mainly for deciding whether an item is worthy of AI processing. It is different from a separate Function triggered within an AI step, which can do anything the user wants based on the assistant workflow.

---

## AI Voice Agent Pre-Agent Functions

A pre-agent Function runs before an AI Voice Agent call begins.

It can generate custom data for the voice agent's instructions. The returned object becomes available in AI Voice Agent Handlebars context under:

```handlebars
{{pre_agent_function.response.property_name}}
```

A pre-agent Function can be used to:

- personalize voice-agent instructions,
- add customer-specific context,
- add product or offer details,
- add call-specific rules,
- retrieve external context before the call,
- change the voice-agent guidance based on item details.

Pre-agent Functions should return a plain JSON object.

Example:

```javascript
callback(null, {
  company_name: "Acme Inc.",
  allow_refund_offer: false,
  call_goal: "Recover declined payment"
});
```

---

## Payment Profile Trigger

The Payment Profile trigger runs a Function during an existing Payment Profile flow.

This is an advanced use case because the Function can influence payment-flow behavior.

A Payment Profile Function may be used to:

- call an external risk system,
- parse payment response details,
- choose a next flow output,
- route to a specific connected node,
- set a gateway for the current flow,
- return a custom error for the flow.

Important safety notes:

- Payment Profile Functions affect active payment behavior.
- Bad code can prevent a payment from processing correctly.
- External requests add latency.
- A timeout or error should have a safe red-output path in the Payment Profile flow.
- Use this trigger only with careful testing and review.

When the Payment Profile flow waits for a Function response, the Function can return routing instructions such as:

```javascript
callback(null, {
  next_output: "1",
  set_gateway_id: "XXXXXXXXXXXXXXXXXXXX"
});
```

This does not mean an AI Assistant can create or modify Payment Profiles. AI Assistants cannot create or modify Payment Profiles.

---

## Function Code Runtime

Function code is JavaScript running in a Node.js 20.x environment.

Important runtime rules:

- The code is already wrapped by RevCent in a handler.
- Do not include your own handler wrapper.
- Use `event`, `context`, and `callback` directly.
- Always call `callback` to end the run.
- No filesystem access is available.
- `require()` and `import` are not supported.
- Dependencies are exposed through the `global` object.
- Function runs do not share memory or state with future runs.
- Too many execution errors may automatically disable a Function.

RevCent wraps the code conceptually like this:

```javascript
function(event, context, callback) {
  // user code runs here
}
```

The user should write code directly inside that environment.

Correct:

```javascript
callback(null, {
  success: true
});
```

Incorrect:

```javascript
exports.handler = async function(event, context, callback) {
  callback(null, {
    success: true
  });
};
```

---

## Callback Requirement

The `callback` function ends the Function run.

Callback shape:

```javascript
callback(error, response);
```

Success example:

```javascript
callback(null, {
  success: true
});
```

Error example:

```javascript
callback('Something went wrong.');
```

Important:

```text
Always call callback.
```

If the Function does not call `callback`, it can timeout and count as an error.

If code continues below a callback, return immediately after calling it when appropriate.

Example:

```javascript
if (!event.data) {
  callback(null, {
    skipped: true
  });
  return;
}
```

---

## Event Argument

The `event` argument contains trigger-specific data.

Most Function logic starts with:

```javascript
event.data
```

Examples:

| Trigger | `event.data` |
|---|---|
| Account Event | Event details and item details. |
| Schedule | Empty string. |
| URL | Request body as a string. |
| Webhook | POST body as a string. |
| Email Template | Item details for the email template trigger. |
| API/AI | Item details and/or custom arguments, depending on source type. |
| Payment Profile | Payment-flow request and flow details. |

---

## Context Argument

The `context` argument contains details about the Function run and source.

Useful paths include:

```javascript
context.source.trigger
context.source.type
context.source.method
context.source.content_type
context.source.ip_address
context.source.headers
context.source.url_params
context.function.id
context.function.name
context.function_run.id
context.dependencies
```

For AI Voice Agent pre-agent or tool-call source types, the context may also include AI Voice Call details.

---

## Dependencies

Functions do not use `require()` or `import`.

Dependencies are available through the `global` object.

Examples:

```javascript
const axios = global['axios'];
const lodash = global['lodash'];
const moment = global['moment'];
```

Dependencies must be selected from RevCent's allowed dependency list. If a dependency is not available, the user must request support for it.

After changing dependencies, allow time for RevCent to bundle them before expecting them to be available in code.

---

## Environment Variables

Functions can use environment variables through:

```javascript
process.env
```

Environment variables can be configured for a specific Function. Sensitive values can be encrypted.

Use environment variables for:

- API keys,
- private tokens,
- webhook secrets,
- external endpoint credentials,
- per-Function configuration,
- sensitive integration values.

Do not hardcode secrets in Function code.

Do not log secrets.

Do not return secrets in callback responses.

---

## Function Values

Function Values are shared values that can be made available to Functions through `process.env`.

They are useful when multiple Functions need the same shared value.

Function-specific environment variables take precedence over Function Values with the same name.

Conceptually:

```text
Function Value = shared value for all Functions
Function environment variable = value specific to one Function
```

Use Function Values for common configuration that should be reused across Functions.

Use Function-specific environment variables for values that apply only to one Function or should override the shared value.

---

## Global RevCent Tools

The `global` object includes a `revcent` property:

```javascript
global['revcent']
```

In Function code, the RevCent helper tools available through `global['revcent']` are limited to:

- `GetKeyValue`
- `UpdateKeyValue`

No other RevCent operations should be assumed to exist inside `global['revcent']`. If a Function needs to interact with another RevCent feature, it should use the appropriate trigger data, external API call, or documented integration path rather than assuming there is a built-in global helper.

### GetKeyValue

`GetKeyValue` retrieves an existing Key Value by key.

```javascript
global['revcent'].GetKeyValue('my_key', function(error, key_value) {
  if (error) {
    callback(error);
    return;
  }

  callback(null, key_value);
});
```

### UpdateKeyValue

`UpdateKeyValue` updates the value of an existing string Key Value. Pointer Key Values cannot be updated from inside a Function.

```javascript
global['revcent'].UpdateKeyValue('my_key', 'Updated string', function(error, key_value) {
  if (error) {
    callback(error);
    return;
  }

  callback(null, key_value);
});
```

Both tools use callbacks. Always handle errors and always end the Function run with `callback`.

---

## External System and Third-Party API Integrations

Functions allow a RevCent account to integrate with virtually any external system that exposes an API, accepts HTTP requests, or sends webhooks.

A Function can act as the bridge between RevCent and outside systems by reading RevCent trigger data, transforming it into the format the external system expects, and sending or receiving HTTP requests.

Common external integration targets include:

- CRMs,
- fulfillment providers,
- warehouse systems,
- helpdesk platforms,
- SMS and email providers,
- Slack or team notification tools,
- fraud and risk systems,
- accounting systems,
- custom business APIs,
- external databases or internal applications.

There are two main integration directions:

```text
Outbound integration = Function calls an external API
Inbound integration = external system calls a Function URL or Webhook URL
```

### Outbound API Calls

For outbound integrations, the Function can use an allowed HTTP dependency such as `axios`, `request`, or `superagent` through the `global` object.

A typical outbound flow is:

```text
RevCent trigger occurs
  ↓
Function receives event.data
  ↓
Function validates and transforms the data
  ↓
Function sends an HTTP request to the external API
  ↓
Function handles the response or error
  ↓
Function ends with callback
```

Example using `axios`:

```javascript
const axios = global['axios'];

const payload = {
  item_type: event.data.item_type,
  item_id: event.data.item_id,
  item_details: event.data.item_details
};

axios.post('https://api.example.com/revcent/events', payload, {
  headers: {
    Authorization: 'Bearer ' + process.env['EXTERNAL_API_TOKEN'],
    'Content-Type': 'application/json'
  },
  timeout: 5000
}).then(function(response) {
  callback(null, {
    sent: true,
    status: response.status
  });
}).catch(function(error) {
  callback(error);
});
```

Use outbound API calls when RevCent should notify or update another system after an event, during an AI workflow, during an Email Template compile step, from a scheduled job, or from a Payment Profile flow.

Examples:

- Send a new Sale to a CRM.
- Send Shipping details to a warehouse system.
- Send a Chargeback alert to Slack.
- Ask an external risk system for a fraud decision.
- Create a support ticket when a customer needs escalation.
- Sync customer or subscription updates to an internal app.

### Inbound Webhooks and Function URLs

For inbound integrations, an external system can call a RevCent Function URL or Webhook URL.

Use a Function URL when the caller needs the custom response returned by the Function.

Use a Webhook URL when the external system only needs to POST data and receive RevCent's static OK response.

Inbound examples:

- A fulfillment provider posts shipment status to a Function webhook.
- A CRM posts customer status changes into RevCent.
- A custom storefront sends checkout data to a Function URL.
- A partner system calls a Function URL to request a computed response.
- A third-party service sends event notifications that the Function validates and processes.

### Authentication and Secrets

External integrations usually require authentication. Store tokens, API keys, webhook secrets, and private endpoint credentials in encrypted Function environment variables.

Do not hardcode secrets in Function code.

Do not expose secrets in callback responses, logs, email content, AI messages, or public URL responses.

For inbound requests, validate the caller before trusting the payload. Common validation patterns include:

- shared secret headers,
- HMAC signatures,
- bearer tokens,
- timestamp checks,
- IP restrictions,
- request body validation,
- idempotency keys.

### Integration Design Rules

When building an external integration with a Function:

1. Choose the correct trigger for the business flow.
2. Confirm the exact `event.data` shape for that trigger.
3. Store external credentials in encrypted environment variables.
4. Validate all inbound data before using it.
5. Transform RevCent data into the external system's expected schema.
6. Use short HTTP timeouts.
7. Handle failed requests intentionally.
8. Avoid duplicate processing with idempotency keys where possible.
9. Return only the data the caller or RevCent workflow actually needs.
10. Always call `callback` to end the Function run.

This makes Functions the primary RevCent feature for connecting account events, AI workflows, Email Templates, Payment Profile flows, URL endpoints, and webhooks to outside systems over HTTP/API calls.

---

## Security Best Practices

Functions can connect RevCent to external systems and can receive public inbound requests, so security matters.

Best practices:

- Store secrets in encrypted environment variables.
- Validate webhook signatures or shared secrets.
- Use IP restrictions for URL and Webhook triggers when possible.
- Validate inbound request body shape before using it.
- Do not log sensitive data.
- Do not return sensitive data from Function URLs unless the request is authenticated.
- Use short external request timeouts.
- Handle errors intentionally.
- Keep Payment Profile Functions especially small and safe.

---

## Common Mistakes to Avoid

Avoid these mistakes:

- creating a Function and immediately editing it before provisioning completes,
- forgetting to call `callback`,
- including a custom handler wrapper,
- using `require()` or `import`,
- assuming Function runs share memory or state,
- returning a string from an Email Template Function instead of a JSON object,
- returning anything other than `pass` or `fail` from a filter Function,
- using a normal AI tool-call Function when a filter Function is required,
- using a filter Function when the goal is to run custom logic inside an AI Assistant step,
- exposing a Function URL without authentication when it returns sensitive data,
- trusting webhook data without validating it,
- hardcoding secrets in code,
- failing to test external API latency before using a Function inside a Payment Profile flow,
- enabling a high-impact Function before reviewing required values and trigger behavior.

---

## Setup Checklist

Before enabling a Function, verify:

- The Function has a clear name.
- The description explains the trigger and purpose.
- The correct trigger type is selected.
- Trigger-specific settings are complete.
- Event filters are correct when using Account Event.
- Schedule cron expression is valid when using Schedule.
- URL or Webhook security is handled when using public endpoints.
- Email Template Functions return a JSON object.
- Filter Functions return exactly `pass` or `fail`.
- Pre-agent Functions return a plain JSON object.
- Payment Profile Functions have safe fallback routing.
- Required environment variables are present.
- Dependencies are selected and bundled.
- Code always calls `callback`.
- Error handling is present.
- The Function has been tested with realistic payloads.

---

## Relationship to Email Templates

Functions can power Email Templates by generating `custom_data` at template compile time.

This lets an Email Template use data that is computed, enriched, or fetched when the email is being prepared.

The Function must return a JSON object, and the Email Template can reference the returned fields through `custom_data`.

---

## Relationship to AI Assistants

AI Assistants can use Functions in two main ways.

First, an AI Assistant can trigger a Function within a step through a system tool such as `TriggerFunction`. This is used when the assistant needs custom logic during the workflow.

Second, an AI Assistant can use a Function as a filter before the assistant proceeds. This is used to decide whether the item should be processed by AI at all.

These are separate patterns and should not be treated as the same thing.

---

## Relationship to AI Voice Agents

AI Voice Agents can use Functions in three main ways.

First, a voice agent can trigger a Function as a normal system tool during a call.

Second, a Function can be used as a filter to decide whether a voice agent should proceed.

Third, a pre-agent Function can run before the call starts and return custom data for voice-agent instructions.

Pre-agent Function output is available through `pre_agent_function.response` in the AI Voice Agent instruction context.

---

## Summary

Functions are RevCent's custom-code feature for ecommerce automation and integrations.

They let users run hosted JavaScript from account events, schedules, URLs, webhooks, Email Templates, AI Assistants, AI Voice Agents, and Payment Profile flows.

The most important concepts are:

```text
Choose the correct trigger.
Understand the event data shape.
Use event, context, and callback correctly.
Keep secrets in environment variables.
Use dependencies through global['module_name'].
Return the correct response shape for each trigger type.
Treat public URLs and webhooks as security-sensitive.
Distinguish filter Functions from normal AI-triggered Functions.
Wait for provisioning before editing newly created Functions.
```

Used carefully, Functions give RevCent accounts a flexible way to add custom business logic while keeping that logic inside the RevCent workflow ecosystem.


---
Document Parent Directory
* [Features](https://revcent.com/documentation/markdown/ecosystem/feature/index.md) - Non-technical markdown documentation for features within the RevCent ecosystem. A feature is a part of the RevCent ecosystem that a user can create and configure.