Skip to content

Commit f23545f

Browse files
raven-ruiwendeng00
authored andcommitted
add mdg type: tg channel name
1 parent d94c781 commit f23545f

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

notify.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/deng00/go-notify/slack"
1111
"github.com/deng00/go-notify/telegram"
1212
"strconv"
13+
"strings"
1314
)
1415

1516
type Platform string
@@ -105,10 +106,20 @@ func (n *Notify) sendDiscordNotify(msg string) error {
105106
}
106107

107108
func (n *Notify) sendTelegramNotify(msg string) error {
108-
_channel, _ := strconv.ParseInt(n.config.Channel, 10, 64)
109+
var _channel int64
110+
var _chatName string
111+
if strings.Contains(n.config.Channel, "@") {
112+
_channel = 0
113+
_chatName = n.config.Channel
114+
} else {
115+
_channel, _ = strconv.ParseInt(n.config.Channel, 10, 64)
116+
_chatName = ""
117+
}
118+
109119
app := telegram.New(telegram.Options{
110-
Token: n.config.Token,
111-
Channel: _channel,
120+
Token: n.config.Token,
121+
Channel: _channel,
122+
ChatName: _chatName,
112123
})
113124
err := app.Send(msg)
114125
return err

telegram/notify.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ const (
1515

1616
// Options allows full configuration of the message sent to the Pushover API
1717
type Options struct {
18-
Token string `json:"token"`
19-
Channel int64 `json:"channel"`
18+
Token string `json:"token"`
19+
Channel int64 `json:"channel"`
20+
ChatName string `json:"chat_name"`
2021
// User may be either a user key or a group key.
2122
}
2223

@@ -47,7 +48,13 @@ func (c *client) Send(message string) error {
4748
if message == "" {
4849
return errors.New("missing message")
4950
}
50-
msg := tgbotapi.NewMessage(c.opt.Channel, message)
51+
var msg tgbotapi.MessageConfig
52+
if c.opt.Channel != 0 {
53+
msg = tgbotapi.NewMessage(c.opt.Channel, message)
54+
} else {
55+
msg = tgbotapi.NewMessageToChannel(c.opt.ChatName, message)
56+
}
57+
5158
sendRes, err := c.bot.Send(msg)
5259
if err != nil {
5360
return err

0 commit comments

Comments
 (0)