Event Triggered by the Chat Bot Command ONIMCOMMANDADD

Scope: imbot

Who can subscribe: user of the application that registered the chat bot

The ONIMCOMMANDADD event is triggered when a user invokes a bot command in a chat.

Events will not be sent to the application until the installation is complete. Check the application installation

What the Handler Receives

Data is transmitted as a POST request

{
            "event": "ONIMCOMMANDADD",
            "event_handler_id": "1045",
            "data": {
                "COMMAND": {
                    "103": {
                        "access_token": "be4ca0690000071b006e2cf200050b0077317605eb83b25d2bd6",
                        "expires": "1772113086",
                        "expires_in": "3600",
                        "scope": "imbot",
                        "domain": "some-domain.bitrix24.com",
                        "server_endpoint": "https://oauth.bitrix.info/rest/",
                        "status": "F",
                        "client_endpoint": "https://some-domain.bitrix24.com/rest/",
                        "member_id": "d897063e1ce7c5eb9f04b9751eef5915",
                        "refresh_token": "aecbc7690000071b006e2cf200050b007f827f47e120e49da",
                        "user_id": "1291",
                        "client_id": "a7eff906dd1d950269258a599214f69e",
                        "application_token": "8e3ab48a764a9b02700e759d59e91125",
                        "AUTH": {
                            "access_token": "be4ca0690000071b006e2cf200050b0077317605eb83b25d2bd6",
                            "expires": "1772113086",
                            "expires_in": "3600",
                            "scope": "imbot",
                            "domain": "some-domain.bitrix24.com",
                            "server_endpoint": "https://oauth.bitrix.info/rest/",
                            "status": "F",
                            "client_endpoint": "https://some-domain.bitrix24.com/rest/",
                            "member_id": "d897063e1ce7c5eb9f04b9751eef5915",
                            "refresh_token": "aecbc7690000071b006e2cf200050b007f827f47e120e49da",
                            "user_id": "1291",
                            "client_id": "a7eff906dd1d950269258a599214f69e",
                            "application_token": "8e3ab48a764a9b02700e759d59e91125"
                        },
                        "BOT_ID": "1291",
                        "BOT_CODE": "BOT_GM",
                        "COMMAND": "echo",
                        "COMMAND_ID": "103",
                        "COMMAND_PARAMS": "test",
                        "COMMAND_CONTEXT": "TEXTAREA",
                        "MESSAGE_ID": "33899"
                    }
                },
                "PARAMS": {
                    "MESSAGE": "/echo test",
                    "TEMPLATE_ID": "acae8d22-4536-4f47-a276-2e3bdf866475",
                    "MESSAGE_TYPE": "P",
                    "FROM_USER_ID": "1269",
                    "DIALOG_ID": "1269",
                    "TO_CHAT_ID": "2737",
                    "AUTHOR_ID": "1269",
                    "SYSTEM": "N",
                    "TO_USER_ID": "1291",
                    "SKIP_USER_CHECK": "Y",
                    "PUSH": "Y",
                    "PUSH_IMPORTANT": "N",
                    "RECENT_ADD": "Y",
                    "RECENT_SKIP_AUTHOR": "N",
                    "CONVERT": "N",
                    "SKIP_COMMAND": "N",
                    "SKIP_COUNTER_INCREMENTS": "N",
                    "SILENT_CONNECTOR": "N",
                    "SKIP_CONNECTOR": "N",
                    "IMPORTANT_CONNECTOR": "N",
                    "NO_SESSION_OL": "N",
                    "FAKE_RELATION": "0",
                    "SKIP_URL_INDEX": "N",
                    "MESSAGE_ID": "33899",
                    "CHAT_TYPE": "P",
                    "LANGUAGE": "en"
                },
                "USER": {
                    "ID": "1269",
                    "NAME": "John Smith",
                    "FIRST_NAME": "John",
                    "LAST_NAME": "Smith",
                    "GENDER": "M"
                }
            },
            "ts": "1772109486",
            "auth": {
                "access_token": "be4ca06900071b006e2cf200004f50005243fd374178cf59f7831",
                "expires": "1772113086",
                "expires_in": "3600",
                "scope": "imbot",
                "domain": "some-domain.bitrix24.com",
                "server_endpoint": "https://oauth.bitrix.info/rest/",
                "status": "F",
                "client_endpoint": "https://some-domain.bitrix24.com/rest/",
                "member_id": "d897063e1ce7c5eb9f04b9751eef5915",
                "user_id": "1269",
                "refresh_token": "aecbc76900071b006e2cf200004f50000f2e62ee8e8baa598968",
                "application_token": "8e3ab48a764a9b02700e759d59e91125"
            }
        }
        
