go_dingtalk_sdk_wrapper

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 20 Imported by: 5

README

go-dingtalk-sdk-wrapper

go-dingtalk-sdk-wrapper

wrapper https://github.com/alibabacloud-go/dingtalk to used easily

如果官方已经有最新的 sdk可以实现,这里只需加入功能后给出示例即可,不需要再实现

go get github.com/xops-infra/go-dingtalk-sdk-wrapper
Usage
  1. 钉钉机器人:
  2. 事件订阅 Stream
  3. 工单相关 Workflow

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionCardBody

type ActionCardBody struct {
	HideAvatar     string    `json:"hideAvatar"`
	BtnOrientation string    `json:"btnOrientation"`
	Single         string    `json:"singleURL"`
	SingleTitle    string    `json:"singleTitle"`
	Title          string    `json:"title"`
	Text           string    `json:"text"`
	Btns           []BtnBody `json:"btns"`
}

type AlertPerson

type AlertPerson map[string]string

func (AlertPerson) Marshal

func (p AlertPerson) Marshal() string

type ApprovalResult

type ApprovalResult string
const (
	Agree     ApprovalResult = "agree"
	Refuse    ApprovalResult = "refuse"
	Revoke    ApprovalResult = "revoke"
	Approving ApprovalResult = "approving"
)

type ApprovalStatus

type ApprovalStatus string
const (
	Running    ApprovalStatus = "RUNNING"
	Completed  ApprovalStatus = "COMPLETED"
	Terminated ApprovalStatus = "TERMINATED"
	New        ApprovalStatus = "NEW"
	Canceled   ApprovalStatus = "CANCELED"
)

流程实例状态,未传值代表查询所有状态的实例ID列表。 NEW:新创建 RUNNING:审批中 TERMINATED:被终止 COMPLETED:完成 CANCELED:取消

func (ApprovalStatus) String

func (s ApprovalStatus) String() string

to string

type ApprovalTask

type ApprovalTask struct {
	ActivityId        *string `json:"activityId,omitempty" xml:"activityId,omitempty"`
	CreateTime        *string `json:"createTime,omitempty" xml:"createTime,omitempty"`
	FinishTime        *string `json:"finishTime,omitempty" xml:"finishTime,omitempty"`
	MobileUrl         *string `json:"mobileUrl,omitempty" xml:"mobileUrl,omitempty"`
	PcUrl             *string `json:"pcUrl,omitempty" xml:"pcUrl,omitempty"`
	ProcessInstanceId *string `json:"processInstanceId,omitempty" xml:"processInstanceId,omitempty"`
	Result            *string `json:"result,omitempty" xml:"result,omitempty"`
	Status            *string `json:"status,omitempty" xml:"status,omitempty"`
	TaskId            *int64  `json:"taskId,omitempty" xml:"taskId,omitempty"`
	UserId            *string `json:"userId,omitempty" xml:"userId,omitempty"`
}

type AtBody

type AtBody struct {
	IsAtAll   bool     `json:"isAtAll"`
	AtMobiles []string `json:"atMobiles"`
	AtUserIDS []string `json:"atUserIds"`
}

type AttachmentFiled

type AttachmentFiled struct {
	SpaceID   string    `json:"spaceId"`
	FileName  string    `json:"fileName"`
	Thumbnail Thumbnail `json:"thumbnail"`
	FileSize  any       `json:"fileSize"`
	FileType  string    `json:"fileType"`
	FileID    string    `json:"fileId"`
}

type BtnBody

type BtnBody struct {
	ActionURL string `json:"actionURL"`
	Title     string `json:"title"`
}

type CommentInput

type CommentInput struct {
	ProcessID     string
	Comment       string      //评论内容
	AlertPerson   AlertPerson //通知@多人,  "[周xx](2907024xxxx09257xxxx)[崔xx](303256xxxx8455xxxx)"
	CommentUserID string      //指评论的人
}

type CommentResp

type CommentResp struct {
}

type CommonResponse

type CommonResponse struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
	// task_id
	TaskId int `json:"task_id"` // 发送任务的id
	// request_id
	RequestId string `json:"request_id"` // 请求id
}

