Event on Message Deletion ONIMBOTMESSAGEDELETE

Scope: imbot

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

The event ONIMBOTMESSAGEDELETE is triggered when a message is deleted in a dialogue with the chat bot. This event only works in the context of the chat bot application.

For bots with TYPE=B/H and OPENLINE=N, the parameter EVENT_MESSAGE_DELETE is ignored in the method imbot.register. To enable the event for such bots, bind the handler EVENT_MESSAGE_DELETE using the method imbot.update.

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

Event Triggering Rule

The event is triggered if a handler for EVENT_MESSAGE_DELETE is bound and the message meets the logic of the bot type:

  • TYPE=B/H:
    • personal chat with the bot: the event triggers regardless of mentions,
    • group chat: triggers only when the bot is mentioned,
  • TYPE=S — the event triggers regardless of mentions,
  • TYPE=O — the event triggers in open line chats where the bot is involved.

Without EVENT_MESSAGE_DELETE, the event will not trigger regardless of mentions.

What the Handler Receives

Data is transmitted as a POST request

{
            "event": "ONIMBOTMESSAGEDELETE",
            "event_handler_id": "457",
            "data": {
                "BOT": {
                    "571": {
                        "access_token": "9a0aa06900071b0000084400023bf0f107e7cd778b0dbccd0155cea",
                        "expires": "1772096154",
                        "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": "9a0aa06900071b000844000023bf0f107e7cd778b0dbccd0155cea",
                        "user_id": "571",
                        "client_id": "a7eff906dd1d950269258a599214f69e",
                        "application_token": "831c76b092f9f135d9b6b36c3a720757",
                        "AUTH": {
                            "access_token": "9a0aa06900071b0000084400023bf0f107e7cd778b0dbccd0155cea",
                            "expires": "1772096154",
                            "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": "9a0aa06900071b000844000023bf0f107e7cd778b0dbccd0155cea",
                            "user_id": "571",
                            "client_id": "a7eff906dd1d950269258a599214f69e",
                            "application_token": "831c76b092f9f135d9b6b36c3a720757"
                        },
                        "BOT_ID": "571",
                        "BOT_CODE": "BOT"
                    }
                },
                "PARAMS": {
                    "ID": "84525",
                    "CHAT_ID": "1453",
                    "AUTHOR_ID": "27",
                    "MESSAGE": "Message from 26.02.2026 09:27:30 was deleted",
                    "MESSAGE_TYPE": "P",
                    "CHAT_AUTHOR_ID": "571",
                    "CHAT_ENTITY_ID": "",
                    "CHAT_ENTITY_DATA_1": "",
                    "CHAT_ENTITY_DATA_2": "",
                    "CHAT_ENTITY_DATA_3": "",
                    "FROM_USER_ID": "27",
                    "TO_USER_ID": "571",
                    "DIALOG_ID": "27",
                    "MESSAGE_ID": "84525",
                    "CHAT_TYPE": "P",
                    "LANGUAGE": "de"
                },
                "USER": {
                    "ID": "27",
                    "NAME": "Emily Smith",
                    "FIRST_NAME": "Emily",
                    "LAST_NAME": "Smith",
                    "WORK_POSITION": "",
                    "GENDER": "F",
                    "IS_BOT": "N",
                    "IS_CONNECTOR": "N",
                    "IS_NETWORK": "N",
                    "IS_EXTRANET": "N"
                }
            },
            "ts": "1772092554",
            "auth": {
                "access_token": "9a0aa06900071b00084400001b0000781c0546d93491d81d",
                "expires": "1772096154",
                "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",
                "refresh_token": "8a89c769000071b00084400001b000c1b724e4652017b0ea7051ffb8e",
                "application_token": "831c76b092f9f135d9b6b36c3a720757"
            }
        }
        
