# Sending messages via automation

### Basic chat flow

A basic chat flow where agent is a participant of the chatroom along with capabilities to send one-way messages via API (for ex. at the start of the chatroom or updates in between) is achieved as follows.

1. Create a contact
2. Create a chatroom with participants
3. Send a message

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXf-3OyKxVTcIMjKz7tBIjIDJYVQ5IT-natRYgy_WIT3rZQIgk5Dxo9EKv0NVjOFBqryKBb-ewSzbyqJU-a5AA60qp-4ytQqNArDclVVRCrvuVL0XaF9VJ8B08xcRrS-xVGZW8OOgw?key=bGSRkjs4wA34jhlbBI21EoKd" alt=""><figcaption><p>Basic chat flow</p></figcaption></figure>

{% hint style="info" %}
Saleschat provides APIs for basic chat flow.
{% endhint %}

### Send Template Message API

Since WABA requires initialization of a new chat session via a pre-approved template, the API currently allows sending of only template messages via API.

Even during the conversation, any interactive message, for example, messages with buttons, also need to be sent as a template.

### Workflows using templates

Organizations that want to optimize agents time may want to send messages and also process the response via workflow automation.

To be able to achieve this, the Send Template Message API provides a `relay_response` query parameter.

{% hint style="info" %}
**Where will I receive response from the customer?**

The response will be sent to the webhook that is configured for the organization. If the webhook is not configured then the response will not be sent.
{% endhint %}

{% hint style="info" %}
**Which responses will be relayed back to the webhook?**

Only interactions with the templates that have buttons will be relayed back to the webhook. Any message other than interaction with the template, for example, a free flow response will not be sent back to the webhook

{% endhint %}

{% hint style="info" %}
**Will agent be allowed to chat during the workflow?**

Yes, agent will be allowed to send messages even while the workflow is sending messages. The interactions with the template for which relay\_response is set will still be relayed back to the webhook.
{% endhint %}

<figure><img src="/files/DKMjtQw2feQHiletTgIP" alt=""><figcaption></figcaption></figure>

### Silent messaging / Bump

In a basic chat scenario, each message bumps the chatroom to the top of the chatroom list.&#x20;

Organizations may require that while the workflow automation is sending messages as well as any interaction on the template message remain silent and do not bump the chatroom to the top.

To be able to achieve this, the Send Template Message API provides 2 parameters -

1. `bump` - when set to `false` , the chatroom will not be bumped to the top of chatroom list when a template message is sent.&#x20;
2. `bump_response` - when set to `false` , any interaction with the template message will not bump the chatroom to the top of the chatroom list.

{% hint style="info" %}
Free flow (non-interactive) response from the customer will always bump the chatroom to the top of the chatroom list.&#x20;
{% endhint %}

<figure><img src="/files/z8BLexuQVSdDnsUCkzKj" alt=""><figcaption></figcaption></figure>

### Optimizing Agent Participation

A new chatroom for a participant, unlike a message, will always bump it to the top of the chatroom list.&#x20;

In some cases, bots can handle the initial conversation with a new customer. The system sends a message and waits for the customer to respond. On the basis of handover rules, a human agent can step in to manage the interaction. This ensures efficiency and allows agents to focus on engaged customers.

To be able to achieve this, the Create Chatroom API provides a flag `assign_on_handover`

This would also make sure that the chatroom is created but not bumped in the list of chatrooms for the agent, because the agent is not yet a participant of the chatroom.

{% hint style="info" %}
What do you mean by handover?

1. If `assign_on_handover` is set to `true` , then the agent will be assigned to the chatroom only when -
   1. Customer sends a free flow message
   2. There is an interaction with a template sent via STM API and `relay_response` flag is set to `false` (default is `false` )
2. &#x20;Explicit reassignment using Chatroom Reassign API
   {% endhint %}

{% hint style="info" %}
Agent participation can only be optimized at the time of chatroom creation.
{% endhint %}

### Explicit Reassignment

In some cases, organizations may want to send a message to a customer and not wait for response even though `assign_on_handover` was set to `true` .&#x20;

Consider the following scenario -

1. A chatroom was created with `assign_on_handover` set to `true`
2. A message was sent via STM
3. Customer neither interacted with the STM message nor responded with any free flow message
4. Organization would like the agent to follow up manually

To achieve this, you can re-assign chatroom.&#x20;

On explicitly reassigning in this manner, the pending `assign_on_handover` will be discarded.


---

# 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.saleschat.pro/principles/sending-messages-via-automation.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.