type ContactClient

type ContactClient struct {
	// contains filtered or unexported fields
}

func NewContactClient

func NewContactClient(client *contact.Client, token *TokenDetail) *ContactClient

func (*ContactClient) DepartmentList

func (c *ContactClient) DepartmentList(ctx context.Context) ([]*int64, error)

DepartmentList 403 forbidden

type CreateProcessInstanceInput

type CreateProcessInstanceInput struct {
	ProcessCode         string               `json:"processCode" binding:"required"`         // 流程模板唯一标识,可在OA管理后台编辑审批表单部分查询
	OriginatorUserID    string               `json:"originatorUserId" binding:"required"`    // 审批实例发起人的userid
	FormComponentValues []FormComponentValue `json:"formComponentValues" binding:"required"` // 审批流表单参数 表单数据内容,控件列表,最大列表长度:150。
	DeptId              string               `json:"deptId"`                                 // 若approvers未传值时(即不直接指定审批人列表),则deptId需必填,若为根部门ID需填-1。
}

type CreateProcessInstanceResponse

type CreateProcessInstanceResponse struct {
	InstanceId string `json:"instanceId"`
}

type Depart

type Depart interface {
	// 获取部门详情
	GetDepartmentDetail(input *GetDepartmentDetailInput, accessToken string) (*Department, error)
	// 获取部门列表
	GetDepartments(input *GetDepartmentsInput, accessToken string) ([]*Department, error)
	// 获取所有部门
	GetAllDepartments(accessToken string) ([]*Department, error)
	// 获取子部门ID列表
	GetDepartmentIDs(input *GetDepartmentsIDInput, accessToken string) ([]int64, error)
	// 获取所有部门 ID
	GetAllDepartmentIDs(accessToken string) ([]int64, error)
}

func NewDepart

func NewDepart(requestBuilder requestBuilder) Depart

type Department

type Department struct {
	DepartID int64  `json:"dept_id"`
	Name     string `json:"name"`
	ParentID int64  `json:"parent_id"`
	// create_dept_group bool
	CreateDeptGroup bool `json:"create_dept_group"`
	// auto_add_user bool
	AutoAddUser bool `json:"auto_add_user"`
}

type DingTalkClient

type DingTalkClient struct {
	OpenapiConfig *openapi.Config
	AuthClient    *oauth.Client
	//AccessTokenCache
	AccessToken    *TokenDetail
	Locker         *sync.Mutex
	DingTalkConfig *DingTalkConfig
	// Needed Client
	WorkflowClient *WorkflowClient
	MiniProgram    MiniProgram
	Workflow       Workflow
	Depart         Depart
	User           User
	// contains filtered or unexported fields
}

func NewDingTalkClient

func NewDingTalkClient(appConfig *DingTalkConfig) (*DingTalkClient, error)

func (*DingTalkClient) CronSetAccessToken

func (d *DingTalkClient) CronSetAccessToken() error

func (*DingTalkClient) SetAccessToken

func (d *DingTalkClient) SetAccessToken() error

func (*DingTalkClient) WithDepartClient

func (d *DingTalkClient) WithDepartClient() *DingTalkClient

func (*DingTalkClient) WithMiniProgramClient

func (d *DingTalkClient) WithMiniProgramClient(agentId int64) *DingTalkClient

func (*DingTalkClient) WithUserClient

func (d *DingTalkClient) WithUserClient() *DingTalkClient

func (*DingTalkClient) WithWorkflowClient

func (d *DingTalkClient) WithWorkflowClient() *DingTalkClient

func (*DingTalkClient) WithWorkflowClientV2

func (d *DingTalkClient) WithWorkflowClientV2() *DingTalkClient

func (*DingTalkClient) WorkflowSvc

func (d *DingTalkClient) WorkflowSvc() *WorkflowClient

type DingTalkConfig

type DingTalkConfig struct {
	AppKey    string
	CorpId    string
	AppSecret string
	AgentId   string
}

type FeedCard

type FeedCard struct {
	Links []LinkBody `json:"links"`
}

type FormComponentValue

