-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
65 lines (53 loc) · 1.43 KB
/
main.go
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
package main
import (
"context"
"fmt"
"os"
"github.com/coze-dev/coze-go"
)
// This examples is for describing how to retrieve a bot, fetch published bot list from the API.
// The document for those interface:
func main() {
// Get an access_token through personal access token or oauth.
token := os.Getenv("COZE_API_TOKEN")
botID := os.Getenv("PUBLISHED_BOT_ID")
authCli := coze.NewTokenAuth(token)
// Init the Coze client through the access_token.
cozeCli := coze.NewCozeAPI(authCli, coze.WithBaseURL(os.Getenv("COZE_API_BASE")))
ctx := context.Background()
//
// retrieve a bot
botInfo, err := cozeCli.Bots.Retrieve(ctx, &coze.RetrieveBotsReq{
BotID: botID,
})
if err != nil {
fmt.Println("Error retrieving bot:", err)
return
}
fmt.Println(botInfo.Bot)
fmt.Println("Log ID:", botInfo.LogID())
//
// get published bot list
pageNum := 1
workspaceID := os.Getenv("WORKSPACE_ID")
botList, err := cozeCli.Bots.List(ctx, &coze.ListBotsReq{
SpaceID: workspaceID,
PageNum: pageNum,
PageSize: 4,
})
if err != nil {
fmt.Println("Error listing bots:", err)
return
}
// you can use iterator to automatically retrieve next page
for botList.Next() {
fmt.Println(botList.Current())
}
if botList.Err() != nil {
fmt.Println("Error listing bots:", botList.Err())
return
}
// the page result will return followed information
fmt.Println("total:", botList.Total())
fmt.Println("has_more:", botList.HasMore())
}