# How to manually manage comments

{% hint style="success" %}
It works when Instagram is enabled
{% endhint %}

## Configuring a response to an Instagram callback

You need to toggle the switch in the connected Instagram account within the **Messengers** section to enable your bot to respond to comments.

<div data-with-frame="true"><figure><img src="/files/9jePiNhHI33n1f3BBQst" alt="" width="563"><figcaption></figcaption></figure></div>

If Instagram displays "Reconnect to work with comments" under your Official Instagram connection, you need to reconnect Instagram to update the necessary permissions. To do this, click the trash icon in the lower right corner (delete bot).

<div data-with-frame="true"><figure><img src="/files/gZzNlWRszYXgapAdXxTn" alt="" width="563"><figcaption></figcaption></figure></div>

Connect the Instagram account again. How to connect Instagram, [see here.](/chatbot/messengers/instagram/chatbot.md)

{% hint style="warning" %}
When publishing posts as a co-author, all comment notifications will be sent to the account **from which you create** the post.
{% endhint %}

{% hint style="info" %}
It works with comments under Reels as well as under posts.
{% endhint %}

When a user comments on a post, a callback is sent to the bot (you can view it in the **"Clients"** section within the user's dialog).

The callback has the format: `client_wall_reply_new link id: text`

where:

* `link` is the post link
* `id` is the record ID
* `text` is the comment text

<div data-with-frame="true"><figure><img src="/files/gjSie3JdgrqYCSQ9ABFg" alt="" width="563"><figcaption></figcaption></figure></div>

We can work with comments in two ways: reply with your comment or write one message in Direct.

**client\_wall\_reply\_new** -  is a common part of the callback.&#x20;

**client\_wall\_reply\_new\_comment -** if we are interested in comments only on the post

**client\_wall\_reply\_new\_live -** if the comments are only during live broadcast

### How to set up an auto-reply to comments in Direct

{% hint style="warning" %}
Аutomatic response to a comment does NOT open a 24-hour window.
{% endhint %}

Copy the callback and go to the Funnel Constructor section. Create a block of the type "Primary condition check" or "Non-state condition" and paste the copied callback into the condition. We are setting up a check "For the presence of keywords"

{% hint style="warning" %}
ATTENTION! It is **not recommended** to use **numbers** as a trigger for launching a bot. \
\
The post ID can contain these numbers. The bot can respond to any callback that contains these numbers if it chooses a match based on the presence of keywords.
{% endhint %}

If you want to set up a reaction to comments under any post for any comment, then in the terms you specify only **client\_wall\_reply\_new\_comment.**&#x20;

During selecting a match, it sets “Keyword matc&#x68;**".**

<div data-with-frame="true"><figure><img src="/files/pxmLcuzkNKr6VhKvZpRb" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="danger" %}

#### **Important note:**<br>

We recommend using the **"Keyword match"** search type when setting up a callback response.

Remember, the matching logic for a block's condition should be chosen according to your project's settings and requirements. Therefore, be sure to test your chatbot flow thoroughly!

Read about choosing a match in the block condition in the article "[Trigger and match type](/chatbot/builder/setting/trigger/type.md)".
{% endhint %}

If you plan to set up a reaction to a specific post, include `client_wall_reply_new_comment` followed by the post ID in the trigger field.

{% hint style="warning" %}

#### **ATTENTION!**

It is not recommended to use numbers as triggers to launch your bot.

A post ID often consists of numbers. If your bot uses keyword-based matching, it might incorrectly respond to *any* callback containing those numbers.
{% endhint %}

<div data-with-frame="true"><figure><img src="/files/eCjxEUIKr2tdb7Fo18gS" alt="" width="563"><figcaption></figcaption></figure></div>

If you plan to set up a reaction to a specific post, include `client_wall_reply_new_comment` followed by the post ID in the trigger field.

{% hint style="warning" %}

#### **ATTENTION!**

It is not recommended to use numbers as triggers to launch your bot.

A post ID often consists of numbers. If your bot uses keyword-based matching, it might incorrectly respond to *any* callback containing those numbers.
{% endhint %}

<div data-with-frame="true"><figure><img src="/files/BjNV6476q2n6aW93olWp" alt="" width="563"><figcaption></figcaption></figure></div>

In the reply field, enter the text you want to send as a response to this comment.

<div data-with-frame="true"><figure><img src="/files/ylWmgNgqFFLSQxc4VIZv" alt="" width="563"><figcaption></figcaption></figure></div>

Above the message, it indicates that it was sent in response to a comment. If you click on **"View post"**, you will be redirected to the post you commented on.

