-
Notifications
You must be signed in to change notification settings - Fork 34
/
media_type.go
115 lines (107 loc) · 4.14 KB
/
media_type.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
package notices
import "github.com/iwind/TeaGo/maps"
// 通知媒介类型
type NoticeMediaType = string
const (
NoticeMediaTypeEmail = "email"
NoticeMediaTypeWebhook = "webhook"
NoticeMediaTypeScript = "script"
NoticeMediaTypeDingTalk = "dingTalk"
NoticeMediaTypeQyWeixin = "qyWeixin"
NoticeMediaTypeQyWeixinRobot = "qyWeixinRobot"
NoticeMediaTypeAliyunSms = "aliyunSms"
NoticeMediaTypeTeaSms = "teaSms"
)
// 所有媒介
func AllNoticeMediaTypes() []maps.Map {
return []maps.Map{
{
"name": "邮件",
"code": NoticeMediaTypeEmail,
"supportsHTML": true,
"instance": new(NoticeEmailMedia),
"description": "通过邮件发送通知",
"user": "接收人邮箱地址",
},
{
"name": "Webhook",
"code": NoticeMediaTypeWebhook,
"supportsHTML": false,
"instance": new(NoticeWebhookMedia),
"description": "通过HTTP请求发送通知",
"user": "通过${NoticeUser}参数传递到URL上",
},
{
"name": "脚本",
"code": NoticeMediaTypeScript,
"supportsHTML": false,
"instance": new(NoticeScriptMedia),
"description": "通过运行脚本发送通知",
"user": "可以在脚本中使用${NoticeUser}来获取这个标识",
},
{
"name": "钉钉群机器人",
"code": NoticeMediaTypeDingTalk,
"supportsHTML": false,
"instance": new(NoticeDingTalkMedia),
"description": "通过钉钉群机器人发送通知消息,<a href=\"http://teaos.cn/doc/notices/DingTalk.md\" target=\"_blank\">相关文档»</a>",
"user": "要At(@)的群成员的手机号,多个手机号用英文逗号隔开,也可以为空",
},
{
"name": "企业微信应用",
"code": NoticeMediaTypeQyWeixin,
"supportsHTML": false,
"instance": new(NoticeQyWeixinMedia),
"description": "通过企业微信应用发送通知消息,<a href=\"http://teaos.cn/doc/notices/QyWeixin.md\" target=\"_blank\">相关文档»</a>",
"user": "接收消息的成员的用户账号,多个成员用竖线(|)分隔,如果所有成员使用@all。留空表示所有成员。<a href=\"http://teaos.cn/doc/notices/QyWeixin.md#%E7%94%A8%E6%88%B7%E8%B4%A6%E5%8F%B7\" target=\"_blank\">如何查看成员的用户账号?</a>",
},
{
"name": "企业微信群机器人",
"code": NoticeMediaTypeQyWeixinRobot,
"supportsHTML": false,
"instance": new(NoticeQyWeixinRobotMedia),
"description": "通过微信群机器人发送通知消息",
"user": "要At(@)的群成员的手机号,多个手机号用英文逗号隔开,也可以为空",
},
{
"name": "阿里云短信",
"code": NoticeMediaTypeAliyunSms,
"supportsHTML": false,
"instance": new(NoticeAliyunSmsMedia),
"description": "通过<a href=\"https://www.aliyun.com/product/sms?spm=5176.11533447.1097531.2.12055cfa6UnIix\" target=\"_blank\">阿里云短信服务</a>发送短信,<a href=\"http://teaos.cn/doc/notices/AliyunSms.md\" target=\"_blank\">相关文档»</a>",
"user": "接收消息的手机号",
},
{
"name": "TeaOS云短信",
"code": NoticeMediaTypeTeaSms,
"supportsHTML": false,
"instance": new(NoticeTeaSmsMedia),
"description": "通过<a href=\"http://cloud.teaos.cn\" target=\"_blank\">TeaOS官方</a>提供的云短信接口发送短信,<a href=\"http://teaos.cn/doc/notices/TeaSms.md\" target=\"_blank\">相关文档»</a>",
"user": "接收消息的手机号",
},
}
}
// 查找媒介类型
func FindNoticeMediaType(mediaType string) maps.Map {
for _, m := range AllNoticeMediaTypes() {
if m["code"] == mediaType {
return m
}
}
return nil
}
// 查找媒介类型名称
func FindNoticeMediaTypeName(mediaType string) string {
m := FindNoticeMediaType(mediaType)
if m == nil {
return ""
}
return m["name"].(string)
}
// 媒介接口
type NoticeMediaInterface interface {
// 发送
Send(user string, subject string, body string) (resp []byte, err error)
// 是否可以需要用户标识
RequireUser() bool
}