package dingtalk import ( "ai_scheduler/internal/config" errorcode "ai_scheduler/internal/data/error" openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client" robot "github.com/alibabacloud-go/dingtalk/robot_1_0" util "github.com/alibabacloud-go/tea-utils/v2/service" "github.com/alibabacloud-go/tea/tea" ) type RobotClient struct { config *config.Config cli *robot.Client } func NewRobotClient(config *config.Config) (*RobotClient, error) { cfg := &openapi.Config{ AccessKeyId: tea.String(config.Tools.DingTalkBot.APIKey), AccessKeySecret: tea.String(config.Tools.DingTalkBot.APISecret), Protocol: tea.String("https"), RegionId: tea.String("central"), } c, err := robot.NewClient(cfg) if err != nil { return nil, err } return &RobotClient{config: config, cli: c}, nil } type SendGroupMessagesReq struct { FullMatchField int32 QueryWord string Offset int32 Size int32 } type SendGroupMessagesResp struct { Body interface{} } func (c *RobotClient) SendGroupMessages(accessToken string, name string) (string, error) { headers := &robot.OrgGroupSendHeaders{} headers.XAcsDingtalkAccessToken = tea.String(accessToken) resp, err := c.cli.OrgGroupSendWithOptions(&robot.OrgGroupSendRequest{ MsgKey: tea.String("sampleText"), MsgParam: tea.String("{\"content\":\"今天吃肘子\"}"), OpenConversationId: tea.String("cidwP24PLZhLVOS2dVIkEawLw=="), RobotCode: tea.String("ding5wwvnf9hxeyjau7t"), }, headers, &util.RuntimeOptions{}) if err != nil { return "", err } if resp.Body == nil { return "", errorcode.ParamErrf("empty response body") } return *resp.Body.ProcessQueryKey, nil }