Skip to main content

Edit Message

Use the editMessage method to change a message your YoAI sent earlier, in a private chat or in a channel. You can change the text, markups, buttons and options. You can also replace the message with files, for example a generated image in place of its loader.

The edit replaces the content of the original message for everyone in the chat. A YoAI can only edit messages it sent itself.

Request​

You need to send a POST request to:

https://yoai.yophone.com/api/pub/editMessage

Request body params format (JSON)​

  • to (required):
    The unique identifier of the chat or channel the original message was sent to.

  • messageId (required):
    The identifier of the message to edit. It is returned as data.messageId by sendMessage.

  • text (optional):
    The new text of the message. It can be empty or left out, for example when the edit replaces the message with an image that has no caption.

  • markups (optional):
    A list of markup objects for the new text.

  • buttons (optional):
    The new button configuration, in the same format as in Send Message With Buttons.

  • options (optional):
    A list of up to 20 {label:"label","value":"value"} objects, as in Send Message With Options.

  • file (optional, multipart/form-data only):
    Files that replace the message content: up to 10 files, each up to 50MB, with the MIME types listed in Send Media Files.

  • generation (optional):
    Marks the message as an image that is being generated or failed to generate. See Image Generation Placeholders.

The edit replaces the whole message content. Send every part you want to keep: if the original message had buttons and the edit has none, the edited message has no buttons.

Sending files​

To replace the message with files, send the request as multipart/form-data instead of JSON:

  • Send to, messageId and text as plain form fields.
  • Send each file as a file field.
  • Send markups and generation as JSON strings, one markups field per markup.
  • buttons and options are only supported in a JSON request, not together with files.

Request example (POST):​

Expecting Message format​

{
"to": "123456789",
"messageId": "6f1d2c3e-8f00-11ef-8000-000000000001",
"text": "Order #42 is shipped",
"buttons": {
"grid": 1,
"inline_buttons": [
{
"label": "Track order",
"url": "https://example.com/track/42"
}
]
}
}

Request example​

curl -X POST https://yoai.yophone.com/api/pub/editMessage \
-H "Content-Type: application/json" \
-H "X-YoAI-API-Key: your YoAI api token" \
-d '{
"to": "123456789",
"messageId": "6f1d2c3e-8f00-11ef-8000-000000000001",
"text": "Order #42 is shipped"
}'

Replacing the message with an image​

curl -X POST https://yoai.yophone.com/api/pub/editMessage \
-H "X-YoAI-API-Key: your YoAI api token" \
-F "to=123456789" \
-F "messageId=6f1d2c3e-8f00-11ef-8000-000000000001" \
-F "text=Here is your image" \
-F "file=@/path/to/result.png"

Response Example:​

The response is JSON data with status code 200

Message response format​

{
"success": true,
"code": 200,
"data": {
"messageId": "6f1d2c3e-8f00-11ef-8000-000000000001",
"editId": "6f1d2c3e-8f00-11ef-8000-000000000002"
}
}
  • messageId:
    The identifier of the edited message. Use the same value to edit the message again.

  • editId:
    The identifier of this edit.

Failure response format​

Errors are also returned with HTTP status 200. The code field holds the actual error code.

{
"success": false,
"code": 404,
"text": "message not found"
}
codetextReason
400not allowedYour YoAI is not allowed to post in this chat.
403message can not be editedThe message was not sent by your YoAI.
404message not foundThere is no message with this messageId in the chat given in to.
400generation must be valid JSONThe generation form field is not valid JSON.
422Error validating edit message dataA parameter is missing or invalid. The errors field lists the parameters.