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 asdata.messageIdby 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-dataonly):
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,messageIdandtextas plain form fields. - Send each file as a
filefield. - Send
markupsandgenerationas JSON strings, onemarkupsfield per markup. buttonsandoptionsare 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"
}
code | text | Reason |
|---|---|---|
| 400 | not allowed | Your YoAI is not allowed to post in this chat. |
| 403 | message can not be edited | The message was not sent by your YoAI. |
| 404 | message not found | There is no message with this messageId in the chat given in to. |
| 400 | generation must be valid JSON | The generation form field is not valid JSON. |
| 422 | Error validating edit message data | A parameter is missing or invalid. The errors field lists the parameters. |