Views: 5385
Last Modified: 28.08.2018
Attention! The
restCommand function is used in all methods.
You can send a REST command with your own function, or use the
BX24.callMethod or
bitrix24-php-sdk JavaScript methods.
Send message to chat
REST method:
im.message.add
Method call:
$result = restCommand('im.message.add', Array(
'CHAT_ID' => 13, // Recipient chat ID, if message is for chat
'USER_ID' => 2, // Recipient user ID, if message is for private chat
'MESSAGE' => 'Message text' // Message test
'SYSTEM' => 'N' // To display message as system message or not, optional field, by default 'N'
'ATTACH' => '' // Attachment, optional field
'URL_PREVIEW' => 'Y' // Convert links to rich-links, optional field, by default 'Y'
'KEYBOARD' => '' // Keyboard, optional field
'MENU' => '' // Context menu, optional field
), $_REQUEST["auth"]);
Return:
MESSAGE_ID
ID or an error.
Related Links:
Using Keyboards
Attachments
Formatting
Possible errors:
Error code | Error description |
USER_ID_EMPTY |
Chat ID not specified, if message is sent in person-to-person chat. |
CHAT_ID_EMPTY |
Chat ID not specified if message is sent to chat. |
ACCESS_ERROR |
Insufficient rights to send message. |
MESSAGE_EMPTY |
No message text. |
ATTACH_ERROR |
Complete sent attachment object was not validated. |
ATTACH_OVERSIZE |
Maximum permissible attachment size was exceeded (30 Kb). |
KEYBOARD_ERROR |
Complete sent keyboard object was not validated. |
KEYBOARD_OVERSIZE |
Maximum permissible keyboard size was exceeded (30 Kb). |
MENU_ERROR |
Complete attachment object was not validated. |
MENU_OVERSIZE |
Maximum permissible menu size was exceeded (30 Kb). |
PARAMS_ERROR |
Something went wrong. |
|
Update chatbot message
REST method:
im.message.update
Method call:
$result = restCommand('im.message.update', Array(
'MESSAGE_ID' => 1, // Message ID
'MESSAGE' => 'answer text' // Message test, optional field, if empty value is specified - message will be deleted
'ATTACH' => '' // Attachment, optional field
'URL_PREVIEW' => 'Y' // Convert links to rich-links, optional field
'KEYBOARD' => '' // Keyboard, optional field
'MENU' => '' // Context menu, optional field
), $_REQUEST["auth"]);
Return:
true
or an error.
Related Links:
Using Keyboards
Attachments
Formatting
Possible errors:
Error code | Error description |
MESSAGE_ID_ERROR |
No message ID. |
CANT_EDIT_MESSAGE |
You do not have access to this message or time to modify it has expired (3 days passed since message posting). |
ATTACH_ERROR |
Complete sent attachment object not validated. |
ATTACH_OVERSIZE |
Maximum permissible attachment size was exceeded (30 Kb). |
KEYBOARD_ERROR |
Complete sent keyboard object not validated. |
KEYBOARD_OVERSIZE |
Maximum permissible keyboard size was exceeded (30 Kb). |
MENU_ERROR |
Complete sent menu object not validated. |
MENU_OVERSIZE |
Maximum permissible menu size was exceeded (30 Kb). |
|
Delete chatbot message
REST method:
im.message.delete
Method call:
$result = restCommand('im.message.delete', Array(
'MESSAGE_ID' => 1, // Message ID
), $_REQUEST["auth"]);
Return:
true
or an error.
Possible errors:
Error code | Error description |
MESSAGE_ID_ERROR |
No message ID. |
CANT_EDIT_MESSAGE |
You don't have access to this message or time to modify it has expired (3 days passed since message posting). |
|
Message “Like”
REST method:
im.message.like
Method call:
$result = restCommand('im.message.like', Array(
'MESSAGE_ID' => 1, // Message ID (any message, sent in private or group chats that have chatbot)
'ACTION' => 'auto' // Action, connected with method: plus - select «Like»; minus – remove «Like»; auto – automatic calculation, whether specified or not. If 'Like' is not specified, auto mode operation
), $_REQUEST["auth"]);
Return:
true
or an error.
Possible errors:
Error code | Error description |
MESSAGE_ID_ERROR |
No message ID. |
WITHOUT_CHANGES |
«Like» status. |
|