# 添加会话标签页

在指定会话内添加自定义会话标签页，仅支持添加文档类型（doc）或 URL （url）类型的标签页。

## 前提条件

- 应用需要开启[机器人能力](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)。
- 调用当前接口的用户或者机器人必须在对应的会话内。

## 使用限制

- 调用该接口仅支持添加 doc、url 类型的标签页，即 tab_type 参数传值时，只能传入 doc 或 url，传入其他枚举值将会报错。如果你需要添加其他类型的会话标签页，需要在飞书客户端内操作，详情参见[会话内标签页](https://www.feishu.cn/hc/zh-CN/articles/536850681075)。
- 如果群组配置了 **仅群主和群管理员可以管理标签页**，则仅群主或者群管理员可以添加会话标签页。
- 操作内部群时，操作者须与群组在同一租户下。

## 请求

基本 | &nbsp;
---|---
HTTP URL | https://open.feishu.cn/open-apis/im/v1/chats/:chat_id/chat_tabs
HTTP Method | POST
接口频率限制 | [1000 次/分钟、50 次/秒](https://open.feishu.cn/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
支持的应用类型 | Custom App、Store App
权限要求<br>**调用该 API 所需的权限。开启其中任意一项权限即可调用**<br>开启任一权限即可 | 获取与更新群组信息(im:chat)<br>操作群会话标签页(im:chat.tabs:write_only)

### 请求头

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

### 路径参数

名称 | 类型 | 描述
---|---|---
chat_id | string | 群 ID。获取方式：<br>- [创建群](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/create)，从返回结果中获取该群的 chat_id。<br>- 调用[获取用户或机器人所在的群列表](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/list)接口，可以查询用户或机器人所在群的 chat_id。<br>- 调用[搜索对用户或机器人可见的群列表](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/search)，可搜索用户或机器人所在的群、对用户或机器人公开的群的 chat_id。<br>**注意**：仅支持群模式为 **群组（group）**、**单聊（p2p）** 的群组 ID。你可以调用[获取群信息](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/get)接口，在返回结果中查看 `chat_mode` 参数取值是否为 `group`、`p2p`。<br>**示例值**："oc_a0553eda9014c201e6969b478895c230"

### 请求体

名称 | 类型 | 必填 | 描述
---|---|---|---
chat_tabs | chat.tab\[\] | 是 | 会话标签页<br>**注意**：一个会话内最多只允许添加 20 个自定义会话标签页
tab_name | string | 否 | 会话标签页名称<br>**注意**：会话标签页的名称不能超过 60 个字符<br>**示例值**："文档"
tab_type | string | 是 | 会话标签页类型<br>**注意**：只支持添加 doc、url 类型的标签页，其他字段为只读字段<br>**示例值**："doc"<br>**可选值有**：<br>- message：消息类型<br>- doc_list：云文档列表<br>- doc：文档<br>- pin：Pin<br>- meeting_minute：会议纪要<br>- chat_announcement：群公告<br>- url：URL<br>- file：文件<br>- files_resources：合并类型，包含文件、Doc 文档、URL 链接<br>- images_videos：合并类型，包含图片、视频<br>- task：任务
tab_content | chat_tab_content | 否 | 会话标签页的内容
url | string | 否 | URL 地址，在 tab_type 取值为 url 时生效<br>**注意**：<br>- tab_type 取值为 url 时url不能为空<br>- 必须以 http 或 https 开头<br>**示例值**："https://www.feishu.cn"
doc | string | 否 | 云文档链接，在 tab_type 取值为 doc 时生效<br>**注意**：<br>- tab_type 取值为 doc 时doc不能为空<br>- 必须以 http 或 https 开头<br>- 当前操作者必须有云文档的协作者权限<br>**示例值**："https://example.feishu.cn/wiki/wikcnPIcqWjJQwkwDzrB9t40123xz"
meeting_minute | string | 否 | 会议纪要，因不支持添加 meeting_minute 类型的会话标签页，该字段为只读字段，无需传值。<br>**示例值**："https://example.feishu.cn/docs/doccnvIXbV22i6hSD3utar4123dx"
task | string | 否 | 任务，因不支持添加 task 类型的会话标签页，该字段为只读字段，无需传值。<br>**示例值**："https://bytedance.feishu.cn/client/todo/task_list?guid=fa03fb6d-344b-47d9-83e3-049e3b3da931"
tab_config | chat_tab_config | 否 | 会话标签页的配置<br>**注意**：仅当  tab_type 取值为 url 时，该参数生效
icon_key | string | 否 | 会话标签页的图标。需要先调用[上传图片](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/image/create) 接口，图片类型设置为 message 上传图片，然后获取 `image_key` 后传入当前参数。<br>**示例值**："img_v2_b99741-7628-4abd-aad0-b881e4db83ig"
is_built_in | boolean | 否 | 会话标签页是否在 App 内嵌打开<br>**示例值**：false

### 请求体示例
```json
{
    "chat_tabs": [
        {
            "tab_name": "文档",
            "tab_type": "doc",
            "tab_content": {
                "url": "https://www.feishu.cn",
                "doc": "https://example.feishu.cn/wiki/wikcnPIcqWjJQwkwDzrB9t40123xz",
                "meeting_minute": "https://example.feishu.cn/docs/doccnvIXbV22i6hSD3utar4123dx",
                "task": "https://bytedance.feishu.cn/client/todo/task_list?guid=fa03fb6d-344b-47d9-83e3-049e3b3da931"
            },
            "tab_config": {
                "icon_key": "img_v2_b99741-7628-4abd-aad0-b881e4db83ig",
                "is_built_in": false
            }
        }
    ]
}
```

## 响应

### 响应体

名称 | 类型 | 描述
---|---|---
code | int | 错误码，非 0 表示失败
msg | string | 错误描述
data | \- | \-
chat_tabs | chat.tab\[\] | 会话标签页
tab_id | string | 会话标签页 ID，建议你保存该 ID，后续更新、删除、排序标签页时需要基于该 ID 进行操作。
tab_name | string | 会话标签页名称
tab_type | string | 会话标签页类型<br>**可选值有**：<br>- message：消息类型<br>- doc_list：云文档列表<br>- doc：文档<br>- pin：Pin<br>- meeting_minute：会议纪要<br>- chat_announcement：群公告<br>- url：URL<br>- file：文件<br>- files_resources：合并类型，包含文件、Doc文档、URL链接<br>- images_videos：合并类型，包含图片、视频<br>- task：任务
tab_content | chat_tab_content | 会话标签页内容
url | string | url 类型标签页对应的 URL 地址
doc | string | 文档类型标签页对应的云文档链接
meeting_minute | string | 会议纪要类型标签页对应的会议纪要地址
task | string | 任务
tab_config | chat_tab_config | 会话标签页配置
icon_key | string | 会话标签页图标。可调用[下载图片](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/image/get)（只能下载由当前机器人上传的图片），将图标下载至本地查看
is_built_in | boolean | 会话标签页是否在 App 内嵌打开

### 响应体示例
```json
{
    "code": 0,
    "msg": "ok",
    "data": {
        "chat_tabs": [
            {
               "tab_id": "7101214603622940633",
               "tab_type": "message"
            },
            {
                "tab_id": "7101214603622940671",
                "tab_name": "文档",
                "tab_type": "doc",
                "tab_content": {
                    "doc": "https://example.feishu.cn/wiki/wikcnPIcqWjJQwkwDzrB9t40123xz"
                }
            },
            {
                "tab_id": "7158333373373759422",
                "tab_name": "测试",
                "tab_type": "url",
                "tab_content": {
                    "url": "https://www.test.cn"
                },
                "tab_config": {
                    "icon_key": "img_v2_b99741-7628-4abd-aad0-b881e4db83ig",
                    "is_built_in": true
                }
            }
        ]
    }
}
```

### 错误码

HTTP状态码 | 错误码 | 描述 | 排查建议
---|---|---|---
400 | 232001 | Your request contains an invalid request parameter. | 参数错误，参考接口文档提供的参数描述，检查输入参数是否有误。
400 | 232006 | Your request specifies a chat_id which is invalid. | 无效的 chat_id，请检查 chat_id 是否正确。获取方式：<br>- [创建群](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/create)，从返回结果中获取该群的 chat_id。<br>- 调用[获取用户或机器人所在的群列表](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/list)接口，可以查询用户或机器人所在群的 chat_id。<br>- 调用[搜索对用户或机器人可见的群列表](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/search)，可搜索用户或机器人所在的群、对用户或机器人公开的群的 chat_id。
400 | 232009 | Your request specifies a chat which has already been dissolved. | 群组已被解散，无法操作。
400 | 232010 | Operator and chat can NOT be in different tenants. | 操作者和被操作的群组应该在同一租户下。
400 | 232011 | Operator can NOT be out of the chat. | 操作者不在群组中。你需要将当前调用 API 的应用或用户[加入待操作的群组](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat-members/create)后重试。
400 | 232024 | Users do not have the visibility of the app, or the operator does not have collaboration permissions with the target users. | 机器人对用户没有可见性，或操作者与用户间没有协作权限。<br>- 如果是机器人对用户没有可见性，需要在[开发者后台](https://open.feishu.cn/app) > **应用详情页** > **应用发布** > **版本管理与发布** 编辑应用对用户的可见性并发布应用。具体操作参考[配置应用可用范围](https://open.feishu.cn/document/home/introduction-to-scope-and-authorization/availability)。<br>- 如果是操作者与用户之间没有协作权限，请检查是否与目标用户有协作权限，如屏蔽、未添加为联系人等。
400 | 232025 | Bot ability is not activated. | 应用未启用机器人能力。你需要登录[开发者后台](https://open.feishu.cn/app)，在应用详情页的 **应用能力** > **添加应用能力** 页面内，添加 **机器人** 能力，并发布应用使配置生效。具体操作参见[机器人能力](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)。
400 | 232033 | The operator or invited bots does NOT have the authority to manage external chats without the scope. | 当前被操作的群为外部群，暂不支持操作外部群。只有开启对外共享能力的机器人支持外部群，详情参见[机器人支持外部群和外部用户单聊](https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/develop-robots/add-bot-to-external-group)。
400 | 232034 | The app is unavailable or inactivated by the tenant. | 应用在本租户下未安装或未启用。需要先安装应用，再使用应用调用接口。
400 | 232046 | The number of chat tabs has reached the limit. | 自定义的会话标签页个数超过上限 20 个，无法继续添加。你可以选择[更新会话标签页](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat-tab/update_tabs)或者[删除会话标签页](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat-tab/delete_tabs)。
400 | 232047 | The length of the tab name reaches the limit. | 会话标签页名称过长。不能超过 60 个字符。
400 | 232048 | The chat tab content is illegal. | 会话标签页内容非法。检查 tab_content 参数，传入正确值，例如 url 需要以 http、https 开头。
400 | 232050 | Operate chat tab unsupported chat type. | 请求的群类型不支持会话标签页。仅支持群模式为 **群组（group）**、**单聊（p2p）** 的群组 ID。你可以调用[获取群信息](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/get)接口，在返回结果中查看 `chat_mode` 参数取值是否为 `group`、`p2p`。
400 | 232051 | The operator does not have doc permission. | 操作者必须拥有云文档权限。你可以调用[增加协作者权限](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/permission-member/create)接口，为当前操作者添加云文档权限。
400 | 232055 | The operator does not have chat tab, chat menu, chat widget manage permission | 没有会话标签页、会话菜单和小组件的管理权限。如果在飞书客户端群设置中 **谁可以管理标签页、小组件和会话菜单** 选择了 **仅群主和管理员**，则只允许群主或者管理员进行操作。
400 | 232056 | The operator is not the image's owner, no permission to complete the request. | 机器人需要使用自己[上传的图片](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/image/create)。

更多错误码信息，参见[通用错误码](https://open.feishu.cn/document/ukTMukTMukTM/ugjM14COyUjL4ITN)。

