dingtalk

package
v0.100.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package dingtalk provides cryptographic utilities for DingTalk.

Package dingtalk implements the DingTalk Robot channel.

Index

Constants

View Source
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

func DecryptCallback(encryptKey, ciphertext, iv string) ([]byte, error)

DecryptCallback decrypts a callback from DingTalk (for enterprise robots).

func SignURL

func SignURL(appSecret, url string, params map[string]string) string

SignURL generates a signature for DingTalk API requests.

func VerifyWebhookSignature

func VerifyWebhookSignature(timestamp, sign, secret, body string) bool

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

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

type DingTalkConfig struct {
	AppKey    string
	AppSecret string
}

DingTalkConfig holds configuration for the DingTalk channel.

type DingTalkFileContent

type DingTalkFileContent struct {
	MediaID  string `json:"media_id"`
	FileName string `json:"file_name"`
}

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"`
}

Jump to

Keyboard shortcuts

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