gitee.com/larksuite/oapi-sdk-go/v3@v3.0.3/service/baike/v1/api.go (about) 1 // Package baike code generated by oapi sdk gen 2 /* 3 * MIT License 4 * 5 * Copyright (c) 2022 Lark Technologies Pte. Ltd. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 * 9 * The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 */ 13 14 package larkbaike 15 16 import ( 17 "context" 18 "net/http" 19 20 "gitee.com/larksuite/oapi-sdk-go/v3/core" 21 ) 22 23 func NewService(config *larkcore.Config) *BaikeService { 24 b := &BaikeService{config: config} 25 b.Classification = &classification{service: b} 26 b.Draft = &draft{service: b} 27 b.Entity = &entity{service: b} 28 return b 29 } 30 31 type BaikeService struct { 32 config *larkcore.Config 33 Classification *classification // 分类 34 Draft *draft // 草稿 35 Entity *entity // 词条 36 } 37 38 type classification struct { 39 service *BaikeService 40 } 41 type draft struct { 42 service *BaikeService 43 } 44 type entity struct { 45 service *BaikeService 46 } 47 48 // 获取百科分类 49 // 50 // - 获取企业百科当前分类。;企业百科目前为二级分类体系,每个词条可添加多个二级分类,但每个一级分类下只能添加一个分类。 51 // 52 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/baike-v1/classification/list 53 // 54 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/baikev1/list_classification.go 55 func (c *classification) List(ctx context.Context, req *ListClassificationReq, options ...larkcore.RequestOptionFunc) (*ListClassificationResp, error) { 56 // 发起请求 57 apiReq := req.apiReq 58 apiReq.ApiPath = "/open-apis/baike/v1/classifications" 59 apiReq.HttpMethod = http.MethodGet 60 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser} 61 apiResp, err := larkcore.Request(ctx, apiReq, c.service.config, options...) 62 if err != nil { 63 return nil, err 64 } 65 // 反序列响应结果 66 resp := &ListClassificationResp{ApiResp: apiResp} 67 err = apiResp.JSONUnmarshalBody(resp) 68 if err != nil { 69 return nil, err 70 } 71 return resp, err 72 } 73 func (c *classification) ListByIterator(ctx context.Context, req *ListClassificationReq, options ...larkcore.RequestOptionFunc) (*ListClassificationIterator, error) { 74 return &ListClassificationIterator{ 75 ctx: ctx, 76 req: req, 77 listFunc: c.List, 78 options: options, 79 limit: req.Limit}, nil 80 } 81 82 // 创建草稿 83 // 84 // - 草稿并非百科词条,而是指通过 API 发起创建新词条或更新现有词条的申请。百科管理员审核通过后,草稿将变为新的词条或覆盖已有词条。 85 // 86 // - 以用户身份创建草稿(即 Authorization 使用 user_access_token),对应用户将收到由企业百科 Bot 发送的审核结果;以应用身份创建草稿(即 Authorization 使用 tenant_access_toke),不会收到任何通知。 87 // 88 // - · 创建新的百科词条时,无需传入 entity_id 字段;· 更新已有百科词条时,请传入对应词条的 entity_id 或 outer_info 89 // 90 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/baike-v1/draft/create 91 // 92 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/baikev1/create_draft.go 93 func (d *draft) Create(ctx context.Context, req *CreateDraftReq, options ...larkcore.RequestOptionFunc) (*CreateDraftResp, error) { 94 // 发起请求 95 apiReq := req.apiReq 96 apiReq.ApiPath = "/open-apis/baike/v1/drafts" 97 apiReq.HttpMethod = http.MethodPost 98 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser, larkcore.AccessTokenTypeTenant} 99 apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...) 100 if err != nil { 101 return nil, err 102 } 103 // 反序列响应结果 104 resp := &CreateDraftResp{ApiResp: apiResp} 105 err = apiResp.JSONUnmarshalBody(resp) 106 if err != nil { 107 return nil, err 108 } 109 return resp, err 110 } 111 112 // 更新草稿 113 // 114 // - 根据 draft_id 更新草稿内容,已审批的草稿无法编辑 115 // 116 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/baike-v1/draft/update 117 // 118 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/baikev1/update_draft.go 119 func (d *draft) Update(ctx context.Context, req *UpdateDraftReq, options ...larkcore.RequestOptionFunc) (*UpdateDraftResp, error) { 120 // 发起请求 121 apiReq := req.apiReq 122 apiReq.ApiPath = "/open-apis/baike/v1/drafts/:draft_id" 123 apiReq.HttpMethod = http.MethodPut 124 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser, larkcore.AccessTokenTypeTenant} 125 apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...) 126 if err != nil { 127 return nil, err 128 } 129 // 反序列响应结果 130 resp := &UpdateDraftResp{ApiResp: apiResp} 131 err = apiResp.JSONUnmarshalBody(resp) 132 if err != nil { 133 return nil, err 134 } 135 return resp, err 136 } 137 138 // 创建免审词条 139 // 140 // - 通过此接口创建的词条,不需要百科管理员审核可直接写入词库,请慎重使用【租户管理员请慎重审批】 141 // 142 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/baike-v1/entity/create 143 // 144 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/baikev1/create_entity.go 145 func (e *entity) Create(ctx context.Context, req *CreateEntityReq, options ...larkcore.RequestOptionFunc) (*CreateEntityResp, error) { 146 // 发起请求 147 apiReq := req.apiReq 148 apiReq.ApiPath = "/open-apis/baike/v1/entities" 149 apiReq.HttpMethod = http.MethodPost 150 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser} 151 apiResp, err := larkcore.Request(ctx, apiReq, e.service.config, options...) 152 if err != nil { 153 return nil, err 154 } 155 // 反序列响应结果 156 resp := &CreateEntityResp{ApiResp: apiResp} 157 err = apiResp.JSONUnmarshalBody(resp) 158 if err != nil { 159 return nil, err 160 } 161 return resp, err 162 } 163 164 // 获取词条详情 165 // 166 // - 通过词条 id 拉取对应的实体词详情信息 167 // 168 // - 也支持通过 provider 和 outer_id 返回对应实体的详情数据。此时路径中的 entity_id 为固定的 enterprise_0 169 // 170 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/baike-v1/entity/get 171 // 172 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/baikev1/get_entity.go 173 func (e *entity) Get(ctx context.Context, req *GetEntityReq, options ...larkcore.RequestOptionFunc) (*GetEntityResp, error) { 174 // 发起请求 175 apiReq := req.apiReq 176 apiReq.ApiPath = "/open-apis/baike/v1/entities/:entity_id" 177 apiReq.HttpMethod = http.MethodGet 178 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser, larkcore.AccessTokenTypeTenant} 179 apiResp, err := larkcore.Request(ctx, apiReq, e.service.config, options...) 180 if err != nil { 181 return nil, err 182 } 183 // 反序列响应结果 184 resp := &GetEntityResp{ApiResp: apiResp} 185 err = apiResp.JSONUnmarshalBody(resp) 186 if err != nil { 187 return nil, err 188 } 189 return resp, err 190 } 191 192 // 词条高亮 193 // 194 // - 传入一句话,智能识别句中对应的词条,并返回词条位置和 entity_id,可在外部系统中快速实现百科词条智能高亮 195 // 196 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/baike-v1/entity/highlight 197 // 198 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/baikev1/highlight_entity.go 199 func (e *entity) Highlight(ctx context.Context, req *HighlightEntityReq, options ...larkcore.RequestOptionFunc) (*HighlightEntityResp, error) { 200 // 发起请求 201 apiReq := req.apiReq 202 apiReq.ApiPath = "/open-apis/baike/v1/entities/highlight" 203 apiReq.HttpMethod = http.MethodPost 204 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser, larkcore.AccessTokenTypeTenant} 205 apiResp, err := larkcore.Request(ctx, apiReq, e.service.config, options...) 206 if err != nil { 207 return nil, err 208 } 209 // 反序列响应结果 210 resp := &HighlightEntityResp{ApiResp: apiResp} 211 err = apiResp.JSONUnmarshalBody(resp) 212 if err != nil { 213 return nil, err 214 } 215 return resp, err 216 } 217 218 // 获取词条列表 219 // 220 // - 分页拉取词条列表数据,支持拉取租户内的全部词条 221 // 222 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/baike-v1/entity/list 223 // 224 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/baikev1/list_entity.go 225 func (e *entity) List(ctx context.Context, req *ListEntityReq, options ...larkcore.RequestOptionFunc) (*ListEntityResp, error) { 226 // 发起请求 227 apiReq := req.apiReq 228 apiReq.ApiPath = "/open-apis/baike/v1/entities" 229 apiReq.HttpMethod = http.MethodGet 230 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser} 231 apiResp, err := larkcore.Request(ctx, apiReq, e.service.config, options...) 232 if err != nil { 233 return nil, err 234 } 235 // 反序列响应结果 236 resp := &ListEntityResp{ApiResp: apiResp} 237 err = apiResp.JSONUnmarshalBody(resp) 238 if err != nil { 239 return nil, err 240 } 241 return resp, err 242 } 243 func (e *entity) ListByIterator(ctx context.Context, req *ListEntityReq, options ...larkcore.RequestOptionFunc) (*ListEntityIterator, error) { 244 return &ListEntityIterator{ 245 ctx: ctx, 246 req: req, 247 listFunc: e.List, 248 options: options, 249 limit: req.Limit}, nil 250 } 251 252 // 精准搜索词条 253 // 254 // - 将关键词与词条名、别名精准匹配,并返回对应的 词条 ID 255 // 256 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/baike-v1/entity/match 257 // 258 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/baikev1/match_entity.go 259 func (e *entity) Match(ctx context.Context, req *MatchEntityReq, options ...larkcore.RequestOptionFunc) (*MatchEntityResp, error) { 260 // 发起请求 261 apiReq := req.apiReq 262 apiReq.ApiPath = "/open-apis/baike/v1/entities/match" 263 apiReq.HttpMethod = http.MethodPost 264 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser, larkcore.AccessTokenTypeTenant} 265 apiResp, err := larkcore.Request(ctx, apiReq, e.service.config, options...) 266 if err != nil { 267 return nil, err 268 } 269 // 反序列响应结果 270 resp := &MatchEntityResp{ApiResp: apiResp} 271 err = apiResp.JSONUnmarshalBody(resp) 272 if err != nil { 273 return nil, err 274 } 275 return resp, err 276 } 277 278 // 模糊搜索词条 279 // 280 // - 传入关键词,与词条名、别名、释义等信息进行模糊匹配,返回搜到的词条信息 281 // 282 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/baike-v1/entity/search 283 // 284 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/baikev1/search_entity.go 285 func (e *entity) Search(ctx context.Context, req *SearchEntityReq, options ...larkcore.RequestOptionFunc) (*SearchEntityResp, error) { 286 // 发起请求 287 apiReq := req.apiReq 288 apiReq.ApiPath = "/open-apis/baike/v1/entities/search" 289 apiReq.HttpMethod = http.MethodPost 290 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser} 291 apiResp, err := larkcore.Request(ctx, apiReq, e.service.config, options...) 292 if err != nil { 293 return nil, err 294 } 295 // 反序列响应结果 296 resp := &SearchEntityResp{ApiResp: apiResp} 297 err = apiResp.JSONUnmarshalBody(resp) 298 if err != nil { 299 return nil, err 300 } 301 return resp, err 302 } 303 func (e *entity) SearchByIterator(ctx context.Context, req *SearchEntityReq, options ...larkcore.RequestOptionFunc) (*SearchEntityIterator, error) { 304 return &SearchEntityIterator{ 305 ctx: ctx, 306 req: req, 307 listFunc: e.Search, 308 options: options, 309 limit: req.Limit}, nil 310 } 311 312 // 更新免审词条 313 // 314 // - 通过此接口更新已有的词条,不需要百科管理员审核可直接写入词库,请慎重使用【租户管理员请慎重审批】 315 // 316 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/baike-v1/entity/update 317 // 318 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/baikev1/update_entity.go 319 func (e *entity) Update(ctx context.Context, req *UpdateEntityReq, options ...larkcore.RequestOptionFunc) (*UpdateEntityResp, error) { 320 // 发起请求 321 apiReq := req.apiReq 322 apiReq.ApiPath = "/open-apis/baike/v1/entities/:entity_id" 323 apiReq.HttpMethod = http.MethodPut 324 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser} 325 apiResp, err := larkcore.Request(ctx, apiReq, e.service.config, options...) 326 if err != nil { 327 return nil, err 328 } 329 // 反序列响应结果 330 resp := &UpdateEntityResp{ApiResp: apiResp} 331 err = apiResp.JSONUnmarshalBody(resp) 332 if err != nil { 333 return nil, err 334 } 335 return resp, err 336 }