<div data-with-frame="true"><figure><img src="/files/0ORHW4ITHwVHiLqlMiOi" alt="" width="563"><figcaption></figcaption></figure></div>

If a user leaves a comment that you haven't configured a response for (or if you haven't set up any responses), you can reply to them with a single Direct Message in the **"Clients"** section.

{% hint style="warning" %}
However, if you try to send the user another Direct Message, the second message will not be delivered because responding to a comment does not reopen the 24-hour messaging window.
{% endhint %}

### How to use direct Instagram post links when working with comments

{% hint style="info" %}
To work with comments, you need to enable the **"Respond to comments"** toggle in the Instagram Channels section.
{% endhint %}

When a user comments on a post, a notification appears in the chat within the **Clients** section containing the comment text, and the `instagram_media_url` variable is generated with a link to the publication.

<div data-with-frame="true"><figure><img src="/files/bXBdQdz53D1glUPYQfZd" alt=""><figcaption></figcaption></figure></div>

You can use the `instagram_media_url` variable to set up reactions to comments on specific Instagram posts.

Let's look at an example.

#### Setting up different responses based on which post was commented on

**Task:** The account has several posts, including three featuring products at different prices. Configure responses to comments on these three posts to reply with the exact price. For all other posts, respond with "By agreement." The response should be sent both as a Direct Message and as a comment under the post.

**Solution:**

1. Set up keyword-based reactions for comments on the posts. This means the bot will react to any post where a comment contains the specified keywords.
2. Use the `insta_create_comment` function in the **Calculator** to post a comment under the relevant post, while also setting the response text in the **Message text** field to send a Direct Message. This allows the user to receive the price simultaneously in both the comments and Direct Messages.
3. If a comment containing the keywords appears under any other post, the user will receive a message saying **"by agreement."**

<div data-with-frame="true"><figure><img src="/files/Q1gJuXob9HPaPm5ZZsRc" alt="" width="563"><figcaption></figcaption></figure></div>

Step 1. In the **Start block** trigger field, enter `client_wall_reply_new` followed by the keywords you want to trigger a response. Set the match type to **"Keyword match"**.

Example to copy:

`client_wall_reply_new_comment (price|how many|cost|find out)`

{% hint style="info" %}
If you only want to respond to comments under posts, use `client_wall_reply_new_comment`. If you only want to respond to comments during a live broadcast, use `client_wall_reply_new_live`.
{% endhint %}

{% hint style="info" %}
Comments under Reels work the same way as under simple posts.
{% endhint %}

Step 2. In the **"Calculator"** field, declare a `text` variable. Its value is determined by an IF condition that checks the `instagram_media_url` variable.

*Example to copy (remember to replace the links with your actual post URLs). You can copy the URL from the `instagram_media_url` variable in the client's chat (Clients section) after they comment on the relevant post:*

`text = if(instagram_media_url == "https://www.instagram.com/reel/Cagzkx", "$10", if(instagram_media_url == "https://www.instagram.com/p/CqvCq4", "$29", if(instagram_media_url == "https://www.instagram.com/p/CocLhN", "$35", "Other")))`&#x20;

Step 3. Use the `insta_create_comment` method to post a comment.

Example to copy:&#x20;

`insta_create_comment("#{text}")`

where `#{text}` is the response text we send to the user.

Step 4. In the **Message text** field, enter the variable containing the response for the Direct Message.

In this example, the variable is `#{text}`. The same response is posted as a comment and duplicated in the Direct Message. You can configure different responses for each if needed.

<div data-with-frame="true"><figure><img src="/files/z0ipghxRV101qzjcUCdJ" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="info" %}
`client_wall_reply_new` is the common prefix of the callback. To target only comments under posts, use `client_wall_reply_new_comment`. To target only comments during a live broadcast, use `client_wall_reply_new_live`.
{% endhint %}

### How to post a comment in response to a message under a post or during a live broadcast

{% hint style="info" %}
When working with comments and setting up responses under a post, use a random function and send a variable text. If the bot repeatedly sends identical text, you may encounter the error: "This API call does not support the requested response format." You can learn more about working with [the random function here.](/chatbot/builder/responses.md)
{% endhint %}

Step 1. In the **Clients** section, copy the callback (notification) indicating a comment has been posted, then navigate to the Builder.

<div data-with-frame="true"><figure><img src="/files/GoJRCbCiUkwnCRjVw403" alt="" width="563"><figcaption></figcaption></figure></div>

Step 2. Create a **"Start"** or **"Trigger"** block and paste the copied callback into the **Trigger** field.