type FormComponentValue struct {
	ID            *string `json:"id"`
	ExtValue      *string `json:"extValue"`
	ComponentType *string `json:"componentType"`
	BizAlias      *string `json:"bizAlias"`
	Name          *string `json:"name" binding:"required"`  // 表单控件名称
	Value         *string `json:"value" binding:"required"` // 表单控件值
}

type GetDepartmentDetailInput added in v1.2.0

type GetDepartmentDetailInput struct {
	// dept_id number
	DeptID int64 `json:"dept_id"`
	// language string example:zh_CN,en_US
	Language string `json:"language"`
}

type GetDepartmentDetailResponse added in v1.2.0

type GetDepartmentDetailResponse struct {
	// request_id
	RequestId string `json:"request_id"`
	// errcode
	ErrCode int `json:"errcode"`
	// errmsg
	ErrMsg string `json:"errmsg"`
	// result
	Result Department `json:"result"`
}

type GetDepartmentsIDInput

type GetDepartmentsIDInput struct {
	// dept_id number
	DeptID int64 `json:"dept_id"`
}

type GetDepartmentsIDResponse

type GetDepartmentsIDResponse struct {
	// request_id
	RequestId string `json:"request_id"`
	// errcode
	ErrCode int `json:"errcode"`
	// errmsg
	ErrMsg string `json:"errmsg"`
	// result
	Result struct {
		DepartIDList []int64 `json:"dept_id_list"`
	} `json:"result"`
}

type GetDepartmentsInput

type GetDepartmentsInput struct {
	// dept_id number
	DeptID int64 `json:"dept_id"`
	// language string example:zh_CN,en_US
	Language string `json:"language"`
}

type GetDepartmentsResponse

type GetDepartmentsResponse struct {
	// request_id
	RequestId string `json:"request_id"`
	// errcode
	ErrCode int `json:"errcode"`
	// errmsg
	ErrMsg string `json:"errmsg"`
	// result
	Result []*Department `json:"result"`
}

type GetUsersInput

type GetUsersInput struct {
	// dept_id number
	DeptID int64 `json:"dept_id"`
	// cursor number 分页查询的游标,最开始传0,后续传返回参数中的next_cursor值。
	Cursor int64 `json:"cursor" default:"0"`
	// size number 每页条数。
	Size int64 `json:"size" default:"20"`
}

type GetUsersResponse

type GetUsersResponse struct {
	// errcode
	ErrCode int64 `json:"errcode"`
	// errmsg
	ErrMsg string `json:"errmsg"`
	// result
	Result struct {
		// has_more bool
		HasMore bool `json:"has_more"`
		// next_cursor number
		NextCursor int64 `json:"next_cursor"`
		// list
		List []*UserInfo `json:"list"`
	} `json:"result"`
}

type GrantProcessInstanceForDownloadFileInput

type GrantProcessInstanceForDownloadFileInput struct {
	FileId    string
	ProcessID string
}

type Json

type Json map[string]interface{}

type LinkBody

type LinkBody struct {
	MessageUrl string `json:"messageUrl"`
	Title      string `json:"title"`
	PicUrl     string `json:"picUrl"`
	Text       string `json:"text"`
}

type ListWorkflowInput

type ListWorkflowInput struct {
	ProcessCode string
	StartTime   int64
	EndTime     int64
	NextToken   int64
	Statuses    []ApprovalStatus
}

type LowApiError

type LowApiError struct {
	ErrMsg  string `json:"errmsg"`
	ErrCode uint   `json:"errcode"`
}

func (*LowApiError) Error

func (e *LowApiError) Error() string

type MarkDownBody

type MarkDownBody struct {
	Title string `json:"title"`
	Text  string `json:"text"`
}

type MessageContent

type MessageContent struct {
	MsgType    string         `json:"msgtype"`
	Text       TextBody       `json:"text,omitempty"`
	At         AtBody         `json:"at,omitempty"`
	Link       LinkBody       `json:"link,omitempty"`
	MarkDown   MarkDownBody   `json:"markdown,omitempty"`
	ActionCard ActionCardBody `json:"actionCard,omitempty"`
}

type MiniProgram

