import json
import requests
def send():
url = "https://open.feishu.cn/open-apis/im/v1/messages"
params = {"receive_id_type":"chat_id"}
msg = "text content"
msgContent = {
"text": msg,
}
req = {
"receive_id": "oc_xxx", # chat id
"msg_type": "text",
"content": json.dumps(msgContent)
}
payload = json.dumps(req)
headers = {
'Authorization': 'Bearer xxx', # your access token
'Content-Type': 'application/json'
}
response = requests.request("POST", url, params=params, headers=headers, data=payload)
print(response.headers['X-Tt-Logid']) # for debug or oncall
print(response.content) # Print Response
if __name__ == '__main__':
send()
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. | 机器人能力未启用 。在开发者后台-应用功能-机器人页面开启机器人功能并发布上线。 |
400 | 230013 | Bot has NO availability to this user. | 机器人对用户没有可用性。可在开发者后台-应用发布-版本管理与发布 编辑应用对用户的可用性并发布。 |
400 | 230015 | P2P chat can NOT be shared. | 私聊会话不允许被分享。 |
400 | 230017 | Bot is NOT the owner of the resource. | 机器人不是资源的拥有者。 |
400 | 230018 | These operations are NOT allowed at current group settings. | 当前操作被群设置禁止,请检查群设置或联系群管理员。 |
400 | 230019 | The topic does NOT exist. | 当前话题不存在。 |
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 | 230099 | Failed to create card content. | 创建卡片失败,失败原因请查看接口报错信息。 |
400 | 230028 | The messages do NOT pass the audit. | 消息DLP审查未通过,当消息内容中含有明文电话号码、明文个人邮箱等内容时可能会触发该错误;请根据接口返回的错误信息检查消息内容。 |
400 | 230029 | User has resigned. | 用户已离职。 |
400 | 230034 | The receive_id is invalid. | 请求参数中的receive_id不合法,请检查。 |
400 | 230035 | Send Message Permission deny. | 没有发言权限 ,请检查机器人是否在该群内,或群是否已开启禁言。 |
400 | 230036 | Tenant crypt key has been deleted. | 租户加密密钥已被删除,请联系企业管理员。 |
400 | 230038 | Cross tenant p2p chat operate forbid. | 跨租户的单聊不允许通过本接口发送消息。 |
400 | 230049 | The message is being sent. | 消息正在发送中,请稍后。 |
400 | 230053 | The user has stopped the bot from sending messages. | 用户已设置不再接收机器人消息,无法主动给用户发送单聊消息。 |
curl --location --request POST 'https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type' \
--header 'Authorization;' \
--header 'Content-Type: application/json' \
--data-raw '{
"receive_id": "ou_7d8a6e6df7621556ce0d21922b676706ccs",
"msg_type": "text",
"content": "{\"text\":\"test content\"}",
"uuid": "a0d69e20-1dd1-458b-k525-dfeca4015204"
}'
{
"code": 0,
"msg": "success",
"data": {
"message_id": "om_dc13264520392913993dd051dba21dcf",
"root_id": "om_40eb06e7b84dc71c03e009ad3c754195",
"parent_id": "om_d4be107c616aed9c1da8ed8068570a9f",
"msg_type": "card",
"create_time": "1615380573411",
"update_time": "1615380573411",
"deleted": false,
"updated": false,
"chat_id": "oc_5ad11d72b830411d72b836c20",
"sender": {
"id": "cli_9f427eec54ae901b",
"id_type": "app_id",
"sender_type": "app",
"tenant_key": "736588c9260f175e"
},
"body": {
"content": "text:测试消息"
},
"mentions": [
{
"key": "@_user_1",
"id": "ou_155184d1e73cbfb8973e5a9e698e74f2",
"id_type": "open_id",
"name": "Tom",
"tenant_key": "736588c9260f175e"
}
],
"upper_message_id": "om_40eb06e7b84dc71c03e009ad3c754195"
}
}