> For the complete documentation index, see [llms.txt](https://help.talkie.se/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.talkie.se/action-blocks/trigger.md).

# Trigger

Choose when your chatbot starts and pass website data into conversation variables.

The **Trigger** block is the starting point of a chatbot flow. It determines which chatbot opens when a user starts a conversation and can store external data in variables for use in the flow.

### Choose when a chatbot starts

If your account has multiple chatbots, use trigger conditions to select the appropriate one. Combine conditions with **AND** or **OR** to define your rules.

| Condition        | What it checks                                                            | Example or use case              |
| ---------------- | ------------------------------------------------------------------------- | -------------------------------- |
| URL              | The webpage the visitor is on                                             | URL contains `pricing`           |
| Browser language | The visitor’s browser language                                            | Language is French               |
| Date range       | Whether the current date is within a chosen range                         | A seasonal campaign              |
| Keyword          | A keyword sent by the user; WhatsApp and SMS only                         | Book appointment                 |
| Button payload   | A click on a button in a business template message; WhatsApp and SMS only | Route a template button response |

**Default behavior:** Conditions are optional. If no conditions are set, ZyndraAI starts the first active chatbot by default.

### Inject data into the chatbot

Pass information your website already knows, such as a customer ID or a user’s name, into chatbot variables. Website data can be supplied through **URL query parameters** or a **JSON payload** in the widget code snippet.

#### Set up the variable mapping

1. Open the **Trigger** block.
2. Enable **Store/Inject other values into variables**.
3. Under **Variable Name**, select the variable that should receive the value.
4. Under **Object Path/Parameter**, enter the source field name or query parameter name.
5. Use **Add another** for each additional mapping.

**Source and destination are different:** Object Path/Parameter identifies the incoming data. Variable Name selects where ZyndraAI stores it. For the top-level fields below, enter the field name directly, such as `customer_id`, without quotation marks or `#` characters.

#### Using Query params

Use this method when the values are supplied in the webpage URL. The defined query parameters and their values are stored when the widget snippet first loads on the website.

Example URL:

```
https://www.example.com/?cust_id=1234&plan=standard
```

Set up these mappings, choosing your corresponding destination variables:

| Variable Name (destination) | Object Path/Parameter (source) | Value in this example |
| --------------------------- | ------------------------------ | --------------------- |
| Your customer ID variable   | `cust_id`                      | `1234`                |
| Your plan variable          | `plan`                         | `standard`            |

#### Using JSON

Use this method when your website supplies values directly in the widget code snippet. Add a `data-session-payload` attribute containing a valid JSON object to your existing widget `<script>` tag.

**Example only:** Replace `YOUR_EXISTING_WIDGET_URL` with the script URL from your existing ZyndraAI installation. Keep any other attributes required by that installation. The values below are fictional examples.

```html
<script
  src="YOUR_EXISTING_WIDGET_URL"
  data-session-payload='{"name":"Alex","customer_id":"1234","plan":"standard"}'
  defer>
</script>
```

Map the JSON fields in the Trigger block:

| Variable Name (destination) | Object Path/Parameter (source) | Value in this example |
| --------------------------- | ------------------------------ | --------------------- |
| Your name variable          | `name`                         | `Alex`                |
| Your customer ID variable   | `customer_id`                  | `1234`                |
| Your plan variable          | `plan`                         | `standard`            |

**When the payload is read**

**ZyndraAI reads the JSON object once, when the widget code snippet runs. Data supplied after the snippet has loaded will not be read through this mechanism.**

Populate the payload with the appropriate values before the widget snippet runs. For a signed-in user, make sure the relevant user or organization data is available at that point.

Changing the attribute later is not a documented way to update an existing conversation. If your site supports sign-in or organization switching after the widget loads, confirm the supported session-update behavior with ZyndraAI support before relying on it.

**Keep the JSON and HTML valid**

* Use double quotes around JSON property names and string values. The example uses single quotes around the HTML attribute.
* When generating values dynamically, use JSON serialization and your framework’s HTML attribute escaping. Names containing apostrophes or quotation marks must not break the attribute or the JSON.
* Pass only the data the chatbot needs. Keep passwords, API keys and other secrets out of URLs and widget payloads.
* A customer ID supplied by the browser is context, not proof of authorization. Any API that returns customer-specific data must enforce the appropriate access checks.

### WhatsApp Meta Cloud: map incoming messages

For WhatsApp Meta Cloud, use the following paths in **Object Path/Parameter** and select the destination under **Variable Name**.

#### Selected button payload

```
entry[0]['changes'][0].value.messages[0].button.payload
```

#### Selected button text

```
entry[0]['changes'][0].value.messages[0].button.text
```

#### Text message body

```
entry[0]['changes'][0].value.messages[0].text.body
```

These paths apply to the corresponding incoming message type. They are separate from the website JSON payload described above.