type MiniProgram interface {
	// 使用机器人发送工作通知
	SendWorkNotification(ctx context.Context, req *SendWorkNotificationRequest, accessToken string) error
	// 发送到群会话,chatID很难找,弃用。改用群机器人
	SendGroupNotification(ctx context.Context, req *SendGroupNotificationRequest, accessToken string) error //发送消息到企业群接口相关文档,已于2022年09月23日迁移至历史文档(不推荐)目录。不再支持新应用接入,已接入的应用可以正常调用。
}

func NewMiniProgram

func NewMiniProgram(agentId int64, requestBuilder requestBuilder) MiniProgram

agentId 应用程序的agentId,后台查看

type OperationRecord added in v1.1.0

type OperationRecord struct {
	UserId      *string           `json:"userId"`
	Date        *string           `json:"date"`
	Type        *string           `json:"type"`
	Result      *string           `json:"result"`
	Remark      *string           `json:"remark"`
	Attachments []AttachmentFiled `json:"attachments"`
	CcUserIds   []string          `json:"ccUserIds"`
}

type ProcessInstanceResp

type ProcessInstanceResp workflow.GetProcessInstanceResponseBody

func (*ProcessInstanceResp) GetAttachmentFileIDs

func (r *ProcessInstanceResp) GetAttachmentFileIDs() ([]AttachmentFiled, error)

func (*ProcessInstanceResp) GetComment

func (r *ProcessInstanceResp) GetComment() ([]CommentResp, error)

drop 用户直接在detail获取操作

func (*ProcessInstanceResp) GetResult

func (r *ProcessInstanceResp) GetResult() ApprovalResult

func (*ProcessInstanceResp) GetStatus

func (r *ProcessInstanceResp) GetStatus() ApprovalStatus

func (*ProcessInstanceResp) IsAgree

func (r *ProcessInstanceResp) IsAgree() bool

type ProcessInstanceRespV2 added in v1.1.0

type ProcessInstanceRespV2 struct {
	Success bool                  `json:"success"`
	Result  ProcessInstanceResult `json:"result"`
}

type ProcessInstanceResult added in v1.1.0

type ProcessInstanceResult struct {
	Status              *string              `json:"status"`
	Title               *string              `json:"title"`
	FinishTime          *string              `json:"finishTime"`
	CreateTime          *string              `json:"createTime"`
	Result              *string              `json:"result"`
	BusinessId          *string              `json:"businessId"`
	OperationRecords    []OperationRecord    `json:"operationRecords"`
	Tasks               []ApprovalTask       `json:"tasks"`
	FormComponentValues []FormComponentValue `json:"formComponentValues"`
}

没有完全写完,需要自己加入解析的字段

type RobotClient

type RobotClient struct {
	// contains filtered or unexported fields
}

func NewRobotClient

func NewRobotClient() *RobotClient

func (*RobotClient) SendMessage

func (c *RobotClient) SendMessage(ctx context.Context, req *SendMessageRequest) error

type SendGroupNotificationRequest

type SendGroupNotificationRequest struct {
	// chatid
	ChatId *string `json:"chatid" required:"true"` // 群会话的id
	// msg
	Msg *MessageContent `json:"msg" required:"true"` // 消息内容,消息类型和样例可参考“消息类型与数据格式”。最长不超过2048个字节
}

type SendMessageRequest

type SendMessageRequest struct {
	AccessToken    string         `json:"access_token"`
	Sign           string         `json:"sign"`
	MessageContent MessageContent `json:"message_content"`
}

type SendWorkNotificationRequest

type SendWorkNotificationRequest struct {
	// agent_id
	AgentId *int64 `json:"agent_id" required:"true"` // 应用agentId。 12345
	// userid_list
	UseridList *string `json:"userid_list" example:"user123,user456"` // 接收者的用户userid列表,最大列表长度:100
	// dept_id_list
	DeptIdList *string `json:"dept_id_list" example:"123,456"` // 接收者的部门id列表。最大列表长度为20
	// to_all_user
	ToAllUser *bool `json:"to_all_user" default:"false"` // 是否发送给企业全部用户 当设置为false时必须指定userid_list或dept_id_list其中一个参数的值。
	// msg { "msgtype": "text", "text": { "content": "请提交日报。" } }
	Msg *MessageContent `json:"msg" required:"true"` // 消息内容,消息类型和样例可参考“消息类型与数据格式”。最长不超过2048个字节
}

