| 1 | package lark |
| 2 | |
| 3 | // RequestBody represents the payload sent to the Lark API. |
| 4 | type RequestBody struct { |
| 5 | MsgType MsgType `json:"msg_type"` |
| 6 | Content Content `json:"content"` |
| 7 | Timestamp string `json:"timestamp,omitempty"` |
| 8 | Sign string `json:"sign,omitempty"` |
| 9 | } |
| 10 | |
| 11 | // MsgType defines the type of message to send. |
| 12 | type MsgType string |
| 13 | |
| 14 | // Content holds the message content, supporting text or post formats. |
| 15 | type Content struct { |
| 16 | Text string `json:"text,omitempty"` |
| 17 | Post *Post `json:"post,omitempty"` |
| 18 | } |
| 19 | |
| 20 | // Post represents a rich post message with language-specific content. |
| 21 | type Post struct { |
| 22 | Zh *Message `json:"zh_cn,omitempty"` // Chinese content |
| 23 | En *Message `json:"en_us,omitempty"` // English content |
| 24 | } |
| 25 | |
| 26 | // Message defines the structure of a post message. |
| 27 | type Message struct { |
| 28 | Title string `json:"title"` |
| 29 | Content [][]Item `json:"content"` |
| 30 | } |
| 31 | |
| 32 | // Item represents a content element within a post message. |
| 33 | type Item struct { |
| 34 | Tag TagValue `json:"tag"` |
| 35 | Text string `json:"text,omitempty"` |
| 36 | Link string `json:"href,omitempty"` |
| 37 | } |
| 38 | |
| 39 | // TagValue specifies the type of content item. |
| 40 | type TagValue string |
| 41 | |
| 42 | // Response represents the API response from Lark. |
| 43 | type Response struct { |
| 44 | Code int `json:"code"` |
| 45 | Msg string `json:"msg"` |
| 46 | Data any `json:"data"` |
| 47 | } |
| 48 | |
| 49 | // Constants for message types supported by Lark. |
| 50 | const ( |
| 51 | MsgTypeText MsgType = "text" |
| 52 | MsgTypePost MsgType = "post" |
| 53 | ) |
| 54 | |
| 55 | // Constants for tag values supported by Lark. |
| 56 | // |
| 57 | //nolint:goconst // TagValueTextContent and MsgTypeText have same value but represent different concepts |
| 58 | const ( |
| 59 | TagValueTextContent TagValue = "text" |
| 60 | TagValueLink TagValue = "a" |
| 61 | ) |