forked from riba2534/feishu-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_create.go
More file actions
68 lines (55 loc) · 1.92 KB
/
chat_create.go
File metadata and controls
68 lines (55 loc) · 1.92 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 chatCreateCmd = &cobra.Command{
Use: "create",
Short: "创建群聊",
Long: `创建一个新的群聊。
参数:
--name 群名称(必填)
--description 群描述
--owner-id 群主 ID
--user-ids 邀请的成员 ID 列表(逗号分隔)
--chat-type 群类型(private/public,默认 private)
示例:
# 创建私有群
feishu-cli chat create --name "测试群"
# 创建公开群并邀请成员
feishu-cli chat create --name "公开群" --chat-type public --user-ids ou_xxx,ou_yyy
# 指定群主创建群
feishu-cli chat create --name "项目群" --owner-id ou_xxx --description "项目讨论群"`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := config.Validate(); err != nil {
return err
}
name, _ := cmd.Flags().GetString("name")
description, _ := cmd.Flags().GetString("description")
ownerID, _ := cmd.Flags().GetString("owner-id")
userIDsStr, _ := cmd.Flags().GetString("user-ids")
chatType, _ := cmd.Flags().GetString("chat-type")
var userIDs []string
if userIDsStr != "" {
userIDs = splitAndTrim(userIDsStr)
}
chatID, err := client.CreateChat(name, description, ownerID, userIDs, chatType)
if err != nil {
return err
}
fmt.Printf("群聊创建成功!\n")
fmt.Printf(" 群 ID: %s\n", chatID)
return nil
},
}
func init() {
chatCmd.AddCommand(chatCreateCmd)
chatCreateCmd.Flags().String("name", "", "群名称")
chatCreateCmd.Flags().String("description", "", "群描述")
chatCreateCmd.Flags().String("owner-id", "", "群主 ID")
chatCreateCmd.Flags().String("user-ids", "", "邀请的成员 ID 列表(逗号分隔)")
chatCreateCmd.Flags().String("chat-type", "private", "群类型(private/public)")
mustMarkFlagRequired(chatCreateCmd, "name")
}