type TextBody

type TextBody struct {
	Content string `json:"content"`
}

type Thumbnail

type Thumbnail struct {
	AuthCode    string `json:"authCode"`
	AuthMediaID string `json:"authMediaId"`
	Rotation    int    `json:"rotation"`
	Width       int    `json:"width"`
	MediaID     string `json:"mediaId"`
	Height      int    `json:"height"`
}

type TokenDetail

type TokenDetail struct {
	// Dingtalk token
	Token    string `json:"token"`
	CreateAt int64  `json:"create_at"`
	ExpireIn int64  `json:"expire_in"`
}

func (*TokenDetail) IsExpire

func (t *TokenDetail) IsExpire() bool

type User

type User interface {
	// 获取部门id的用户信息
	GetUsers(*GetUsersInput, string) ([]*UserInfo, error)
}

func NewUser

func NewUser(requestBuilder requestBuilder) User

type UserClient

type UserClient struct {
	// contains filtered or unexported fields
}

func (*UserClient) GetUsers

func (c *UserClient) GetUsers(input *GetUsersInput, accessToken string) ([]*UserInfo, error)

type UserInfo

type UserInfo struct {
	// userid string
	UserID string `json:"userid"`
	// unionid string
	UnionID string `json:"unionid"`
	// name string
	Name string `json:"name"`
	// avatar
	Avatar string `json:"avatar"`
	// state_code 国际电话区号。
	StateCode string `json:"state_code"`
	// mobile
	Mobile string `json:"mobile"`
	// hide_mobile bool
	HideMobile bool `json:"hide_mobile"`
	// telephone string 分机号
	Telephone string `json:"telephone"`
	// job_number
	JobNumber string `json:"job_number"`
	// title
	Title string `json:"title"`
	// email
	Email string `json:"email"`
	// org_email
	OrgEmail string `json:"org_email"`
	// work_place
	WorkPlace string `json:"work_place"`
	// remark
	Remark string `json:"remark"`
	// dept_id_list
	DeptIDList []int64 `json:"dept_id_list"`
	// dept_order number 员工在部门中的排序。
	DeptOrder int64 `json:"dept_order"`
	// extension string 扩展属性。
	Extension string `json:"extension"`
	// hired_date number 入职时间,Unix时间戳,单位毫秒。
	HiredDate int64 `json:"hired_date"`
	// active bool
	Active bool `json:"active"`
	// admin
	Admin bool `json:"admin"`
	// boss
	Boss bool `json:"boss"`
	// leader
	Leader bool `json:"leader"`
	// exclusive_account 是否企业账号
	ExclusiveAccount bool `json:"exclusive_account"`
}

type Workflow

type Workflow interface {
	// 创建审批实例
	CreateProcessInstance(input *CreateProcessInstanceInput, accessToken string) (string, error)
	// 查询审批工单
	GetProcessInstance(processID string, accessToken string) (*ProcessInstanceRespV2, error)
}

func NewWorkflowV2

func NewWorkflowV2(requestBuilder requestBuilder) Workflow

type WorkflowClient

type WorkflowClient struct {
	// contains filtered or unexported fields
}

func NewWorkflowClient

func NewWorkflowClient(client *workflow.Client, token *TokenDetail) *WorkflowClient

func (*WorkflowClient) AddProcessInstancedComment

func (c *WorkflowClient) AddProcessInstancedComment(ctx context.Context, input *CommentInput) error

func (*WorkflowClient) GetProcessInstance

func (c *WorkflowClient) GetProcessInstance(ctx context.Context,
	processID string) (*ProcessInstanceResp, error)

func (*WorkflowClient) ListProcessInstanceIds

func (c *WorkflowClient) ListProcessInstanceIds(ctx context.Context, input *ListWorkflowInput) ([]string, error)

func (*WorkflowClient) TerminateProcessInstance

func (c *WorkflowClient) TerminateProcessInstance(ctx context.Context,
	processID string) (bool, error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL