Views: 1744
Last Modified: 13.05.2022

Chatbot creates a chat

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.

Method call

$result = restCommand('imbot.chat.add', Array(

  'TYPE' => 'CHAT' // OPEN - opened to join chat, CHAT - usual chat with invitations, CHAT by default 
   'TITLE' => 'My new private chat', // Chat title
   'DESCRIPTION' => 'Very important chat', // Chat description
   'COLOR' => 'PINK', // Chat color for mobile application - RED, GREEN, MINT, LIGHT_BLUE, DARK_BLUE, PURPLE, AQUA, PINK, LIME, BROWN, AZURE, KHAKI, SAND, MARENGO, GRAY, GRAPHITE
   'MESSAGE' => 'Welcome to the chat', // First greeting message in the chat
   'USERS' => Array(1,2), // Chat participants (req.)
   'AVATAR' => '/* base64 image */', // Chat icon in base64 format
   'ENTITY_TYPE' => 'CHAT', // Arbitrary entity ID (for example CHAT, CRM, OPENLINES, CALL and etc.), can be used for chat search and easy context definition in the following event handlers: ONIMBOTMESSAGEADD, ONIMBOTMESSAGEUPDATE, ONIMBOTMESSAGEDELETE
   'ENTITY_ID' => 13, // Entity numerical ID; it can be used for chat search and for easy context definition in the following event handlers: ONIMBOTMESSAGEADD, ONIMBOTMESSAGEUPDATE, ONIMBOTMESSAGEDELETE
   'OWNER_ID' => 39, // Chat owner ID. May not be specified, if your are creating chat under the necessary user.
   'BOT_ID' => 39, // Chatbot ID from which the request is sent. May not be specified, if there is only one chatbot

), $_REQUEST["auth"]);
Required fields: USERS (chat participants).

Return:

CHAT_ID or error.

Possible error codes

Code Description
USERS_EMPTY No chat participants.
WRONG_REQUEST Something went wrong.



Courses developed by Bitrix24