# Trigger

The trigger block is what determines which chatbot is to be executed when a user requests a chat.

### Conditions for trigger <a href="#conditions-for-trigger" id="conditions-for-trigger"></a>

As you can have more than one chatbot on your account, the conditions on the trigger help the system qualify the right chatbot for the conversation.

You can also combine multiple conditions using an AND/OR operation.

The conditions on the trigger can be:

| **URL**              | <p>The webpage URL the user is on.</p><p>For example, "URL contains pricing" or "URL equals <https://swiftsell.biz>"</p>                                            |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Browser language** | The default language set by the user on their browser. For example, "Language is French"                                                                            |
| **Date range**       | The date when the user is initiating the chat. For example, you can build a separate chatbot flow that activates during Christmas or for a new launch announcement. |
| **Keyword**          | \[Only for WhatsApp and SMS] The incoming keyword from the user that started the chat. For example, the user sent a keyword containing "Book appointment".          |
| **Button payload**   | \[Only for WhatsApp and SMS] When the user receives a template message from the business and clicks on a button.                                                    |

**Conditions are not mandatory.** If you have not defined any conditions for your chatbots, the first active chatbot on the list will be activated.

### Contact subscription <a href="#contact-subscription" id="contact-subscription"></a>

Applicable only for WhatsApp and SMS.

In channels like WhatsApp and SMS, businesses can reach out to contacts at any time, even if the contact doesn't want to have a conversation.

Countries' laws mandate that companies maintain a subscription status for each contact, meaning that a contact has subscribed or unsubscribed from receiving your communication. This is similar to how unsubscription works on emails.

**SUBSCRIBED -** Will receive any new template message that the company sends as a promotion.

**UNSUBSCRIBED -** Will not receive any template message that the company sends as a promotion.

So, based on the conditions you define for the trigger, you can choose to set the subscription status for the contact.

Generally, you should always have two chatbots:

* Your main chatbot, which has the 'Subscribed' status
* An acknowledgment chatbot for when users type 'STOP.'

### Inject data into the chatbot <a href="#inject-data-into-the-chatbot" id="inject-data-into-the-chatbot"></a>

If you want to send external data to the chatbot, you can use this option. Once enabled, you can map the fields that contain the value with the Swiftsell variable.

Two ways you can inject the data:

#### Using Query params <a href="#using-query-params" id="using-query-params"></a>

With this method, when the Swiftsell snippet is loaded on the website for the first time, the defined query params and their values will be stored in the Swiftsell variable.

For example, if your URL is the following`www.swiftsell.biz?cust_id=1234&plan=9896`

You can choose to store the values of `cust_id` and `plan` on the trigger action block.

<div align="left"><figure><img src="https://help.wotnot.io/~gitbook/image?url=https%3A%2F%2F360969599-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsrMxU8nO3RjusUiYuXBB%252Fuploads%252FFcGmWsh3vcRFCRd6bGsH%252FCleanShot%25202024-06-08%2520at%252011.38.13.png%3Falt%3Dmedia%26token%3D5a79f128-c032-4cf3-935a-5c002f00075d&#x26;width=768&#x26;dpr=2&#x26;quality=100&#x26;sign=744685df&#x26;sv=1" alt=""><figcaption></figcaption></figure></div>

#### Using JSON <a href="#using-json" id="using-json"></a>

With this method, you can inject a JSON payload inside Swiftsell's code snippet and map the objects to be stored in the trigger action block.

To do this you need to add the following object with your desired fields in the Swiftsell code snippet

Copy

```
data-session-payload='{"field1": "value", "field2: "value"}
```

Now, let's take an example to understand this.

Assume you are using the chatbot in your web app and already know the user initiating the chat. For your agents to know the user details, you can add their name, email, customer\_id, plan, etc. to the Swiftsell code snippet.

Copy

```
<script src="" data-session-payload='{"name": "Charles", "phone": "8164848686"}' defer></script>
```

We have stored the “name” and “phone" fields to Swiftsell variables on the trigger action block.

![](https://help.wotnot.io/~gitbook/image?url=https%3A%2F%2F360969599-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FsrMxU8nO3RjusUiYuXBB%252Fuploads%252FdpN4xZDKrAJ0DB5IOTK8%252FCleanShot%25202024-06-08%2520at%252011.45.53.png%3Falt%3Dmedia%26token%3D1b4bcdc4-03fa-40bf-b1eb-ef58f17cb389\&width=768\&dpr=4\&quality=100\&sign=584b136\&sv=1)

{% hint style="info" %}
Note:

* Swiftsell reads this object only once when the code snippet is fired. Sending data after the code snippet loads will not be read.
* Dynamically add the data-session-payload object to the Swiftsell code snippet
  {% endhint %}


---

# Agent Instructions: 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:

```
GET https://docs.swiftsell.biz/bot-builder/action-block/trigger.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