{
            "event": "ONIMBOTMESSAGEDELETE",
            "event_handler_id": "457",
            "data": {
                "BOT": {
                    "571": {
                        "access_token": "9a0aa0690000071b000008440001b000781c0546d82fee9e8c",
                        "expires": "1772100933",
                        "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": "9a0aa0690071b0000084400001b000781c0546d82fee9e8c",
                        "user_id": "571",
                        "client_id": "a7eff906dd1d950269258a599214f69e",
                        "application_token": "831c76b092f9f135d9b6b36c3a720757",
                        "AUTH": {
                            "access_token": "9a0aa0690000071b000008440001b000781c0546d82fee9e8c",
                            "expires": "1772100933",
                            "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": "9a0aa0690071b0000084400001b000781c0546d82fee9e8c",
                            "user_id": "571",
                            "client_id": "a7eff906dd1d950269258a599214f69e",
                            "application_token": "831c76b092f9f135d9b6b36c3a720757"
                        },
                        "BOT_ID": "571",
                        "BOT_CODE": "BOT"
                    }
                },
                "PARAMS": {
                    "ID": "84537",
                    "CHAT_ID": "1157",
                    "AUTHOR_ID": "27",
                    "MESSAGE": "Message from 26.02.2026 11:14:02 was deleted",
                    "MESSAGE_TYPE": "C",
                    "CHAT_AUTHOR_ID": "27",
                    "CHAT_ENTITY_TYPE": "THREAD",
                    "CHAT_ENTITY_ID": "",
                    "CHAT_ENTITY_DATA_1": "",
                    "CHAT_ENTITY_DATA_2": "",
                    "CHAT_ENTITY_DATA_3": "",
                    "DIALOG_ID": "chat1157",
                    "MESSAGE_ID": "84537",
                    "CHAT_TYPE": "C",
                    "LANGUAGE": "de"
                }
            },
            "ts": "1772097333",
            "auth": {
                "access_token": "451da069000071b00084400001b00075b8bc870e6dbc3",
                "expires": "1772100933",
                "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",
                "refresh_token": "359cc76900071b0000084400001b00071a54cd7aad70b5d2fa",
                "application_token": "831c76b092f9f135d9b6b36c3a720757"
            }
        }
        

Parameter
type

Description

event
string

Symbolic code of the event.

In this case — ONIMBOTMESSAGEDELETE

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 of the event sent from the event queue

auth
object

Object with 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 message is intended. The key of the object is the bot identifier BOT_ID.

The structure is described below

PARAMS
object

Parameters of the deleted message.

The structure is described below

USER
object

Data of the author of the deleted message. It may be an empty object if FROM_USER_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 of the bot

expires
timestamp

Moment of token expiration

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

Status indicator of the application on the account

client_endpoint
string

Common 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 during 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

ID
integer

Identifier of the message in the chat table

CHAT_ID
integer

Identifier of the chat.

For group chat and open line chat, the parameter is always passed. For personal dialogue, the parameter may be absent

AUTHOR_ID
integer

Identifier of the author of the deleted message

MESSAGE
string

Text of the system notification about the deleted message

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

CHAT_AUTHOR_ID
integer

Identifier of the chat owner

CHAT_ENTITY_TYPE
string

Type of the object to which the chat is linked

CHAT_ENTITY_ID
string

Identifier of the object to which the chat is linked

CHAT_ENTITY_DATA_1
string

Additional data of the chat object — field 1

CHAT_ENTITY_DATA_2
string

Additional data of the chat object — field 2

CHAT_ENTITY_DATA_3
string

Additional data of the chat object — field 3

DIALOG_ID
string

Identifier of the dialogue

MESSAGE_ID
integer

Identifier of the deleted message. Added in the event handler from the second argument of the event

CHAT_TYPE
string

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

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

Position of the user

GENDER
string

Gender of the user: M or F

IS_BOT
string

Indicator of bot user: Y or N

IS_CONNECTOR
string

Indicator of connector user: Y or N

IS_NETWORK
string

Indicator of external network user: Y or N

IS_EXTRANET
string

Indicator of extranet user: Y or N

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