This commit is contained in:
2023-07-10 18:22:21 +08:00
commit 7f0e0b8a9d
12 changed files with 691 additions and 0 deletions

40
feishu.go Normal file
View File

@@ -0,0 +1,40 @@
package main
import (
"bytes"
"encoding/json"
"log"
"net/http"
"os"
)
type FeishuMessage struct {
MsgType string `json:"msg_type"`
Content FeishuMessageContent `json:"content"`
}
type FeishuMessageContent struct {
Text string `json:"text"`
}
func sendFeishuMessage(content string) error {
messageBytes, err := json.Marshal(&FeishuMessage{
MsgType: "text",
Content: FeishuMessageContent{
Text: content,
},
})
if err != nil {
log.Println("Failed to send feishu message", err)
}
FEISHU_WEBHOOK := os.Getenv("FEISHU_WEBOOK")
if FEISHU_WEBHOOK == "" {
log.Println("FEISHU_WEBOOK environment not set")
return nil
}
http.Post(
FEISHU_WEBHOOK,
"application/json",
bytes.NewReader(messageBytes),
)
return nil
}