feat: channel email is done

This commit is contained in:
JustSong
2022-11-11 17:24:03 +08:00
parent f1d5d9c8d1
commit e1d09aa58f
15 changed files with 196 additions and 67 deletions
+1
View File
@@ -0,0 +1 @@
package channel
+18
View File
@@ -0,0 +1,18 @@
package channel
import (
"errors"
"message-pusher/common"
"message-pusher/model"
)
func SendEmailMessage(message *Message, user *model.User) error {
if user.Email == "" {
return errors.New("未配置邮箱地址")
}
subject := message.Description
if subject == "" {
subject = message.Title
}
return common.SendEmail(subject, user.Email, message.Content)
}
+1
View File
@@ -0,0 +1 @@
package channel
+39
View File
@@ -0,0 +1,39 @@
package channel
import (
"errors"
"message-pusher/model"
)
const (
TypeEmail = "email"
TypeWeChatTestAccount = "test"
TypeWeChatCorpAccount = "corp"
TypeLark = "lark"
TypeDingTalk = "ding"
TypeTelegram = "telegram"
)
type Message struct {
Title string `json:"title"`
Description string `json:"description"`
Content string `json:"content"`
URL string `json:"url"`
Channel string `json:"channel"`
Token string `json:"token"`
}
func (message *Message) Send(user *model.User) error {
switch message.Channel {
case TypeEmail:
return SendEmailMessage(message, user)
case TypeWeChatTestAccount:
case TypeWeChatCorpAccount:
case TypeLark:
case TypeDingTalk:
case TypeTelegram:
default:
return errors.New("不支持的消息通道:" + message.Channel)
}
return nil
}
+1
View File
@@ -0,0 +1 @@
package channel
+1
View File
@@ -0,0 +1 @@
package channel
+1
View File
@@ -0,0 +1 @@
package channel