package main import ( "context" "encoding/json" "fmt" "github.com/coze-dev/coze-go" "net/http" "time" ) var ( token = "pat_3Qryy0Dgo1nA0eZ9CoTlC4GDQECphJcD7ZVWF5iSQ1qXMahca8xeWU08NFv9i8XY" api = "https://api.coze.cn" ) type OutlineResp struct { Sections []struct { Contents []struct { Items []struct { Items []string `json:"items"` Title string `json:"title"` } `json:"items"` Subtitle string `json:"subtitle"` Title string `json:"title"` } `json:"contents"` Subtitle string `json:"subtitle"` Title string `json:"title"` } `json:"sections"` Subtitle string `json:"subtitle"` Title string `json:"title"` } type ThemeResp struct { Data []struct { ID int `json:"id"` Keywords string `json:"keywords"` Thumbnail string `json:"thumbnail"` Title string `json:"title"` Type string `json:"type"` } `json:"data"` } type PptResp struct { FileUrl string `json:"file_url"` } func WorkflowOutline(ctx context.Context, keyword string) (resData OutlineResp, err error) { workflowId := "7514159115984617524" auth := coze.NewTokenAuth(token) // Init the Coze client through the access_token. cozeCli := coze.NewCozeAPI(auth, coze.WithBaseURL(api), coze.WithHttpClient(&http.Client{ Timeout: time.Second * 5000, })) // if your workflow need input params, you can send them by map data := map[string]interface{}{ "keyword": keyword, } req := &coze.RunWorkflowsReq{ WorkflowID: workflowId, Parameters: data, IsAsync: false, } resp, err := cozeCli.Workflows.Runs.Create(ctx, req) if err != nil { return } json.Unmarshal([]byte(resp.Data), &resData) return } func WorkflowTheme(ctx context.Context, keyword string) (res ThemeResp, err error) { workflowId := "7514593043828539407" auth := coze.NewTokenAuth(token) // Init the Coze client through the access_token. cozeCli := coze.NewCozeAPI(auth, coze.WithBaseURL(api), coze.WithHttpClient(&http.Client{ Timeout: time.Second * 5000, })) // if your workflow need input params, you can send them by map data := map[string]interface{}{ "keyword": keyword, } req := &coze.RunWorkflowsReq{ WorkflowID: workflowId, Parameters: data, IsAsync: false, } resp, err := cozeCli.Workflows.Runs.Create(ctx, req) fmt.Println(resp, req) if err != nil { return } err = json.Unmarshal([]byte(resp.Data), &res) return } func WorkflowPpt(ctx context.Context, outline string, themeId int) (res PptResp, err error) { workflowId := "7514654025384951820" auth := coze.NewTokenAuth(token) // Init the Coze client through the access_token. cozeCli := coze.NewCozeAPI(auth, coze.WithBaseURL(api), coze.WithHttpClient(&http.Client{ Timeout: time.Second * 5000, })) // if your workflow need input params, you can send them by map data := map[string]interface{}{ "outline": outline, "themeId": themeId, } req := &coze.RunWorkflowsReq{ WorkflowID: workflowId, Parameters: data, IsAsync: false, } fmt.Println(themeId) resp, err := cozeCli.Workflows.Runs.Create(ctx, req) fmt.Println(resp, err) if err != nil { return } err = json.Unmarshal([]byte(resp.Data), &res) return }