<div data-with-frame="true"><figure><img src="/files/jJTzIQaAPIFwHaC1bsWd" alt="" width="563"><figcaption></figcaption></figure></div>

There are several ways to configure the bot's trigger condition.

In this example, the bot responds to comments under **all posts** with the message "reply in comments." To set this up, enter the main callback prefix and the keyword in the condition field:

`client_wall_reply_new_comment reply in comments`

**Important:** set the matching type to **"Keyword match"**.

{% hint style="warning" %}

#### ATTENTION!

It is not recommended to use numbers as triggers to launch your bot.

A post ID often consists of numbers. If your bot uses keyword-based matching, it might incorrectly respond to any callback containing those numbers.
{% endhint %}

{% hint style="info" %}
`client_wall_reply_new` is the common prefix of the callback that triggers for both posts and live broadcasts.

To respond only to comments under posts, use:\
`client_wall_reply_new_comment`

To respond only to comments during a live broadcast, use:\
`client_wall_reply_new_live`
{% endhint %}

{% hint style="warning" %}
There is one specific behavior for live broadcast callbacks (`client_wall_reply_new_live`): the bot will only react **during** the live broadcast. Once the live broadcast ends, the bot will no longer detect comments under it and will not be able to respond.
{% endhint %}

<div data-with-frame="true"><figure><img src="/files/ZO4b2EscSrQTZpe7yxpT" alt="" width="563"><figcaption></figcaption></figure></div>

Step 3. In the **response** field, enter `#{none}`.

Step 4. In the **"Calculator"** field, write:

`insta_create_comment("your comment text response")`

Your comment text should be placed inside the parentheses.

Then, click **"Done"**.

With this configuration, as in the example, the bot-generated comment will be posted in response to any comment under a post containing the keywords "reply in the comments".

*Example of a bot's response to a comment in the comments.*

<div data-with-frame="true"><figure><img src="/files/OsOs6uMs2vM1zPD9eTgJ" alt="" width="375"><figcaption></figcaption></figure></div>

*<mark style="color:green;">**The bot's response to ANY comment under ANY post.**</mark>*

If you enter only the general callback prefix `client_wall_reply_new` in the **"Trigger"** field, your comment will be posted in response to comments under **all posts** (regardless of the text the user wrote).

<div data-with-frame="true"><figure><img src="/files/dUVtnLb3JHQiWZsvg2Y8" alt="" width="563"><figcaption></figcaption></figure></div>

*<mark style="color:green;">**The bot's response to A SPECIFIC PHRASE under ANY post.**</mark>*

If you leave in the "Trigger" field **`client_wall_reply_new`**` ``and the keyword`, then your comment will be sent **in response to the comments with the keyword under all posts.**

<div data-with-frame="true"><figure><img src="/files/tvYUrT6CeXmUFOh4QzPJ" alt="" width="563"><figcaption></figcaption></figure></div>

*<mark style="color:green;">**The bot's response to A SPECIFIC PHRASE under A SPECIFIC post.**</mark>*

Copy the full callback from the clients section and put it in the **Start** block field:

<div data-with-frame="true"><figure><img src="/files/tUiW93t5tyIiQ9Np2Esw" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="warning" %}
You can respond to comments that users leave during a live broadcast (there is a separate key for it **client\_wall\_reply\_new\_live)**.

There is one special feature for live broadcasts: the bot will react only during the broadcast. If the broadcast is over, the bot will not see the comments under this broadcast and can not respond.
{% endhint %}

### How to save comment text to a variable

To save the text of a user's comment, use the `comment_text()` function.

Insert the callback `client_wall_reply_new` in the **Trigger** field. Then, in the **"Calculator"** field, assign the text to a variable—for example, `comm` (you can use any other name):

`comm = comment_text()`

Next, click **"Add condition"** in the calculator and specify:

`comm = comment_text()`

<div data-with-frame="true"><figure><img src="/files/hz0gDGXZuE1RrDODBGOF" alt="" width="563"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/AR4lKt0o7RAxlzk4xOrh" alt="" width="563"><figcaption></figcaption></figure></div>

### How to delete a comment&#x20;

The function `insta_delete_comment(comment_id)` deletes a comment.

If `comment_id` is not provided, the function uses the client variable `instagram_last_comment_id`.

On success, it returns `{"success":true}`. If a non-existent `comment_id` is provided, it returns `{"An unexpected error has occurred. Please retry your request later."}`.

## Working with account mentions

### How to mention in media

When a user tags your profile in their post, your bot will receive the following callback:

<div data-with-frame="true"><figure><img src="/files/eWrlPvBe1mXdIbYOVlIj" alt="" width="563"><figcaption></figcaption></figure></div>

