# API Facebook

### What is a persistent menu

A persistent menu allows you to create and send a menu of your business’s main functions, such as business hours, store locations, and products. It will always be visible during a person’s conversation with your company in Messenger.

<figure><img src="/files/2cLEwEACUiRmoW8OoO62" alt="" width="230"><figcaption></figcaption></figure>

#### Supported buttons:

The persistent menu consists of a set of buttons. The following types of buttons are supported in the persistent menu:

● URL buttons (web\_url)\
● Callback buttons (postback)

### How to add a persistent menu for a specific page

**response = fb\_set\_persistent\_menu("group\_id", buttons)**, where:\
**group\_id** - Facebook bot ID, (can be found in the **"Channel"** MaviBot menu)\
**buttons** - a dictionary containing buttons

**Example of how to structure the button dictionary**:\
buttons = {"default": \[\["postback", "Button 1", "callback\_text 1"], \["postback", "Button 2", "callback\_text 2"], \["web\_url", "Site link", "<https://mavibot.ai/"]]}>

**default** - a required key that defines the array of buttons to be shown in the menu by default, regardless of the user's localization.\
The value should be an array of buttons. Each button is described as a separate array in the following format:\
\["button\_type", "Button display text", "Callback text sent to the bot"]

**Button types and their description:**\
\&#xNAN;*- callback button:*\
\["postback", "Button display text", "Callback text sent to the bot"]\
\&#xNAN;*- URL button:*\
\["web\_url", "Link display text", "<https://example.com>"]

### How to configure the menu based on user localization

You can set up buttons for different regions by adding additional keys to the button dictionary corresponding to specific locales.

For example, to add buttons for English locale:

buttons = {"default": \[\["postback", "Button 1", "callback\_text 1"], \["postback", "Button 2", "callback\_text 2"], \["web\_url", "Site link", "<https://mavibot.ai/>"]], **"en\_EN"**: \[\["postback", "Button", "callback\_text 1"], \["postback", "Button 2", "callback\_text 2"], \["web\_url", "Link", "<https://mavibot.ai/"]]}>

{% hint style="info" %}
Note: In this case, the key represents the locale for which the buttons will be displayed.
{% endhint %}

**Supported locales**:\
af\_ZA, ar\_AR, as\_IN, az\_AZ, be\_BY, bg\_BG, bn\_IN, br\_FR, bs\_BA, ca\_ES, cb\_IQ, co\_FR, cs\_CZ, cx\_PH, cy\_GB, da\_DK, de\_DE, el\_GR, en\_GB, en\_UD, en\_US, es\_ES, es\_LA, et\_EE, eu\_ES, fa\_IR, ff\_NG, fi\_FI, fo\_FO, fr\_CA, fr\_FR, fy\_NL, ga\_IE, gl\_ES, gn\_PY, gu\_IN, ha\_NG, he\_IL, hi\_IN, hr\_HR, hu\_HU, hy\_AM, id\_ID, is\_IS, it\_IT, ja\_JP, ja\_KS, jv\_ID, ka\_GE, kk\_KZ, km\_KH, kn\_IN, ko\_KR, ku\_TR, lt\_LT, lv\_LV, mg\_MG, mk\_MK, ml\_IN, mn\_MN, mr\_IN, ms\_MY, mt\_MT, my\_MM, nb\_NO, ne\_NP, nl\_BE, nl\_NL, nn\_NO, or\_IN, pa\_IN, pl\_PL, ps\_AF, pt\_BR, pt\_PT, qz\_MM, ro\_RO, ru\_RU, rw\_RW, sc\_IT, si\_LK, sk\_SK, sl\_SI, so\_SO, sq\_AL, sr\_RS, sv\_SE, sw\_KE, sz\_PL, ta\_IN, te\_IN, tg\_TJ, th\_TH, tl\_PH, tr\_TR, tz\_MA, uk\_UA, ur\_PK, uz\_UZ, vi\_VN, zh\_CN, zh\_HK, zh\_TW

