mirror of
https://github.com/larksuite/cli.git
synced 2026-07-04 06:29:52 +08:00
* feat(task): add task shortcuts with skill docs and tests * docs(task): document task event payload shape * refactor(task): remove unused buildUserIDs helper * fix(task): handle api error codes in set-ancestor * docs(task): clarify get-related-tasks page-token unit * feat(task): support bot identity for subscribe-event * docs(task): clarify bot subscribe-event scope * docs(task): clarify related-task pagination semantics * docs(task): add BOE selftest report (boe_task_tasklist_oapi_support) * docs(task): prefer related-task shortcuts over search for scoped queries * docs(task): clarify tasklist search routing * docs(task): route keywordless tasklist queries to list API * docs(task): refine search routing heuristics * feat(event): include task user-access updates in catch-all subscribe * docs(task): remove auth status --json guidance
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package task
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
|
|
larkcore "github.com/larksuite/oapi-sdk-go/v3/core"
|
|
|
|
"github.com/larksuite/cli/shortcuts/common"
|
|
)
|
|
|
|
var SubscribeTaskEvent = common.Shortcut{
|
|
Service: "task",
|
|
Command: "+subscribe-event",
|
|
Description: "subscribe to task events",
|
|
Risk: "write",
|
|
Scopes: []string{"task:task:read"},
|
|
AuthTypes: []string{"user", "bot"},
|
|
HasFormat: true,
|
|
DryRun: func(ctx context.Context, runtime *common.RuntimeContext) *common.DryRunAPI {
|
|
return common.NewDryRunAPI().
|
|
POST("/open-apis/task/v2/task_v2/task_subscription").
|
|
Params(map[string]interface{}{"user_id_type": "open_id"})
|
|
},
|
|
Execute: func(ctx context.Context, runtime *common.RuntimeContext) error {
|
|
queryParams := make(larkcore.QueryParams)
|
|
queryParams.Set("user_id_type", "open_id")
|
|
apiResp, err := runtime.DoAPI(&larkcore.ApiReq{
|
|
HttpMethod: http.MethodPost,
|
|
ApiPath: "/open-apis/task/v2/task_v2/task_subscription",
|
|
QueryParams: queryParams,
|
|
})
|
|
|
|
// DoAPI may return HTTP 200 while the JSON body contains a non-zero business "code".
|
|
// Parse and validate the envelope to avoid false-success output.
|
|
var result map[string]interface{}
|
|
if err == nil {
|
|
if parseErr := json.Unmarshal(apiResp.RawBody, &result); parseErr != nil {
|
|
return WrapTaskError(ErrCodeTaskInternalError, fmt.Sprintf("failed to parse response: %v", parseErr), "subscribe task events")
|
|
}
|
|
}
|
|
if _, err := HandleTaskApiResult(result, err, "subscribe task events"); err != nil {
|
|
return err
|
|
}
|
|
|
|
outData := map[string]interface{}{"ok": true}
|
|
runtime.OutFormat(outData, nil, func(w io.Writer) {
|
|
fmt.Fprintln(w, "✅ Task event subscription created successfully!")
|
|
})
|
|
return nil
|
|
},
|
|
}
|