> For the complete documentation index, see [llms.txt](https://docs.botdistrikt.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.botdistrikt.com/features/responses/javascript-functions.md).

# Javascript Functions

JavaScript function responses represent a unique and powerful feature in AI chatbots.&#x20;

From e-commerce to travel, healthcare, and finance, you can address an array of use cases and provide valuable solutions to end users.

To navigate to set up JavaScript functions as **Responses:**

1. Select between **Condition Functions** and **Action Functions**

<figure><img src="/files/yG6iaMdGCILzugWeBh8f" alt=""><figcaption><p>Choose between Condition Functions and Action Functions</p></figcaption></figure>

{% hint style="info" %}
**Condition functions** and **Action functions** refer to specific function types that allow your chatbot to evaluate conditions and perform actions accordingly.&#x20;

These functions are used to create dynamic and context-aware responses.

**Condition functions** typically return a Boolean value (true or false) based on the evaluation. Common use cases for condition functions in AI chatbots include:

* **Intent Recognition**: Checking the user's intent.
* **Context Awareness**: Evaluating the conversation context.
* **Validation**: Verifying user input to ensure it meets certain criteria or constraints.
* **Routing**: Deciding which conversation path to follow based on specific conditions.
* **User Authentication**: Checking user authentication/specific permissions to perform certain actions.

**Action functions** perform specific operations based on the outcome of condition functions or as part of the chatbot's response. These functions execute tasks, update data, or trigger external processes to fulfill the user's request or provide a response.

Common use cases for action functions in chatbots include:

* **Sending Messages**: Sending text, images, files, or other media as responses to the user.
* **API Calls**: Making API requests to external services or databases.
* **Database Operations**: Storing or retrieving data from a database.
* **Form Submission**: Handling form submissions or user input.
* **Calculations**: Data processing.
* **Navigation**: Redirecting users to specific sections or pages within the chatbot interface.
  {% endhint %}

1. Once you choose **Condition** from the template, the description and code sample is updated accordingly:

<figure><img src="/files/vWXTwfdqpu9q8DXx5xsi" alt=""><figcaption><p>Example: Condition - Exists</p></figcaption></figure>

Depending upon the choice of condition (exists, equals, or matches regex) or action javascript response (enable, delete), test your function according to the conditions set up.

<figure><img src="/files/hBvVJ1DCnh8pvFxSXs9v" alt=""><figcaption><p>Test Javascript Response</p></figcaption></figure>

**Exists:** For example, if a user inquires about whether X exists on the menu, your bot will use the *exist* function to check.&#x20;

**Equals:** For example, if a user inquires about software updates/weather updates/policy updates, your bot will use the *equal* function to check updates to the said database.&#x20;

**Matches Regex:** For example, when your user introduces themselves with a certain name pattern, then your bot uses *matches regex* to compare name patterns and respond with the name in context.

**Enable:** For example, if your user requests your chatbot to *enable* weather forecasts or monthly email notifications for banking statements, then your bot responds with a respective feature enabling it.&#x20;

**Delete:** Similar to the above use case, if the user requests to *delete* a specific file/associated account, then your bot responds with a respective feature deleting it.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.botdistrikt.com/features/responses/javascript-functions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
