2022-06-04 20:25:23 +02:00
|
|
|
package lark
|
|
|
|
|
|
|
|
// sender is an interface for sending a message to an already defined receiver.
|
2022-09-12 13:46:07 +02:00
|
|
|
//
|
|
|
|
//go:generate mockery --name=sender --output=. --case=underscore --inpackage
|
2022-06-04 20:25:23 +02:00
|
|
|
type sender interface {
|
|
|
|
Send(subject, message string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// sender is an interface for sending a message to a specific receiver ID.
|
2022-09-12 13:46:07 +02:00
|
|
|
//
|
|
|
|
//go:generate mockery --name=sendToer --output=. --case=underscore --inpackage
|
2022-06-04 20:25:23 +02:00
|
|
|
type sendToer interface {
|
|
|
|
SendTo(subject, message, id, idType string) error
|
|
|
|
}
|
|
|
|
|
2022-08-31 08:23:42 +02:00
|
|
|
// ReceiverID encapsulates a receiver ID and its type in Lark.
|
|
|
|
type ReceiverID struct {
|
2022-06-04 20:25:23 +02:00
|
|
|
id string
|
|
|
|
typ receiverIDType
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenID specifies an ID as a Lark Open ID.
|
2022-08-31 08:23:42 +02:00
|
|
|
func OpenID(s string) *ReceiverID {
|
|
|
|
return &ReceiverID{s, openID}
|
2022-06-04 20:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// UserID specifies an ID as a Lark User ID.
|
2022-08-31 08:23:42 +02:00
|
|
|
func UserID(s string) *ReceiverID {
|
|
|
|
return &ReceiverID{s, userID}
|
2022-06-04 20:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnionID specifies an ID as a Lark Union ID.
|
2022-08-31 08:23:42 +02:00
|
|
|
func UnionID(s string) *ReceiverID {
|
|
|
|
return &ReceiverID{s, unionID}
|
2022-06-04 20:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Email specifies a receiver ID as an email.
|
2022-08-31 08:23:42 +02:00
|
|
|
func Email(s string) *ReceiverID {
|
|
|
|
return &ReceiverID{s, email}
|
2022-06-04 20:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ChatID specifies an ID as a Lark Chat ID.
|
2022-08-31 08:23:42 +02:00
|
|
|
func ChatID(s string) *ReceiverID {
|
|
|
|
return &ReceiverID{s, chatID}
|
2022-06-04 20:25:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// receiverIDType represents the different ID types implemented by Lark. This
|
|
|
|
// information is required when sending a message. More information about the
|
|
|
|
// different ID types can be found in the "Query parameters" section of
|
|
|
|
// the https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/create,
|
|
|
|
// or on
|
|
|
|
// https://open.larksuite.com/document/home/user-identity-introduction/introduction.
|
|
|
|
type receiverIDType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
openID receiverIDType = "open_id"
|
2022-08-04 17:13:17 +02:00
|
|
|
userID receiverIDType = "user_id"
|
|
|
|
unionID receiverIDType = "union_id"
|
|
|
|
email receiverIDType = "email"
|
|
|
|
chatID receiverIDType = "chat_id"
|
2022-06-04 20:25:23 +02:00
|
|
|
)
|