Views: 5424
Last Modified: 23.03.2022

Sends message to 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 Required Description Revision
DIALOG_ID chat13
or
256
Yes Dialog ID. Format:
chatXXX – recipient chat, in case of message for chat
or XXX – recipient ID, in case of private conversation message
18
MESSAGE Message text Yes Message text 18
SYSTEM N No Show message as a system message. Optional fields, 'N' by default. 18
ATTACH No Attachment 18
URL_PREVIEW Y No Convert links to rich links. Optional field, 'Y' by default 18
KEYBOARD No Keyboard 18
MENU No Context menu 18

Called method and response

PHP

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

    'DIALOG_ID' => 'chat13',
    'MESSAGE' => 'Message text',
    'SYSTEM' => 'N',
    'ATTACH' => '',
    'URL_PREVIEW' => 'Y',
    'KEYBOARD' => '',
    'MENU' => '',

), $_REQUEST["auth"]);

Response example

{
	"result": 11
}
Executed result: MESSAGE_ID or an error.


Response example on error

{
    "error": "USER_ID_EMPTY",
    "error_description": "Recipient ID not specified for person-to-person chat message"
}

Key description:

  • error – error code
  • error_description – error brief description

Possible error codes

Code Description
USER_ID_EMPTY Recipient code not specified for person-to-person chat message
CHAT_ID_EMPTY Message recipient chat not specified for a chat message
ACCESS_ERROR Insufficient access permissions to send the message
MESSAGE_EMPTY Message text not passed
ATTACH_ERROR Весь переданный объект вложения не прошел валидацию
ATTACH_OVERSIZE Maximum allowed attachment size exceeded (30 Kb)
KEYBOARD_ERROR Complete passed keyboard object was not validated
KEYBOARD_OVERSIZE Maximum permissible keyboard size exceeded (30 Kb)
MENU_ERROR Complete passed menu object not validated
MENU_OVERSIZE Maximum permissible menu size exceeded (30 Kb)
PARAMS_ERROR Something went wrong



Courses developed by Bitrix24