Views: 4835
Last Modified: 26.01.2024

Creates chat

Revision Get current information about current API revision (platform version) – im.revision.get : 18

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.

Parameters

Parameter Example Req. Description Revision
TYPE CHAT No Chat type OPEN | CHAT
(OPEN - open for joining, CHAT - standard chat by invitations, default value: CHAT)
18
TITLE New private chat No Chat title 18
DESCRIPTION Very important chat No Chat description 18
COLOR PINK No Chat color for mobile app: RED, GREEN, MINT, LIGHT_BLUE, DARK_BLUE, PURPLE, AQUA, PINK, LIME, BROWN, AZURE, KHAKI, SAND, MARENGO, GRAY, GRAPHITE 18
MESSAGE Welcome to chat No First salutation message in chat 18
USERS Array(1,2) Yes Chat participants 18
AVATAR base64 image No Chat avatar in base64 format 18
ENTITY_TYPE CHAT No Entity ID, can be implemented for searching by this field and for simple context definition in event handlers ONIMBOTMESSAGEADD, ONIMBOTMESSAGEUPDATE, ONIMBOTMESSAGEDELETE 18
ENTITY_ID 13 No Entity numerical ID, can be used for chat search and for simple context definition in event handlers ONIMBOTMESSAGEADD, ONIMBOTMESSAGEUPDATE, ONIMBOTMESSAGEDELETE 18
OWNER_ID 39 No Chat owner ID. May be skipped, query sender is assigned as owner. 18

Calling method and response

PHP

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

   'TYPE' => 'CHAT',
   'TITLE' => 'My new private chat',
   'DESCRIPTION' => 'Very important chat',
   'COLOR' => 'PINK',
   'MESSAGE' => 'Welcome to chat',
   'USERS' => Array(1,2), 
   'AVATAR' => 'base64 image',
   'ENTITY_TYPE' => 'CHAT',
   'ENTITY_ID' => 13,
   'OWNER_ID' => 39,

), $_REQUEST["auth"]);

Response example

{
	"result": 123
}

Response example on error

{
    "error": "USERS_EMPTY",
    "error_description": "Chat participants not passed"
}

Key description:

  • error – error code
  • error_description – error brief description

Possible error codes

Code Description
USERS_EMPTY Chat participants not passed
WRONG_REQUEST Something went wrong



Courses developed by Bitrix24