Event When Adding a Bot to a Chat ONIMBOTJOINCHAT

Scope: imbot

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

The event ONIMBOTJOINCHAT is triggered when a bot is added to 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 in the form of a POST request

{
            "event": "ONIMBOTJOINCHAT",
            "event_handler_id": "459",
            "data": {
                "BOT": {
                    "571": {
                        "access_token": "e703a069000071b00084400023bf0f10751a702af1e",
                        "expires": "1772094439",
                        "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": "bac1cd5c8940947a75e0d71b1a84e348",
                        "refresh_token": "d782c76900071b00084400023bf0f1077047d2feeb6c5f3fb",
                        "user_id": "571",
                        "client_id": "a7eff906dd1d950269258a599214f69e",
                        "application_token": "831c76b092f9f135d9b6b36c3a720757",
                        "AUTH": {
                            "access_token": "e703a069000071b00084400023bf0f10751a702af1e",
                            "expires": "1772094439",
                            "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": "bac1cd5c8940947a75e0d71b1a84e348",
                            "refresh_token": "d782c76900071b00084400023bf0f1077047d2feeb6c5f3fb",
                            "user_id": "571",
                            "client_id": "a7eff906dd1d950269258a599214f69e",
                            "application_token": "831c76b092f9f135d9b6b36c3a720757"
                        },
                        "BOT_ID": "571",
                        "BOT_CODE": "BOT"
                    }
                },
                "PARAMS": {
                    "CHAT_TYPE": "P",
                    "MESSAGE_TYPE": "P",
                    "BOT_ID": "571",
                    "USER_ID": "27",
                    "TO_USER_ID": "27",
                    "FROM_USER_ID": "571",
                    "DIALOG_ID": "27",
                    "LANGUAGE": "de"
                },
                "USER": {
                    "ID": "27",
                    "NAME": "Emily Smith",
                    "FIRST_NAME": "Emily",
                    "LAST_NAME": "Smith",
                    "WORK_POSITION": "",
                    "GENDER": "F"
                }
            },
            "ts": "1772090839",
            "auth": {
                "access_token": "e703a069000071b00084400001b00074523806a5537056abff",
                "expires": "1772094439",
                "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": "bac1cd5c8940947a75e0d71b1a84e348",
                "user_id": "27",
                "application_token": "831c76b092f9f135d9b6b36c3a720757"
            }
        }
        
{
            "event": "ONIMBOTJOINCHAT",
            "event_handler_id": "459",
            "data": {
                "BOT": {
                    "571": {
                        "access_token": "4d12a06900071b00084400023bf0f1079c6f8b9190c698fd2",
                        "expires": "1772098125",
                        "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": "bac1cd5c8940947a75e0d71b1a84e348",
                        "refresh_token": "3d91c7690000071b00084400023bf0f107580dad11018e",
                        "user_id": "571",
                        "client_id": "a7eff906dd1d950269258a599214f69e",
                        "application_token": "831c76b092f9f135d9b6b36c3a720757",
                        "AUTH": {
                            "access_token": "4d12a06900071b00084400023bf0f1079c6f8b9190c698fd2",
                            "expires": "1772098125",
                            "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": "bac1cd5c8940947a75e0d71b1a84e348",
                            "refresh_token": "3d91c7690000071b00084400023bf0f107580dad11018e",
                            "user_id": "571",
                            "client_id": "a7eff906dd1d950269258a599214f69e",
                            "application_token": "831c76b092f9f135d9b6b36c3a720757"
                        },
                        "BOT_ID": "571",
                        "BOT_CODE": "BOT"
                    }
                },
                "PARAMS": {
                    "CHAT_TYPE": "C",
                    "MESSAGE_TYPE": "C",
                    "BOT_ID": "571",
                    "USER_ID": "27",
                    "CHAT_ID": "1157",
                    "CHAT_AUTHOR_ID": "27",
                    "CHAT_ENTITY_TYPE": "THREAD",
                    "CHAT_ENTITY_ID": "",
                    "ACCESS_HISTORY": "1",
                    "DIALOG_ID": "chat1157",
                    "LANGUAGE": "de"
                },
                "USER": {
                    "ID": "27",
                    "NAME": "Emily Smith",
                    "FIRST_NAME": "Emily",
                    "LAST_NAME": "Smith",
                    "WORK_POSITION": "",
                    "GENDER": "F"
                }
            },
            "ts": "1772094525",
            "auth": {
                "access_token": "4e12a06900071b00084400001b000070de69612254f5f11a912b908",
                "expires": "1772098126",
                "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": "bac1cd5c8940947a75e0d71b1a84e348",
                "user_id": "27",
                "application_token": "831c76b092f9f135d9b6b36c3a720757"
            }
        }
        

Parameter
type

Description

event
string

Symbolic code of the event.

In this case — ONIMBOTJOINCHAT

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

BOT
object

Set of authorization parameters for the bots to which the event is directed. The object key is the bot identifier BOT_ID.

The structure is described below

PARAMS
object

Event parameters.

The structure is described below

USER
object

Data of the user who added the bot to the chat. It may be an empty object if ID = 0.

The structure is described below

Parameter BOT

Parameter
type

Description

{BOT_ID}
object

Data object of a specific bot. The key corresponds to the bot identifier, for example 571.

The structure is described below

Element {BOT_ID}

Parameter
type

Description

access_token
string

OAuth authorization token for the bot

expires
timestamp

Moment when the token expires

expires_in
integer

Lifetime of the token 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

General path for calling REST API methods on the account where the event occurred

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

Parameter PARAMS

Parameter
type

Description

CHAT_TYPE
string

Type of chat to which the bot was added.

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

MESSAGE_TYPE
string

Type of 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

BOT_ID
integer

Identifier of the bot

USER_ID
integer

Identifier of the user who added the bot

TO_USER_ID
integer

Identifier of the user with whom the personal dialog was created. This parameter is only for personal chat

FROM_USER_ID
integer

Identifier of the bot in the personal dialog. This parameter is only for personal chat

CHAT_ID
integer

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

CHAT_AUTHOR_ID
integer

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

CHAT_ENTITY_TYPE
string

Type of the object to which the group chat is linked. This parameter is only for group chat

CHAT_ENTITY_ID
string

Identifier of the object to which the group chat is linked. This parameter is only for group chat

ACCESS_HISTORY
integer

Indicator of the bot's access to history: 1 — access granted, 0 — no access. This parameter is only for group chat

SILENT_JOIN
string

Indicator of adding the bot without a system message: Y or N. This parameter is only for Copilot group chat

DIALOG_ID
string

Identifier of the dialog

LANGUAGE
string

Default language of Bitrix24

Parameter USER

Parameter
type

Description

ID
integer

Identifier of the user

NAME
string

Full name of the user

FIRST_NAME
string

First name of the user

LAST_NAME
string

Last name of the user

WORK_POSITION
string

User's position

GENDER
string

Gender of the user: 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