Last Modified: 13.05.2022
Registers command for processing by chatbot
function is used here for illustration purposes only. It is taken from the EchoBot
example. You can send a REST command with your own function, or use the BX24.callMethod
Command processing requires for application to process a command-adding event ONIMCOMMANDADD
$result = restCommand('imbot.command.register', Array(
'BOT_ID' => 62, // Command owner chatbot ID
'COMMAND' => 'echo', // Text of command, which user will enter in chats
'COMMON' => 'Y', // If 'Y’ is specified, then the command is accessible in all chats, if ‘N’ – then it is accessible only in chats with chatbot
'HIDDEN' => 'N', // Hidden command or not – ‘N’ by default
'EXTRANET_SUPPORT' => 'N', // Extranet users access to command, ‘N’ by default
'CLIENT_ID' => '', // chatbot string ID, used only in Webhooks mode
'LANG' => Array( // Array of translations, preferably to specify, as a minimum for ENG
Array('LANGUAGE_ID' => 'en', 'TITLE' => 'Get echo message', 'PARAMS' => 'some text'), // Language, command description, which data to be required to be entered after the command.
'EVENT_COMMAND_ADD' => 'http://www.hazz/chatApi/bot.php', // Link to command handler
COMMAND_ID or error.
Possible error codes
||Link to event handler is invalid or not specified.
||Command text is not specified, to which chatbot should respond.
||Chatbot not found.
|| Chatbot is not part of this application: you can only work with chatbots, installed within application framework.
||Phrases are not transmitted for visible command.
||Something went wrong.
Attention! Bitrix24 REST restricts the work of event handlers, if more than one chatbot is to be installed within single application framework. Only one event handler per one application is permitted. That is why, upon registration of second command, the following links to event handlers EVENT_COMMAND_ADD all be the same as for the first command.
If processing of several commands is required within single application framework, then it shall be specified inside the event handler. So that during event execution, chatbot array is transmitted for proper processing of chatbots.