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.

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: - callback button: ["postback", "Button display text", "Callback text sent to the bot"] - 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/"]]}
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.
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:
Adding a menu for all users and making this menu the only communication method for everyone:
Adding a menu for the user who entered the block that calls the function:
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:
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"
Last updated