Views: 132
Last Modified: 13.05.2022

Updates chatbot data

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: For chatbots to work properly, access to marta.bitrix.info shall be authorized from Bitrix24 account or site.

CLIENT_ID parameter shall be specified for all methods to work with chatbots via Webhooks. Such code shall be unique for each chatbot.

Method call

$result = restCommand('imbot.update', Array(

    'BOT_ID' => 39, // Chatbot ID, shall be modified (required)
    'CLIENT_ID' => '', // Chatbot string ID, used only in Webhooks mode (required)
    'FIELDS' => Array( // Data for update (required)
        'CODE' => 'newbot', // String ID for bot, unique within your application framework 
        'EVENT_HANDLER' => 'http://www.hazz/chatApi/event.php', // Link to the handler of events, received from the server, see Event Handlers below (req.)  
        'PROPERTIES' => Array( // Required when bot data is updated
            'NAME' => 'UpdatedBot', // Chatbot name 
            'LAST_NAME' => '', // Chatbot last name 
            'COLOR' => 'MINT', // Chatbot color for mobile application: RED, GREEN, MINT, LIGHT_BLUE, DARK_BLUE, PURPLE, AQUA, PINK, LIME,  BROWN, AZURE, KHAKI, SAND, MARENGO, GRAY, GRAPHITE
            'EMAIL' => 'test2@test.com', // E-mail for communication
            'PERSONAL_BIRTHDAY' => '2016-03-12', // Birthday, yyyy-mm-dd
            'WORK_POSITION' => 'My second bot', // Job title, used as description for chatbot
            'PERSONAL_WWW' => 'http://test2.com', // Link to site
            'PERSONAL_GENDER' => 'M', // Chatbot gender, valid values M -  male, F - female, empty, if not required to be specified
            'PERSONAL_PHOTO' => '/* base64 image */', // Chatbot icon - base64
        )
    )

), $_REQUEST["auth"]);

Required fields:

  • BOT_ID - Chatbot ID, shall be modified.
  • FIELDS - Array with data to be updated.
  • PROPERTIES - Array with chatbot properties.
  • EVENT_HANDLER - link to the event handler for message sending to chatbot.
  • or
  • EVENT_MESSAGE_ADD - Link to event handler: send message to chatbot.
  • EVENT_WELCOME_MESSAGE - Link to event handler: open dialogue with chatbot or invite the chatbot to group chat.
  • EVENT_BOT_DELETE - Link to event handler: delete chat bot on the client side.

Return:

true or error.

Event handlers

If you require to process events via different event handlrs, then instead of EVENT_HANDLER you can specify each event handler individually:

:
 'EVENT_MESSAGE_ADD' => 'http://www.hazz/chatApi/event.php', // Link to event handler: send message to chatbot (required)
 'EVENT_WELCOME_MESSAGE' => 'http://www.hazz/chatApi/event.php', // Link to event handler: open dialogue with chatbot or invite the chatbot to group chat (required)
 'EVENT_BOT_DELETE' => 'http://www.hazz/chatApi/event.php', // Link to event handler: delete chat bot on the client side (required)
 'EVENT_MESSAGE_UPDATE' => 'http://www.hazz/chatApi/event.php', // Link to event handler: subscription to message update events 
 'EVENT_MESSAGE_DELETE' => 'http://www.hazz/chatApi/event.php', // Link to event handler: subscription to message deletion events 

Related links:

REST API - Installation and Update Events

Possible error codes:

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.
EVENT_MESSAGE_ADD_ERROR Event handler link invalid or not specified
EVENT_WELCOME_MESSAGE_ERROR Event handler link invalid or not specified.
EVENT_BOT_DELETE_ERROR Event handler link invalid or not specified.
NAME_ERROR One of chatbot required fields NAME or LAST_NAME is not specified.
WRONG_REQUEST Something went wrong.

Method imbot.update no longer supports updates for the fields TYPE and OPENLINE (im 17.5.10).





Courses developed by Bitrix24