### How to add a persistent menu for a specific user

To do this, set the third parameter of the fb\_set\_persistent\_menu function to 1, like so: response = fb\_set\_persistent\_menu('group\_id', buttons, 1)

This menu will be available to the user for whom the function was called.

{% hint style="info" %} <mark style="color:red;">**NOTE**</mark> . **Updating** a user-level **persistent menu** takes effect in real time.\
However, updating a page-level persistent menu may take up to 24 hours.

User-level settings <mark style="color:red;">are limited</mark> to a rate of 10 calls per user every 10 minutes.
{% endhint %}

### How to disable all communications except the persistent menu

To make the persistent menu the only way a user can interact with your Messenger bot, you need to disable the composer.

#### Why would you do this?

It’s useful when your bot is designed for a specific purpose or a predefined set of options.

#### How to do this?

To disable the composer, pass 1 as the fourth parameter in the function:

to disable the composer at the page level (for all users):\
**response = fb\_set\_persistent\_menu('group\_id', buttons, '', 1)**\
to disable the composer for the user for whom the function is called:\
**response = fb\_set\_persistent\_menu('group\_id', buttons, 1, 1)**\
where:\
**group\_id** - Facebook bot ID, (can be found in the **"Channel"** MaviBot menu)\
**buttons** - a dictionary containing buttons

If successful, the function returns:\
{"result":"success"}

Otherwise, it returns an error description.\
'Error parse buttons data' - error in the button dictionary\
{"error":{"message":"(#100) param persistent\_menu\[0]\[call\_to\_actions] must be non-empty.","type":"OAuthException","code":100,"fbtrace\_id":"AJtVczu7TEJJxbMfnO"}}

#### EXAMPLES:

**Adding a menu for all users:**

```
buttons = {"default": [["postback", "Button 1", "callback_text 1"], ["postback", "Button 2", "callback_text 2"], ["web_url", "Site link", "https://mavibot.ai/"]], "en_EN": [["postback", "Button", "callback_text 1"], ["postback", "Button 2", "callback_text 2"], ["web_url", "Link", "https://mavibot.ai/"]]}
response = fb_set_persistent_menu('123456789', buttons)
```

**Adding a menu for all users and making this menu the only communication method for everyone:**

```
buttons = {"default": [["postback", "Button 1", "callback_text 1"], ["postback", "Button 2", "callback_text 2"], ["web_url", "Site link", "https://mavibot.ai/"]], "en_EN": [["postback", "Button", "callback_text 1"], ["postback", "Button 2", "callback_text 2"], ["web_url", "Link", "https://mavibot.ai/"]]}
response = fb_set_persistent_menu('123456789', buttons, '', 1)
```

**Adding a menu for the user who entered the block that calls the function:**

```
buttons = {"default": [["postback", "Button 1", "callback_text 1"], ["postback", "Button 2", "callback_text 2"], ["web_url", "Site link", "https://mavibot.ai/"]]}
response = fb_set_persistent_menu('123456789', buttons, 1)
```

**Adding a menu for the user who entered the block that calls the function, and making this menu the only communication method for all users:**

```
buttons = {"default": [["postback", "Button 1", "callback_text 1"], ["postback", "Button 2", "callback_text 2"], ["web_url", "Site link", "https://mavibot.ai/"]]}
response = fb_set_persistent_menu('123456789', buttons, 1, 1)
```

### Delete the persistent menu at the page level (for all users):

**response = fb\_delete\_persistent\_menu('group\_id')**

If successful, the function returns:\
{"result":"success"}

Otherwise, it returns an error description.\
'Bot not found'

### Delete the persistent menu at the user level:

**response = fb\_delete\_persistent\_menu('group\_id', 1)**

If successful, the function returns:\
{"result":"success"}

Otherwise, it returns an error description.

**"Bot not found"**


---

# 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/facebook-messenger/api.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.
