Fetch the repository succeeded.
package feishu
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
)
type richContentItem map[string]string
type RichContentLine []richContentItem
func (m *RichContentLine) AddLink(content, href string) *RichContentLine {
*m = append(*m, richContentItem{"text": content, "tag": "a", "href": href})
return m
}
func (m *RichContentLine) AddText(content string) *RichContentLine {
*m = append(*m, richContentItem{"text": content, "tag": "text"})
return m
}
type RichContent []RichContentLine
func (m *RichContent) AddLine(v *RichContentLine) *RichContent {
*m = append(*m, *v)
return m
}
type Interface interface {
SendSimpleMsg(content string) (bool, error)
SendRichMsg(title string, content RichContent) (bool, error)
}
func post(url string, body []byte) (bool, error) {
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body))
if err != nil {
return false, err
}
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
return false, err
}
resBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return false, err
}
fmt.Printf("client: response body: %s\n", resBody)
return true, nil
}
func getSimpleMsg(content string) map[string]interface{} {
return map[string]interface{}{
"msg_type": "text",
"content": map[string]string{
"text": content,
},
}
}
func getRichMsg(title string, content RichContent) map[string]interface{} {
return map[string]interface{}{
"msg_type": "post",
"content": map[string]interface{}{
"post": map[string]interface{}{
"zh_cn": map[string]interface{}{
"title": title,
"content": content,
},
},
},
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。