{
            "event": "ONIMCOMMANDADD",
            "event_handler_id": "1035",
            "data": {
                "COMMAND": {
                    "99": {
                        "access_token": "f1ca0690000071b006e2cf20050b00074d9ed82e255b",
                        "expires": "1772100799",
                        "expires_in": "3600",
                        "scope": "imbot",
                        "domain": "some-domain.bitrix24.com",
                        "server_endpoint": "https://oauth.bitrix.info/rest/",
                        "status": "F",
                        "client_endpoint": "https://some-domain.bitrix24.com/rest/",
                        "member_id": "d897063e1ce7c5eb9f04b9751eef5915",
                        "refresh_token": "af9bc7690000071b006e2cf2050b00074d5d4c29337afbc6bb",
                        "user_id": "1291",
                        "client_id": "a7eff906dd1d950269258a599214f69e",
                        "application_token": "8e3ab48a764a9b02700e759d59e91125",
                        "AUTH": {
                            "access_token": "f1ca0690000071b006e2cf20050b00074d9ed82e255b",
                            "expires": "1772100799",
                            "expires_in": "3600",
                            "scope": "imbot",
                            "domain": "some-domain.bitrix24.com",
                            "server_endpoint": "https://oauth.bitrix.info/rest/",
                            "status": "F",
                            "client_endpoint": "https://some-domain.bitrix24.com/rest/",
                            "member_id": "d897063e1ce7c5eb9f04b9751eef5915",
                            "refresh_token": "af9bc7690000071b006e2cf2050b00074d5d4c29337afbc6bb",
                            "user_id": "1291",
                            "client_id": "a7eff906dd1d950269258a599214f69e",
                            "application_token": "8e3ab48a764a9b02700e759d59e91125"
                        },
                        "BOT_ID": "1291",
                        "BOT_CODE": "BOT_GM",
                        "COMMAND": "echo",
                        "COMMAND_ID": "99",
                        "COMMAND_PARAMS": "test",
                        "COMMAND_CONTEXT": "TEXTAREA",
                        "MESSAGE_ID": "33871"
                    }
                },
                "PARAMS": {
                    "MESSAGE": "/echo test",
                    "TEMPLATE_ID": "eb3d5b1c-0830-4728-a7a3-73e9745a90a1",
                    "MESSAGE_TYPE": "C",
                    "FROM_USER_ID": "1269",
                    "DIALOG_ID": "chat2725",
                    "TO_CHAT_ID": "2725",
                    "AUTHOR_ID": "1269",
                    "SYSTEM": "N",
                    "CHAT_ID": "2725",
                    "CHAT_PARENT_ID": "0",
                    "CHAT_PARENT_MID": "0",
                    "CHAT_TITLE": "New chat name",
                    "CHAT_AUTHOR_ID": "1291",
                    "CHAT_TYPE": "C",
                    "CHAT_AVATAR": "33079",
                    "CHAT_COLOR": "GREEN",
                    "CHAT_ENTITY_TYPE": "CHAT",
                    "CHAT_ENTITY_ID": "13",
                    "CHAT_ENTITY_DATA_1": "",
                    "CHAT_ENTITY_DATA_2": "",
                    "CHAT_ENTITY_DATA_3": "",
                    "CHAT_EXTRANET": "N",
                    "CHAT_PREV_MESSAGE_ID": "0",
                    "CHAT_CAN_POST": "MEMBER",
                    "RID": "1269",
                    "IS_MANAGER": "N",
                    "BOT_IN_CHAT": {
                        "1291": "1291"
                    },
                    "SKIP_USER_CHECK": "Y",
                    "PUSH": "Y",
                    "PUSH_IMPORTANT": "N",
                    "RECENT_ADD": "Y",
                    "RECENT_SKIP_AUTHOR": "N",
                    "CONVERT": "N",
                    "SKIP_COMMAND": "N",
                    "SKIP_COUNTER_INCREMENTS": "N",
                    "SILENT_CONNECTOR": "N",
                    "SKIP_CONNECTOR": "N",
                    "IMPORTANT_CONNECTOR": "N",
                    "NO_SESSION_OL": "N",
                    "FAKE_RELATION": "0",
                    "SKIP_URL_INDEX": "N",
                    "MESSAGE_ID": "33871",
                    "LANGUAGE": "en"
                },
                "USER": {
                    "ID": "1269",
                    "NAME": "John Smith",
                    "FIRST_NAME": "John",
                    "LAST_NAME": "Smith",
                    "GENDER": "M"
                }
            },
            "ts": "1772097199",
            "auth": {
                "access_token": "bf1ca06900071b006e2cf200004f500031d5d527f58a97b0768",
                "expires": "1772100799",
                "expires_in": "3600",
                "scope": "imbot",
                "domain": "some-domain.bitrix24.com",
                "server_endpoint": "https://oauth.bitrix.info/rest/",
                "status": "F",
                "client_endpoint": "https://some-domain.bitrix24.com/rest/",
                "member_id": "d897063e1ce7c5eb9f04b9751eef5915",
                "user_id": "1269",
                "refresh_token": "af9bc76900071b006e2cf200004f50080d2934573350daabf8",
                "application_token": "8e3ab48a764a9b02700e759d59e91125"
            }
        }
        

