Working with Keyboards
Choose a tool for developing with an AI agent:
- use Alaio Vibecode to build an app for Bitrix24 from a task description without knowing any programming language. The agent writes the code and deploys the app to a server, with no manual hosting setup
- use the MCP server to develop a REST API integration in your own project. The agent refers to the official REST documentation
The keyboard consists of buttons beneath a message. They can open links, perform actions, and trigger commands. Use a keyboard when an action should remain a separate button beneath the message; for an action within the text, use BBCode.
Methods that support keyboard functionality:
Chatbots 2.0 (imbot.v2)
- imbot.v2.Chat.Message.send — send a message on behalf of the chatbot
- imbot.v2.Chat.Message.update — modify a sent message from the chatbot
- imbot.v2.Command.answer — send a response to a chatbot command
Chats (im)
- im.message.add — send a message in a chat
- im.message.update — modify a sent message
How to Add a Keyboard
To add a keyboard when creating or updating a message, pass it in fields.keyboard for imbot.v2 methods or as the top-level KEYBOARD parameter for im.* methods. imbot.v2 calls require the imbot scope and access as the registered bot's owner. When authorizing with a webhook, pass botToken as a method parameter. Access requirements for im.* methods are described on their pages.
A keyboard or KEYBOARD value can be passed as:
- a JSON string
- an object with the root key
BUTTONS - an array of buttons without wrapping
If the keyboard value does not contain the BUTTONS key, the server treats it as a shortened format and wraps the array in BUTTONS. Button field names inside BUTTONS are uppercase in both API versions.
{
"KEYBOARD": {
"BOT_ID": 456,
"BUTTONS": [
{"TEXT": "Button", "LINK": "https://example.com"}
]
}
}
{
"KEYBOARD": [
{"TEXT": "Button", "LINK": "https://example.com"}
]
}
In the examples above, KEYBOARD is shown as a parameter of im.* methods. For imbot.v2 methods, pass its contents in fields.keyboard, as shown in the message sending examples below.
How to Choose an Action
|
If You Need To |
Use |
What Happens |
|
Show a separate button that performs an action in the chat interface |
|
The client inserts or sends text, copies it, starts a call, or opens a dialog. An |
|
Receive a button click event and handle it in the bot |
|
The registered command triggers ONIMBOTV2COMMANDADD with |
|
Send a command directly from the message text without a separate button |
|
Clicking the link in the text sends the command immediately |
A button with ACTION: "SEND" sends the text from ACTION_VALUE. To make the bot react to a specific button, register a command and specify it in COMMAND.
Button Fields
|
Name |
Description |
|
TEXT |
Button text. For all buttons except |
|
TYPE |
Move the button to a new line. The only allowed value is |
|
LINK |
Button link. |
|
APP_ID |
Application identifier for the chat. Deprecated scenario. To open an application from the chat, use widgets |
|
APP_PARAMS |
Parameters for launching the application in the chat. Pass together with Deprecated scenario. To open an application from the chat, use widgets |
|
ACTION |
Action:
|
|
ACTION_VALUE |
Value for
|
|
COMMAND |
Command for the bot. More about processing — below |
|
COMMAND_PARAMS |
Command parameters. Pass together with |
|
BLOCK |
Button blocking:
Buttons with Default is |
|
DISABLED |
Button activity:
Default is |
|
CONTEXT |
Display context:
Default is |
|
DISPLAY |
Button display:
Default is |
|
WIDTH |
Button width in pixels |
|
BG_COLOR |
Button color in HEX format |
|
BG_COLOR_TOKEN |
Button color token:
Default is |
|
TEXT_COLOR |
Button text color in HEX format |
|
OFF_BG_COLOR |
Button color in inactive state |
|
OFF_TEXT_COLOR |
Button text color in inactive state |
The option with APP_ID and APP_PARAMS parameters is used in chats of Open Channels.
Example of Sending a Message with a Keyboard
How to Use Examples in Documentation
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"botId":456,"botToken":"my_bot_token","dialogId":"chat2725","fields":{"message":"Select action","keyboard":{"BOT_ID":456,"BUTTONS":[{"TEXT":"Open website","LINK":"https://www.example.com/"},{"TYPE":"NEWLINE"},{"TEXT":"Insert command","ACTION":"PUT","ACTION_VALUE":"/help"}]}}}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/imbot.v2.Chat.Message.send
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"botId":456,"dialogId":"chat2725","fields":{"message":"Select an action","keyboard":{"BOT_ID":456,"BUTTONS":[{"TEXT":"Open website","LINK":"https://www.example.com/"},{"TYPE":"NEWLINE"},{"TEXT":"Insert command","ACTION":"PUT","ACTION_VALUE":"/help"}]}},"auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/imbot.v2.Chat.Message.send
try {
const response = await $b24.callMethod('imbot.v2.Chat.Message.send', {
botId: 456,
dialogId: 'chat2725',
fields: {
message: 'Select an action',
keyboard: {
BOT_ID: 456,
BUTTONS: [
{ TEXT: 'Open website', LINK: 'https://www.example.com/' },
{ TYPE: 'NEWLINE' },
{ TEXT: 'Insert command', ACTION: 'PUT', ACTION_VALUE: '/help' },
],
},
},
});
const result = response.getData().result.id;
console.log('Created message ID:', result);
} catch (error) {
console.error('Error:', error);
}
from b24pysdk.errors import BitrixAPIError, BitrixSDKException
try:
bitrix_response = client.imbot.v2.chat.message.send(
bot_id=456,
dialog_id="chat2725",
fields={
"message": "Select an action",
"keyboard": {
"BOT_ID": 456,
"BUTTONS": [
{
"TEXT": "Open the website",
"LINK": "https://www.example.com/",
},
{
"TYPE": "NEWLINE",
},
{
"TEXT": "Insert the command",
"ACTION": "PUT",
"ACTION_VALUE": "/help",
},
],
},
},
).response
result = bitrix_response.result["id"]
print(result)
except BitrixAPIError as error:
print(
"Bitrix API error",
f"error: {error.error}",
f"error_description: {error.error_description}",
sep="\n",
)
except BitrixSDKException as error:
print(f"Bitrix SDK error: {error.message}")
except Exception as error:
print(f"Unexpected error: {error}")
try {
$response = $b24Service
->core
->call(
'imbot.v2.Chat.Message.send',
[
'botId' => 456,
'dialogId' => 'chat2725',
'fields' => [
'message' => 'Select an action',
'keyboard' => [
'BOT_ID' => 456,
'BUTTONS' => [
['TEXT' => 'Open website', 'LINK' => 'https://www.example.com/'],
['TYPE' => 'NEWLINE'],
['TEXT' => 'Insert command', 'ACTION' => 'PUT', 'ACTION_VALUE' => '/help'],
],
],
],
]
);
$result = $response
->getResponseData()
->getResult()['id'];
echo 'Created message ID: ' . $result;
} catch (Throwable $e) {
error_log($e->getMessage());
echo 'Error: ' . $e->getMessage();
}
BX24.callMethod(
'imbot.v2.Chat.Message.send',
{
botId: 456,
dialogId: 'chat2725',
fields: {
message: 'Select an action',
keyboard: {
BOT_ID: 456,
BUTTONS: [
{ TEXT: 'Open website', LINK: 'https://www.example.com/' },
{ TYPE: 'NEWLINE' },
{ TEXT: 'Insert command', ACTION: 'PUT', ACTION_VALUE: '/help' },
],
},
},
},
function(result) {
if (result.error()) {
console.error(result.error().ex);
} else {
console.log('Message ID:', result.data().id);
}
}
);
require_once('crest.php');
$result = CRest::call(
'imbot.v2.Chat.Message.send',
[
'botId' => 456,
'dialogId' => 'chat2725',
'fields' => [
'message' => 'Select an action',
'keyboard' => [
'BOT_ID' => 456,
'BUTTONS' => [
['TEXT' => 'Open website', 'LINK' => 'https://www.example.com/'],
['TYPE' => 'NEWLINE'],
['TEXT' => 'Insert command', 'ACTION' => 'PUT', 'ACTION_VALUE' => '/help'],
],
],
],
]
);
if (!empty($result['error'])) {
echo 'Error: ' . $result['error_description'];
} else {
echo 'Message ID: ' . $result['result']['id'];
}
How to update or delete a keyboard
To update buttons, use the following methods:
When updating a keyboard, specify BOT_ID inside the keyboard object, at the same level as BUTTONS. If you pass only BUTTONS, the button command may not be routed to the correct bot.
To disable button display, pass:
KEYBOARD: 'N'- an empty value for
KEYBOARD
Command Processing by the Chatbot
-
To ensure the command works with the keyboard, register it using the method imbot.v2.Command.register.
-
Pressing a button will generate the event ONIMBOTV2COMMANDADD.
-
In the event, the value of
command.contextindicates the context in which the command was invoked:
textarea— entered manuallykeyboard— invoked by a buttonmenu— invoked from the context menu
Continue Learning
- ONIMBOTV2COMMANDADD — event format when a command is called from a button
- imbot.v2.Command.register — registering a button command
- Text Formatting — BBCode for actions within a message
- Message Attachments — cards with text, links, images, and files