-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
170 lines (153 loc) · 6.71 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package main
import (
"bytes"
fsBotAPI "github.com/electricbubble/feishu-bot-api"
"github.com/electricbubble/feishu-bot-api/md"
"log"
"os"
"strings"
)
func loadTestBot(wh *string, secretKey *string) {
*wh = os.Getenv("FS_BOT_WEBHOOK")
*secretKey = os.Getenv("FS_BOT_SECRET_KEY")
}
func main() {
webhook := "https://open.feishu.cn/open-apis/bot/v2/hook/045b07bd-xxxx-xxxx-xxxx-2b49c4af1a2b"
// 群机器人的 webhook 地址, 可以选择直接使用 👆 地址
// 也可以选择使用该地址尾部的 36位🆔
webhook = "045b07bd-xxxx-xxxx-xxxx-2b49c4af1a2b"
// 开启签名校验时使用
secretKey := "你的密钥"
loadTestBot(&webhook, &secretKey)
// 开启签名校验
bot := fsBotAPI.NewBot(webhook, fsBotAPI.WithSecretKey(secretKey))
// 如果未开启可忽略密钥 👇
// bot := fsBotAPI.NewBot(webhook)
{ // 发送普通文本消息
buf := bytes.NewBufferString("新更新提醒\n")
buf.WriteString("🤓所有人👉" + fsBotAPI.TextMentionAll() + "\n")
buf.WriteString("🤔你是谁👉" + fsBotAPI.TextMentionByOpenID("ou_c99c5f35d542efc7ee492afe11af19ef") + "\n")
err := bot.PushText(buf.String())
if err != nil {
log.Fatalln(err)
}
}
{ // 发送富文本消息
// 可同时设置 3种语言环境
err := bot.PushPost(
fsBotAPI.WithPost(fsBotAPI.LangChinese, "🇨🇳我是一个标题",
fsBotAPI.WithPostElementText("🇨🇳第一行: "),
fsBotAPI.WithPostElementLink("超链接", "https://www.feishu.cn"),
fsBotAPI.WithPostElementImage("img_7ea74629-9191-4176-998c-2e603c9c5e8g"),
fsBotAPI.WithPostElementText("\n"),
fsBotAPI.WithPostElementMentionAll(),
fsBotAPI.WithPostElementText("+"),
fsBotAPI.WithPostElementMentionByOpenID("ou_c99c5f35d542efc7ee492afe11af19ef"),
fsBotAPI.WithPostElementImage("img_ecffc3b9-8f14-400f-a014-05eca1a4310g"),
),
fsBotAPI.WithPost(fsBotAPI.LangEnglish, "🇺🇸🇬🇧 title",
fsBotAPI.WithPostElementText("🇺🇸🇬🇧 first line: "),
fsBotAPI.WithPostElementLink("link", "https://www.feishu.cn"),
fsBotAPI.WithPostElementImage("img_7ea74629-9191-4176-998c-2e603c9c5e8g"),
fsBotAPI.WithPostElementText("\n"),
fsBotAPI.WithPostElementMentionAll(),
fsBotAPI.WithPostElementText("+"),
fsBotAPI.WithPostElementMentionByOpenID("ou_c99c5f35d542efc7ee492afe11af19ef"),
fsBotAPI.WithPostElementImage("img_ecffc3b9-8f14-400f-a014-05eca1a4310g"),
),
fsBotAPI.WithPost(fsBotAPI.LangJapanese, "🇯🇵 タイトル",
fsBotAPI.WithPostElementText("🇯🇵 1行目: "),
fsBotAPI.WithPostElementLink("リンク", "https://www.feishu.cn"),
fsBotAPI.WithPostElementImage("img_7ea74629-9191-4176-998c-2e603c9c5e8g"),
fsBotAPI.WithPostElementText("\n"),
fsBotAPI.WithPostElementMentionAll(),
fsBotAPI.WithPostElementText("+"),
fsBotAPI.WithPostElementMentionByOpenID("ou_c99c5f35d542efc7ee492afe11af19ef"),
fsBotAPI.WithPostElementImage("img_ecffc3b9-8f14-400f-a014-05eca1a4310g"),
),
)
if err != nil {
log.Fatalln(err)
}
}
{ // 发送卡片消息, 可同时设置 3种语言环境
mdZhCn := `**title**
~~DEL~~
🙈 看不见的人 👉` + md.MentionByID("ou_c99c5f35d542efc7ee492afe11af19ef") + "\n" +
md.ColorGreen("这是一个绿色文本") + "\n" +
md.ColorRed("这是一个红色文本") + "\n" +
md.ColorGrey("这是一个灰色文本 ")
mdEnUs := `~~empty~~`
// 卡片消息可以设置是否允许转发,默认允许转发
// fsBotAPI.WithCardConfig(fsBotAPI.WithCardConfigEnableForward(false))
// 也可以将整个卡片作为链接点击, 同时支持多端跳转 👇
// fsBotAPI.WithCardConfig(fsBotAPI.WithCardConfigEnableForward(false), fsBotAPI.WithCardConfigCardLink(
// "https://www.feishu.cn",
// "https://zlink.toutiao.com/kG12?apk=1",
// "https://zlink.toutiao.com/h2Sw",
// "https://www.feishu.cn/download",
// ))
// 第二参数为卡片的基础配置, 默认配置可直接 nil
err := bot.PushCard(fsBotAPI.BgColorOrange, nil,
fsBotAPI.WithCard(fsBotAPI.LangChinese, "标题",
fsBotAPI.WithCardElementPlainText("文本内容"),
fsBotAPI.WithCardElementHorizontalRule(),
fsBotAPI.WithCardElementPlainText(strings.Repeat("文本内容2", 20), 2),
fsBotAPI.WithCardElementHorizontalRule(),
fsBotAPI.WithCardElementMarkdown(mdZhCn),
fsBotAPI.WithCardElementHorizontalRule(),
fsBotAPI.WithCardElementImage("img_7ea74629-9191-4176-998c-2e603c9c5e8g",
fsBotAPI.WithCardElementImageTitle(" *图片标题*", true),
fsBotAPI.WithCardElementImageHover("被发现了"),
),
fsBotAPI.WithCardElementNote(
fsBotAPI.WithCardElementPlainText("**普通文本**"),
fsBotAPI.WithCardElementImage("img_7ea74629-9191-4176-998c-2e603c9c5e8g",
fsBotAPI.WithCardElementImageTitle(" *图片标题*", true),
fsBotAPI.WithCardElementImageHover("被发现了"),
),
fsBotAPI.WithCardElementMarkdown("*test*"),
),
fsBotAPI.WithCardElementFields(
fsBotAPI.WithCardElementField(fsBotAPI.WithCardElementPlainText("列1\nv1"), true),
fsBotAPI.WithCardElementField(fsBotAPI.WithCardElementMarkdown("**列2**\nv2"), true),
fsBotAPI.WithCardElementField(fsBotAPI.WithCardElementMarkdown("~无效的信息~"), false),
),
fsBotAPI.WithCardElementActions(
fsBotAPI.WithCardElementAction(fsBotAPI.WithCardElementPlainText("入门必读"), "https://www.feishu.cn/hc/zh-CN/articles/360024881814", fsBotAPI.WithCardElementActionButton(fsBotAPI.ButtonDefault)),
fsBotAPI.WithCardElementAction(fsBotAPI.WithCardElementPlainText("快速习惯飞书️"), "https://www.feishu.cn/hc/zh-CN/categories-detail?category-id=7018450035717259265", fsBotAPI.WithCardElementActionButton(fsBotAPI.ButtonPrimary)),
fsBotAPI.WithCardElementAction(
fsBotAPI.WithCardElementMarkdown("**多端跳转下载**"), "", fsBotAPI.WithCardElementActionButton(fsBotAPI.ButtonDanger), fsBotAPI.WithCardElementActionMultiURL(
"https://www.feishu.cn",
"https://zlink.toutiao.com/kG12?apk=1",
"https://zlink.toutiao.com/h2Sw",
"https://www.feishu.cn/download",
),
),
),
fsBotAPI.WithCardElementMarkdown("*TEST*", fsBotAPI.WithCardExtraElementImage("img_7ea74629-9191-4176-998c-2e603c9c5e8g",
fsBotAPI.WithCardElementImageTitle(" *图片标题*", true),
fsBotAPI.WithCardElementImageHover("被发现了"),
)),
),
fsBotAPI.WithCard(fsBotAPI.LangEnglish, "title",
fsBotAPI.WithCardElementMarkdown(mdEnUs),
),
)
if err != nil {
log.Fatalln(err)
}
}
{ // 发送图片消息
err := bot.PushImage("img_7ea74629-9191-4176-998c-2e603c9c5e8g")
if err != nil {
log.Fatalln(err)
}
}
{ // 发送群名片
err := bot.PushShareChat("oc_f5b1a7eb27ae2c7b6adc2a74faf339ff")
if err != nil {
log.Fatalln(err)
}
}
}