Parameter
type

Description

event
string

Symbolic code of the event.

In this case — ONIMCOMMANDADD

event_handler_id
integer

Identifier of the event handler

data
object

Object containing event data.

The structure is described below

ts
timestamp

Date and time the event was sent from the event queue

auth
object

Object containing the authorization parameters of the user on behalf of whom the event was triggered.

The structure is described below

Parameter data

Parameter
type

Description

COMMAND
object

Set of invoked commands of the chat bot.

The structure is described below

PARAMS
object

Parameters of the message in which the command was invoked.

The structure is described below

USER
object

Data of the message author. It may be an empty object if FROM_USER_ID = 0.

The structure is described below

Parameter COMMAND

Parameter
type

Description

{COMMAND_ID}
object

Data object of a specific invoked command. The key corresponds to the command identifier, for example 103.

The structure is described below

Element {COMMAND_ID}

Parameter
type

Description

access_token
string

OAuth authorization token of the bot

expires
timestamp

Moment of token expiration

expires_in
integer

Token lifetime in seconds

scope
string

Scope within which the event occurred

domain
string

Address of Bitrix24 where the event occurred

server_endpoint
string

Address of the OAuth server for REST requests

status
string

Application status indicator on the account

client_endpoint
string

Base path for calling the REST API on the current account

member_id
string

Unique identifier of Bitrix24

refresh_token
string

OAuth token for renewing the bot's authorization

user_id
integer

Identifier of the bot user

client_id
string

Identifier of the application issued upon registration

application_token
string

Application token

AUTH
object

Authorization parameters of the bot in auth format.

The structure is described below

BOT_ID
integer

Identifier of the bot

BOT_CODE
string

Symbolic code of the bot

COMMAND
string

Symbolic code of the invoked command

COMMAND_ID
integer

Identifier of the invoked command

COMMAND_PARAMS
string

Parameters with which the command was invoked

COMMAND_CONTEXT
string

Context of the command invocation.

Possible values:

  • TEXTAREA — command entered manually
  • KEYBOARD — command invoked by keyboard button

MESSAGE_ID
integer

Identifier of the message to which a response is required

Parameter PARAMS

Parameter
type

Description

MESSAGE
string

Text of the message with the command

TEMPLATE_ID
string

Identifier of the message template

MESSAGE_TYPE
string

Type of the message.

Possible values:

  • P — private, personal chat
  • C — group chat
  • O — open chat
  • L — open line
  • S — system/notify
  • N — channel
  • J — open channel
  • T — comment thread
  • A — copilot chat
  • B — collab
  • X — external chat

FROM_USER_ID
integer

Identifier of the message sender

DIALOG_ID
string

Identifier of the dialog

TO_CHAT_ID
integer

Identifier of the chat

AUTHOR_ID
integer

Identifier of the message author

SYSTEM
string

Indicator of a system message: Y or N

TO_USER_ID
integer

Identifier of the interlocutor in a personal chat. This parameter is available only for personal chats

SKIP_USER_CHECK
string

Skip user check: Y or N

PUSH
string

Indicator of sending a push notification: Y or N

PUSH_IMPORTANT
string

Indicator of an important push notification: Y or N

RECENT_ADD
string

Add message to the Recent chats list: Y or N

RECENT_SKIP_AUTHOR
string

Exclude author from updating the Recent chats list: Y or N

CONVERT
string

Indicator of message formatting conversion: Y or N

SKIP_COMMAND
string

Skip command processing in the message: Y or N

