forked from riba2534/feishu-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_message.go
More file actions
68 lines (55 loc) · 1.44 KB
/
delete_message.go
File metadata and controls
68 lines (55 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cmd
import (
"fmt"
"github.com/riba2534/feishu-cli/internal/client"
"github.com/riba2534/feishu-cli/internal/config"
"github.com/spf13/cobra"
)
var deleteMessageCmd = &cobra.Command{
Use: "delete <message_id>",
Short: "删除消息",
Long: `删除指定的消息。
参数:
message_id 消息 ID(必填)
--output, -o 输出格式(json)
注意:
- 只能删除机器人发送的消息
- 删除后消息不可恢复
示例:
# 删除消息
feishu-cli msg delete om_xxx
# JSON 格式输出
feishu-cli msg delete om_xxx --output json`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := config.Validate(); err != nil {
return err
}
token, err := resolveRequiredUserToken(cmd)
if err != nil {
return err
}
messageID := args[0]
if err := client.DeleteMessage(messageID, token); err != nil {
return err
}
output, _ := cmd.Flags().GetString("output")
if output == "json" {
if err := printJSON(map[string]any{
"success": true,
"message_id": messageID,
}); err != nil {
return err
}
} else {
fmt.Printf("消息删除成功!\n")
fmt.Printf(" 消息 ID: %s\n", messageID)
}
return nil
},
}
func init() {
msgCmd.AddCommand(deleteMessageCmd)
deleteMessageCmd.Flags().StringP("output", "o", "", "输出格式(json)")
deleteMessageCmd.Flags().String("user-access-token", "", "User Access Token(用户授权令牌)")
}