File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
10
10
"github.com/deng00/go-notify/slack"
11
11
"github.com/deng00/go-notify/telegram"
12
12
"strconv"
13
+ "strings"
13
14
)
14
15
15
16
type Platform string
@@ -105,10 +106,20 @@ func (n *Notify) sendDiscordNotify(msg string) error {
105
106
}
106
107
107
108
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
+
109
119
app := telegram .New (telegram.Options {
110
- Token : n .config .Token ,
111
- Channel : _channel ,
120
+ Token : n .config .Token ,
121
+ Channel : _channel ,
122
+ ChatName : _chatName ,
112
123
})
113
124
err := app .Send (msg )
114
125
return err
Original file line number Diff line number Diff line change @@ -15,8 +15,9 @@ const (
15
15
16
16
// Options allows full configuration of the message sent to the Pushover API
17
17
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"`
20
21
// User may be either a user key or a group key.
21
22
}
22
23
@@ -47,7 +48,13 @@ func (c *client) Send(message string) error {
47
48
if message == "" {
48
49
return errors .New ("missing message" )
49
50
}
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
+
51
58
sendRes , err := c .bot .Send (msg )
52
59
if err != nil {
53
60
return err
You can’t perform that action at this time.
0 commit comments