SKIP_COUNTER_INCREMENTS
string

Do not increment unread message counters: Y or N

SILENT_CONNECTOR
string

Send message to external connector without notification: Y or N

SKIP_CONNECTOR
string

Do not send message to external connectors: Y or N

IMPORTANT_CONNECTOR
string

Indicator of an important message for the connector: Y or N

NO_SESSION_OL
string

Do not create an Open Line session: Y or N

FAKE_RELATION
integer

System value of the user's relation to the chat

SKIP_URL_INDEX
string

Do not index links from the message: Y or N

MESSAGE_ID
integer

Identifier of the message

CHAT_TYPE
string

Type of the chat.

Possible values:

  • P — private, personal chat
  • C — group chat
  • O — open chat
  • L — open line
  • S — system/notify
  • N — channel
  • J — open channel
  • T — comment thread
  • A — copilot chat
  • B — collab
  • X — external chat

LANGUAGE
string

Default language of Bitrix24

CHAT_ID
integer

Identifier of the chat. This parameter is available only for group chats

CHAT_PARENT_ID
integer

Identifier of the parent chat. This parameter is available only for group chats

CHAT_PARENT_MID
integer

Identifier of the parent message. This parameter is available only for group chats

CHAT_TITLE
string

Title of the chat. This parameter is available only for group chats

CHAT_AUTHOR_ID
integer

Identifier of the chat owner. This parameter is available only for group chats

CHAT_AVATAR
string

Identifier of the chat avatar. 0 — avatar not set. This parameter depends on the chat type, it is absent in personal dialogs

CHAT_COLOR
string

Color scheme of the chat. This parameter depends on the chat type, it is absent in personal dialogs

CHAT_ENTITY_TYPE
string

Type of the object to which the chat is linked. This parameter depends on the chat type, it is absent in personal dialogs

CHAT_ENTITY_ID
string

Identifier of the object to which the chat is linked. This parameter depends on the chat type, it is absent in personal dialogs

CHAT_ENTITY_DATA_1
string

Additional data of the chat object — field 1. This parameter depends on the chat type, it is absent in personal dialogs

CHAT_ENTITY_DATA_2
string

Additional data of the chat object — field 2. This parameter depends on the chat type, it is absent in personal dialogs

CHAT_ENTITY_DATA_3
string

Additional data of the chat object — field 3. This parameter depends on the chat type, it is absent in personal dialogs

CHAT_EXTRANET
string

Indicator of an extranet chat: Y or N. This parameter depends on the chat type, it is absent in personal dialogs

CHAT_PREV_MESSAGE_ID
integer

Identifier of the previous message in the chat. This parameter depends on the chat type, it is absent in personal dialogs

CHAT_CAN_POST
string

Permission of the current user to send messages in the chat. This parameter depends on the chat type, it is absent in personal dialogs

RID
integer

Identifier of the record of the user's relation to the chat. This parameter depends on the chat type, it is absent in personal dialogs

IS_MANAGER
string

Indicator of the manager role: Y or N. This parameter is available only for group chats

BOT_IN_CHAT
object

List of bots present in the chat. This parameter is available only for group chats.

The structure is described below

Parameter BOT_IN_CHAT

Parameter
type

Description

{BOT_ID}
integer

Identifier of the bot present in the chat

Parameter USER

Parameter
type

Description

ID
integer

Identifier of the user

NAME
string

User's full name

FIRST_NAME
string

User's first name

LAST_NAME
string

User's last name

GENDER
string

User's gender: M or F

Parameter auth

Required parameters are marked with *

Name
type

Description

access_token
string

Authorization token OAuth 2.0

expires_in
integer

Time in seconds until the token expires

scope*
string

Scope under which the event occurred

domain*
string

Address of Bitrix24 where the event occurred

server_endpoint*
string

Address of the Bitrix24 authorization server needed to refresh OAuth 2.0 tokens

status*
string

Status of the application that subscribed to this event:

client_endpoint*
string

Common path for REST API method calls for Bitrix24 where the event occurred

member_id*
string

Identifier of Bitrix24 where the event occurred

refresh_token
string

Token for extending authorization OAuth 2.0

application_token*
string

Token for secure event handling

Authorization tokens are not always passed to the event handler. If the hit that initiated the event could not be linked to a specific Bitrix24 user, the tokens are not passed. Always check the contents of the auth key in the code.

It is recommended to store tokens obtained earlier during the application installation. Use them when working with the application interface in the form of embeds, widgets, and so on.

Continue Learning