Working with methods to edit and delete messages#
Beta version
The functionality is in beta mode. Features are subject to change and may also work unstably. There may be additional charges for functionality in the future.
Recommendations for working with editable and deleted messages:
1. Instance setup#
To work with notifications about edited and deleted messages, enable the editedMessageWebhook
and deletedMessageWebhook
settings on the instance (on default the settings are disabled).
Choose a way to enable the settings:
-
Console, in the console turn on the necessary webhook types;
-
Via method SetSettings choose
"editedMessageWebhook":"yes"
,"deletedMessageWebhook":"yes"
; -
Via partners' method CreateInstance choose
"editedMessageWebhook":"yes"
,"deletedMessageWebhook":"yes"
for create new instance;
2. Working with editing messages method#
Method EditMessage#
Method EditMessage has to respond identifier idMessage
. This identifier is used to receive a notification about the editing result. You can also track which user edited the message (if your system has several operators).
Processing incoming notifications#
When editing a message via API or device, a notification of the type editedMessageWebhook
is generated for the recipient and sender. It is necessary to process this notification, namely, track the stanzaId
field, it will contain the original message that was corrected by you or your interlocutor, it is necessary to record these changes in your database and update the data on the client part of the integration. The textMessage
field contains the new text of the message.
We recommend that you process only the notifications you need, the handler service should find the required field
typeWebhook
, and depending on their type, process or reset the notification, you will process only the types of events you need, and incorrect instance settings or new API releases will not disrupt your integration.
Working through journals#
When working via journaling methods, you can determine whether a message has been edited by the isEdited: true
field. To update the chat conversation, you need to determine the messages that were received or sent in the last 15 minutes (the allowed time for editing messages) and update them every 10-15 seconds using the GetChatHistory method.
You can also update the original message using the GetMessage method by requesting a message from the journal. It will contain the latest data on the updated message and will have the isEdited: true
field.
Please note#
-
Notifications about edited messages come for all types of messages (incoming and outgoing sent from API and phone), depending on this, the notification type will be indicated as
incomingMessageReceived
,outgoingAPIMessageReceived
, andoutgoingMessageReceived
. -
In the journals, edited messages will have different types outgoing and incoming depending on who edited the message, you or your interlocutor. The journal will only contain an entry with the original message and the field
isEdited: true
, indicating that the message was edited. -
The message editing method works through the message queue and if a mailing was performed on the instance and a queue was formed, then editing will not occur instantly, but only at the moment when the message is taken for processing.
-
If the system does not process the message being edited within 15 minutes from the time the original message was written, the message will not be changed, and a notification with a message editing error (status failed) will be generated in response to the message editing request. The description of the notification will indicate the cause of the error in the description field.
-
If the message is incorrectly specified when calling the editing method, a notification with a message editing error (status failed) will be generated. The description of the notification will indicate the cause of the error in the description field.
3. Working with deleting messages method#
Method DeleteMessage#
When calling the DeleteMessage method, you will receive status code 200 and an empty body in response.
The system generates an identifier for the message deletion event, this identifier will be specified in the notification for the message deletion event.
Processing incoming notifications#
When a message is deleted by the recipient and sender via API or device, a notification of the deletedMessageWebhook
type is generated. This notification needs to be processed, namely, the stanzaId
field needs to be tracked, and the original message that was deleted by you or your interlocutor will be indicated in it, it is necessary to record these changes in your database and update the data on the client part of the integration.
We recommend processing only the notifications you need, your handler service must find the mandatory
typeWebhook
field and then process or reset the notification, so you will process only the types of events you need, and incorrect instance settings or new API releases will not disrupt the operation of your integration.
Working through journals#
When working via journals methods, you can determine whether a message has been deleted by the isDeleted: true
field.
To update the chat correspondence, you need to update it every 10-15 seconds using the GetChatHistory method.
You can also update the original message using the GetMessage method by requesting a message from the journal. It will contain the latest data on the deleted message and will have the isDeleted: true
field.
Please note#
-
Notifications about deleted messages come for all types of messages (incoming, outgoing sent from API and from phone), depending on this,
the notification type will be indicatedincomingMessageReceived
,outgoingAPIMessageReceived
,outgoingMessageReceived
. -
In the journals, deleted messages will have different types outgoing and incoming depending on who deleted the message: you or your interlocutor. The journal will contain an entry with the original message and the field
isDeleted: true
, indicating that the message was deleted. -
The journal will record all events of message deletion (who, in which chat and then deleted the message), and the
stanzaId
of the original deleted message will also be indicated. The original message is not deleted from the journal, it changes the field toisDeleted: true
.