服务端 API/消息/消息管理/编辑消息
# 编辑消息

编辑已发送的消息内容，当前支持编辑文本、富文本消息。如需更新消息卡片，请参考[更新应用发送的消息卡片](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/patch)。
**注意事项**：**注意事项**:
- 一条消息最多可编辑20次
- 仅可编辑操作者自己发送的消息
- 不可编辑已撤回，已删除，超出可编辑时间的消息
- 操作者必须在消息所属的群中且具备发言权限才可以编辑消息

## 请求

基本 | &nbsp;
---|---
HTTP URL | https://open.larksuite.com/open-apis/im/v1/messages/:message_id
HTTP Method | PUT
接口频率限制 | [1000 次/分钟、50 次/秒](https://open.larksuite.com/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
支持的应用类型 | Custom App、Store App
权限要求<br>**调用该 API 所需的权限。开启其中任意一项权限即可调用**<br>开启任一权限即可 | 获取与发送单聊、群组消息(im:message)<br>以应用的身份发消息(im:message:send_as_bot)<br>更新消息(im:message:update)

### 请求头

名称 | 类型 | 必填 | 描述
---|---|---|---
Authorization | string | 是 | `tenant_access_token`<br>**值格式**："Bearer `access_token`"<br>**示例值**："Bearer t-7f1bcd13fc57d46bac21793a18e560"<br>[了解更多：如何选择与获取 access token](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-choose-which-type-of-token-to-use)
Content-Type | string | 是 | **固定值**："application/json; charset=utf-8"

### 路径参数

名称 | 类型 | 描述
---|---|---
message_id | string | 待编辑的消息的ID，仅支持文本（text）或富文本（post）消息，详情参见[消息ID说明](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/intro#ac79c1c2)<br>**示例值**："om_dc13264520392913993dd051dba21dcf"

### 请求体

名称 | 类型 | 必填 | 描述
---|---|---|---
msg_type | string | 是 | 消息的类型，当前仅支持文本（text）和富文本（post）类型<br>**示例值**："text"
content | string | 是 | 消息内容，JSON结构序列化后的字符串。不同msg_type对应不同内容，具体格式说明参考：[发送消息Content](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/im-v1/message/create_json)<br>**注意：**<br>- JSON字符串需进行转义，如换行符转义后为`\\n`<br>- 文本消息请求体最大不能超过150KB<br>- 富文本消息请求体最大不能超过30KB<br>**示例值**："{\"text\":\"test content\"}"

### 请求体示例
```json
{
    "msg_type": "text",
    "content": "{\"text\":\"test content\"}"
}
```

## 响应

### 响应体

名称 | 类型 | 描述
---|---|---
code | int | 错误码，非 0 表示失败
msg | string | 错误描述
data | message | \-
message_id | string | 消息id open_message_id
root_id | string | 根消息id open_message_id
parent_id | string | 父消息的id open_message_id
thread_id | string | 消息所属的话题 ID（不返回说明该消息非话题消息），说明参见：[话题介绍](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/thread-introduction)
msg_type | string | 消息类型 text post card image等等
create_time | string | 消息生成的时间戳(毫秒)
update_time | string | 消息更新的时间戳
deleted | boolean | 消息是否被撤回
updated | boolean | 消息是否被更新
chat_id | string | 所属的群
sender | sender | 发送者，可以是用户或应用
id | string | 该字段标识发送者的id
id_type | string | 该字段标识发送者的id类型
sender_type | string | 该字段标识发送者的类型
tenant_key | string | tenant key
body | message_body | 消息内容，JSON结构
content | string | 消息内容，JSON字符串格式
mentions | mention\[\] | 被艾特的人或应用的id
key | string | mention key
id | string | 用户或机器人的 open_id
id_type | string | 被@的用户或机器人 id 类型，目前仅支持 `open_id` ([什么是 Open ID？](https://open.larksuite.com/document/home/user-identity-introduction/open-id))
name | string | 被at用户的姓名
tenant_key | string | tenant key
upper_message_id | string | 合并消息的上一层级消息id open_message_id

### 响应体示例
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "message_id": "om_dc13264520392913993dd051dba21dcf",
        "root_id": "om_40eb06e7b84dc71c03e009ad3c754195",
        "parent_id": "om_d4be107c616aed9c1da8ed8068570a9f",
        "thread_id": "omt_d4be107c616a",
        "msg_type": "card",
        "create_time": "1609296809",
        "update_time": "1609336806",
        "deleted": false,
        "updated": true,
        "chat_id": "oc_5ad11d72b830411d72b836c20",
        "sender": {
            "id": "cli_9f427eec54ae901b",
            "id_type": "app_id",
            "sender_type": "app",
            "tenant_key": "736588c9260f175e"
        },
        "body": {
            "content": "{\"text\":\"@_user_1 test content\"}"
        },
        "mentions": [
            {
                "key": "@_user_1",
                "id": "ou_155184d1e73cbfb8973e5a9e698e74f2",
                "id_type": "open_id",
                "name": "Tom",
                "tenant_key": "736588c9260f175e"
            }
        ],
        "upper_message_id": "om_40eb06e7b84dc71c03e00ida3c754892"
    }
}
```

### 错误码

HTTP状态码 | 错误码 | 描述 | 排查建议
---|---|---|---
400 | 230001 | Your request contains an invalid request parameter. | 参数错误，请根据接口返回的错误信息并参考文档检查输入参数。
400 | 230002 | The bot can not be outside the group. | 机器人不在对应群组中。
400 | 230006 | Bot ability is not activated. | [机器人能力](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)未启用 。可在[开发者后台](https://open.larksuite.com/app) -> 应用能力 -> 添加应用能力页面添加机器人功能，发布新版本后生效。
400 | 230011 | The message is recalled. | 消息已被撤回。
400 | 230013 | Bot has NO availability to this user. | 机器人对用户没有[可用性](https://open.larksuite.com/document/home/introduction-to-scope-and-authorization/availability)。可在[开发者后台](https://open.larksuite.com/app) -> 应用发布 -> 版本管理与发布 -> 创建版本页面编辑应用的可用范围，发布新版本后生效。
400 | 230018 | These operations are NOT allowed at current group settings. | 当前操作被群设置禁止，请检查群设置或联系群管理员。
400 | 230020 | This operation triggers the frequency limit. | 当前操作触发限频，请降低请求频率。
400 | 230022 | The content of the message contains sensitive information. | 消息包含敏感信息，请检查消息内容。
400 | 230025 | The length of the message content reaches its limit. | 消息体长度超出限制。文本消息最大不能超过150KB，卡片及富文本消息最大不能超过30KB；此外，若消息中包含大量样式标签，会使实际消息体长度大于您输入的请求体长度。
400 | 230027 | Lack of necessary permissions. | 暂不支持在外部群中编辑消息、以用户身份编辑消息。
400 | 230028 | The messages do NOT pass the audit. | 消息DLP审查未通过，当消息内容中含有明文电话号码、明文个人邮箱等内容时可能会触发该错误；请根据接口返回的错误信息检查消息内容。
400 | 230035 | Send message permission deny. | 没有发送消息的权限，请排查群是否已开启禁言，或受到租户维度沟通权限的管控。
400 | 230038 | Cross tenant p2p chat operate forbid. | 跨租户的单聊不允许通过本接口发送消息。
400 | 230050 | The message is invisible to the operator. | 该消息对于操作者不可见，无法进行本操作。
400 | 230054 | This operation is not supported for this message type. | 该消息类型不支持本操作，仅支持文本、富文本消息。
400 | 230055 | The type of file upload does not match the type of message being sent. | 文件上传时选择的类型与发送的消息类型不匹配。
400 | 230071 | The operator is not the sender of the message. | 操作者不是该消息的发送者。
400 | 230072 | The message has reached the number of times it can be edited. | 消息已超过最大可编辑次数20次。
400 | 230073 | The message in the secret group is not allowed to be edited. | 密聊群中的消息暂不支持编辑。
400 | 230074 | The message in the third-party encryption group is not allowed to be edited. | 密盾聊中的消息暂不支持编辑。
400 | 230075 | The message has exceeded the time that can be edited. | 该消息已超出可编辑的时间，不能编辑；消息可编辑的时间范围请咨询本租户管理员。
400 | 230110 | Action unavailable as the message has been deleted. | 消息已被删除，无法进行编辑。
400 | 232009 | Your request specifies a chat which has already been dissolved. | 消息所在的群组已被解散，无法编辑该消息。