The following variables appear:

<div data-with-frame="true"><figure><img src="/files/P43VtXpGp4ZtEG5agoAJ" alt="" width="563"><figcaption></figcaption></figure></div>

**mention\_caption** — post caption

**post\_url** — post link

**mention\_comments\_count** — number of comments

**mention\_like\_count** — number of likes

**mention\_media\_id** — post id

Let's configure a reaction to respond to a mention.

To do this, create a **"Primary Condition Check"** or **"State with Condition"** block. In the **"Condition"** field, enter `mention_in_media` and set the match type to **"Keyword match"**.

In the **"Calculator"** field, enter the following method:

**reply\_to\_mention**(text)

where `text` is the comment that will appear under the mentioned post. You can specify a variable (inserted without quotes inside the parentheses) or enter the text directly (enclosed in quotes).

**Example:**

Step 1. Go to the builder and create a block with a trigger (**Start** block or **Trigger** block). Then, in the **Trigger** field, specify the callback `mention_in_media`.

<div data-with-frame="true"><figure><img src="/files/lAQ6YiMpguUU2mbnLSDt" alt="" width="563"><figcaption></figcaption></figure></div>

Select **"Mention in post"** in the trigger list, and as the calculator method, choose **"Reply comment to a post"**. Then, enter the text for the reply comment.

Step 2. Click **"Add trigger"**. The trigger along with the method will then be entered into the block:

<div data-with-frame="true"><figure><img src="/files/LfpiULZhEKt7zKrYb8ee" alt="" width="563"><figcaption></figcaption></figure></div>

### How to mention in a comment

When a user tags your account in the comments, the chat will receive a callback like:

<div data-with-frame="true"><figure><img src="/files/qOfslaHTUj5wxKks4QGW" alt="" width="375"><figcaption></figcaption></figure></div>

{% hint style="info" %}
If your account is tagged in a private profile, the callback will not be received.
{% endhint %}

The following variables will also appear in the client card:

* `mention_like_count` — number of likes
* `mention_media_id` — post ID

Let's configure a reaction to respond to a mention in a comment.

To do this, create a **"Start"** or **"Trigger"** block. In the **"Condition"** field, enter `mention_in_comment` and set the match type to **"Keyword match"**.

In the **"Calculator"** field, enter the following method:

**reply\_to\_mention**(text)

where `text` is the comment that will be posted in reply to the mention. You can specify a variable (inserted without quotes inside the parentheses) or enter the text directly (enclosed in quotes).

**Example:**

Step 1. Go to the builder, create a block with a trigger (**Start** block or **Trigger** block), and enter the following callback in the **"Trigger"** field:

<div data-with-frame="true"><figure><img src="/files/lOS4LNEc6ku4UDMFRwKP" alt="" width="563"><figcaption></figcaption></figure></div>

Next, select the condition **"Mention in comment"**.

Step 3. Click on **Calculator** and in the field that appears, enter the method:

`reply_to_mention("Response text for mention in comment")`

<div data-with-frame="true"><figure><img src="/files/ybLhs8K1ONNaxxYu99Um" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="warning" %}
If the 24-hour window is not open in the chat with the user, you **cannot** send a direct message in response to the mention. You can only reply with a comment.

If the 24-hour window **is** open, you can enter text in the **Response** field, which the user will receive as a direct message after your account is mentioned.
{% endhint %}

### How to mention other profiles in the comments under your posts

If someone is tagged in the comments under your account, the variable `mentioned_in_comment` is created in the client card.

<div data-with-frame="true"><figure><img src="/files/MUpvIbooeC54S4ZW8Skr" alt="" width="563"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/Q3jvzCTBAZPLNgOX1D23" alt="" width="375"><figcaption></figcaption></figure></div>

It stores the person's username who was tagged.&#x20;If more than two people are tagged, the usernames are stored in an array.

<div data-with-frame="true"><figure><img src="/files/CiN8gRvISNcNJ54xkvjD" alt="" width="375"><figcaption></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/vH9zP7nSU9qiXhxWOBbw" alt="" width="375"><figcaption></figcaption></figure></div>

If you need to segment users who have tagged two or more friends, you can assign a variable like `len = arr_len(mentioned_in_comment)` and then compare that variable with the desired value.

{% hint style="warning" %}
If the 24-hour messaging window is not open in the chat with the user, you cannot send a direct message in response to the mention. You can only reply with a comment.
{% 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.mavibot.ai/chatbot/messengers/instagram/settings/how-to-manually-manage-comments.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.
