Documentation
¶
Overview ¶
Package dingtalk provides cryptographic utilities for DingTalk.
Package dingtalk implements the DingTalk Robot channel.
Index ¶
- Constants
- func DecryptCallback(encryptKey, ciphertext, iv string) ([]byte, error)
- func SignURL(appSecret, url string, params map[string]string) string
- func VerifyWebhookSignature(timestamp, sign, secret, body string) bool
- type DingTalkChannel
- func (d *DingTalkChannel) Close() error
- func (d *DingTalkChannel) DownloadMedia(ctx context.Context, downloadCode string) ([]byte, string, error)
- func (d *DingTalkChannel) GetAccessToken(ctx context.Context) (string, error)
- func (d *DingTalkChannel) Name() chat_apps.Platform
- func (d *DingTalkChannel) ParseMessage(ctx context.Context, payload []byte) (*chat_apps.IncomingMessage, error)
- func (d *DingTalkChannel) SendChunkedMessage(ctx context.Context, chatID string, chunks <-chan string) error
- func (d *DingTalkChannel) SendMessage(ctx context.Context, msg *chat_apps.OutgoingMessage) error
- func (d *DingTalkChannel) SetWebhookURL(webhookURL string)
- func (d *DingTalkChannel) ValidateWebhook(ctx context.Context, headers map[string]string, body []byte) error
- type DingTalkConfig
- type DingTalkFileContent
- type DingTalkMediaContent
- type DingTalkMessage
- type DingTalkTextContent
Constants ¶
const ( DefaultTimestampWindow = 5 * time.Minute // DingTalk webhook timestamp validity window MaxTimestampSkew = 5 * time.Minute // Maximum allowed clock skew DingTalkAPIBaseURL = "https://oapi.dingtalk.com" )
Variables ¶
This section is empty.
Functions ¶
func DecryptCallback ¶
DecryptCallback decrypts a callback from DingTalk (for enterprise robots).
func VerifyWebhookSignature ¶
VerifyWebhookSignature verifies the DingTalk webhook signature.
Types ¶
type DingTalkChannel ¶
type DingTalkChannel struct {
// contains filtered or unexported fields
}
DingTalkChannel implements ChatChannel for DingTalk Robot.
func NewDingTalkChannel ¶
func NewDingTalkChannel(config *DingTalkConfig) (*DingTalkChannel, error)
NewDingTalkChannel creates a new DingTalk channel.
func (*DingTalkChannel) Close ¶
func (d *DingTalkChannel) Close() error
Close closes the DingTalk channel.
func (*DingTalkChannel) DownloadMedia ¶
func (d *DingTalkChannel) DownloadMedia(ctx context.Context, downloadCode string) ([]byte, string, error)
DownloadMedia downloads media from DingTalk using the downloadCode.
func (*DingTalkChannel) GetAccessToken ¶
func (d *DingTalkChannel) GetAccessToken(ctx context.Context) (string, error)
GetAccessToken retrieves an access token from DingTalk. The token is cached until expiry (default 2 hours).
func (*DingTalkChannel) Name ¶
func (d *DingTalkChannel) Name() chat_apps.Platform
Name returns the platform name.
func (*DingTalkChannel) ParseMessage ¶
func (d *DingTalkChannel) ParseMessage(ctx context.Context, payload []byte) (*chat_apps.IncomingMessage, error)
ParseMessage parses the incoming webhook payload.
func (*DingTalkChannel) SendChunkedMessage ¶
func (d *DingTalkChannel) SendChunkedMessage(ctx context.Context, chatID string, chunks <-chan string) error
SendChunkedMessage sends streaming content chunks. DingTalk doesn't support message editing, so we send chunks as separate messages.
func (*DingTalkChannel) SendMessage ¶
func (d *DingTalkChannel) SendMessage(ctx context.Context, msg *chat_apps.OutgoingMessage) error
SendMessage sends a message to DingTalk.
func (*DingTalkChannel) SetWebhookURL ¶
func (d *DingTalkChannel) SetWebhookURL(webhookURL string)
SetWebhookURL sets the custom webhook URL for this channel.
func (*DingTalkChannel) ValidateWebhook ¶
func (d *DingTalkChannel) ValidateWebhook(ctx context.Context, headers map[string]string, body []byte) error
ValidateWebhook verifies the incoming webhook request using DingTalk signature.
type DingTalkConfig ¶
DingTalkConfig holds configuration for the DingTalk channel.
type DingTalkFileContent ¶
type DingTalkMediaContent ¶
type DingTalkMediaContent struct {
MediaID string `json:"media_id"`
}
type DingTalkMessage ¶
type DingTalkMessage struct {
ChatType string `json:"chatType"`
MsgID string `json:"msgId"`
SenderNick string `json:"senderNick"`
SenderStaffID string `json:"senderStaffId"`
MsgType string `json:"msgtype"`
CreateAt int64 `json:"createAt"`
Text DingTalkTextContent `json:"text"`
Image DingTalkMediaContent `json:"image"`
Audio DingTalkMediaContent `json:"audio"`
Video DingTalkMediaContent `json:"video"`
File DingTalkFileContent `json:"file"`
}
DingTalkMessage represents a message from DingTalk.
type DingTalkTextContent ¶
type DingTalkTextContent struct {
Content string `json:"content"`
}