Views: 4709
Last Modified: 30.08.2022
Sends message from 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: These methods of message processing are usually employed when the user is typing something, that is why the
ONIMBOTMESSAGEADD event must be processed.
Method call
$result = restCommand('imbot.message.add', Array(
'BOT_ID' => 39, // ID of chatbot that sends request. Is optional, there is only one chatbot
'DIALOG_ID' => 1, // Dialog ID: it can be either USER_ID, or chatXX - where XX is chat ID, transmitted in events ONIMBOTMESSAGEADD and ONIMJOINCHAT
'MESSAGE' => 'answer text' // Message text
'ATTACH' => '' // Attachment, optional field
'KEYBOARD' => '' // Keyboard, optional field
'MENU' => '' // Context menu, optional field
'SYSTEM' => 'N' // Display messages as system messages, optional field, by default 'N'
'URL_PREVIEW' => 'Y' // Convert links to rich-links, optional field, by default 'Y'
), $_REQUEST["auth"]);
You can post message on behalf of bot in private dialogues (they will be shown as system message). To do it, specify FROM_USER_ID
and TO_USER_ID
instead of DIALOG_ID
.
Return
Message identifier: MESSAGE_ID
or an error.
Related links:
Possible errors:
Code |
Description |
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. |
DIALOG_ID_EMPTY |
Dialogue ID is not transmitted. |
MESSAGE_EMPTY |
Message text is not transmitted. |
ATTACH_ERROR |
Complete transmitted object was not validated. |
ATTACH_OVERSIZE |
Maximum permissible attachment size was exceeded (30 Kb). |
KEYBOARD_ERROR |
Complete transmitted keyboard object was not validated. |
KEYBOARD_OVERSIZE |
Maximum permissible keyboard size was exceeded (30 Kb). |
MENU_ERROR |
Complete transmitted menu object was not validated. |
MENU_OVERSIZE |
Maximum permissible menu size was exceeded (30 Kb). |
WRONG_REQUEST |
Something went wrong. |
|