Documentation ¶
Overview ¶
Package dingbot provides Bot related APIs for dingtalk open platform.
Index ¶
Examples ¶
Constants ¶
const ( WebhookURL = "https://oapi.dingtalk.com/robot/send" DingCodeOk = 0 )
constants
const ( MsgTypeText = "text" MsgTypeLink = "link" MsgTypeMd = "markdown" MsgTypeActionCard = "actionCard" MsgTypeFeedCard = "feedCard" )
exported message types
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ActionCardMsg ¶
type ActionCardMsg struct { Text string `json:"text"` Title string `json:"title"` HideAvatar string `json:"hideAvatar"` // "0" or "1" BtnOrientation string `json:"btnOrientation"` // "0" or "1" // single card SingleTitle string `json:"singleTitle"` SingleURL string `json:"singleURL"` // independent cards Btns []struct { Title string `json:"title"` ActionURL string `json:"actionURL"` } `json:"btns"` }
ActionCardMsg represents a action card.
type DingMessage ¶
type DingMessage struct { Msgtype string `json:"msgtype"` Text *TextMsg `json:"text,omitempty"` Link *LinkMsg `json:"link,omitempty"` Markdown *MarkdownMsg `json:"markdown,omitempty"` ActionCard *ActionCardMsg `json:"actionCard,omitempty"` FeedCard *FeedCardMsg `json:"feedCard,omitempty"` At *AtOption `json:"at,omitempty"` }
DingMessage is the JSON-encoded message to send.
type DingResponse ¶
DingResponse is the response for sending msg.
func (DingResponse) Error ¶
func (d DingResponse) Error() string
type FeedCardMsg ¶
type FeedCardMsg struct {
Links []FeedLink `json:"links"`
}
FeedCardMsg represents a feed card.
type FeedLink ¶
type FeedLink struct { Title string `json:"title"` PicURL string `json:"picUrl"` MessageURL string `json:"messageUrl"` }
FeedLink represents a feed.
type LinkMsg ¶
type LinkMsg struct { Text string `json:"text"` Title string `json:"title"` PicURL string `json:"picUrl,omitempty"` MessageURL string `json:"messageUrl"` }
LinkMsg represents a link.
type MarkdownMsg ¶
MarkdownMsg represents markdown formatted text.
type Sender ¶
type Sender interface { // Send sends a DingMessage. Send(*DingMessage) error }
Sender sends messages of various types to a Dingtalk group.
type Webhook ¶
type Webhook struct {
// contains filtered or unexported fields
}
Webhook sends the message via webhook API. See https://open-doc.dingtalk.com/microapp/serverapi2/qf2nxq.
Example ¶
package main import ( "fmt" "github.com/practigo/dingbot" ) func main() { var testToken = "YOUR_TOKEN_HERE" bot := dingbot.NewWebhook(testToken) var testSecret = "" // if you have secret set, fill here bot.WithSecret(testSecret) msg := dingbot.DingMessage{ Msgtype: dingbot.MsgTypeText, Text: &dingbot.TextMsg{ Content: "hello world", }, } fmt.Println(bot.Send(&msg)) }
Output: Error 300001: token is not exist
func NewWebhook ¶
NewWebhook returns a Webhook with the provided token.
func (*Webhook) Send ¶
func (b *Webhook) Send(msg *DingMessage) (err error)
Send sends a DingMessage. The underlying HTTP client has a 5s timeout and will not retry when fail.
func (*Webhook) WithSecret ¶
WithSecret sets the webhook serect for passing the security check.