Views: 1649
Last Modified: 13.05.2022

Registers command for processing by chatbot

Attention! restCommand 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 or bitrix24-php-sdk methods.

Note: Command processing requires for application to process a command-adding event ONIMCOMMANDADD.

Method call

$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

), $_REQUEST["auth"]);

Return:

COMMAND_ID or error.

Related links:

Possible error codes

Code Description
EVENT_COMMAND_ADD Link to event handler is invalid or not specified.
COMMAND_ERROR Command text is not specified, to which chatbot should respond.
BOT_ID_ERROR Chatbot not found.
APP_ID_ERROR Chatbot is not part of this application: you can only work with chatbots, installed within application framework.
LANG_ERROR Phrases are not transmitted for visible command.
WRONG_REQUEST 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.




Courses developed by Bitrix24