Working with Keyboards
If you are developing integrations for Bitrix24 using AI tools (Codex, Claude Code, Cursor), connect to the MCP server so that the assistant can utilize the official REST documentation.
The keyboard consists of buttons beneath the message. They can be used to open links, perform actions, and trigger commands.
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
Deprecated Chatbots (imbot)
- imbot.message.add — send a message on behalf of the chatbot
- imbot.message.update — modify a sent message from the chatbot
- imbot.command.answer — send a response to a chatbot command
How to Add a Keyboard
To add a keyboard, pass the KEYBOARD parameter when creating or updating a message.
KEYBOARD can be passed as:
- a JSON string
- an object with the root key
BUTTONS - an array of buttons without wrapping
If the KEYBOARD does not contain the BUTTONS key, the server will automatically assume that a shortened format has been provided and will wrap the array in BUTTONS.
{
"KEYBOARD": {
"BUTTONS": [
{"TEXT": "Button", "LINK": "https://example.com"}
]
}
}
{
"KEYBOARD": [
{"TEXT": "Button", "LINK": "https://example.com"}
]
}
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:
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 an action","keyboard":{"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":{"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: {
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);
}
try {
$response = $b24Service
->core
->call(
'imbot.v2.Chat.Message.send',
[
'botId' => 456,
'dialogId' => 'chat2725',
'fields' => [
'message' => 'Select an action',
'keyboard' => [
'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: {
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' => [
'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 Remove a Keyboard
To update buttons, use the following methods:
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