-
Notifications
You must be signed in to change notification settings - Fork 0
/
telegram.go
53 lines (44 loc) · 1.27 KB
/
telegram.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
package notify
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"github.com/thomasfady/xsstower/models"
"github.com/thomasfady/xsstower/notify/types"
)
type TelegramNotifier struct {
Notifier
}
func (n *TelegramNotifier) CanNotify() bool {
fmt.Println(n.Config)
return n.GetConfig("token") != "" && n.GetConfig("chat_id") != ""
}
func (n *TelegramNotifier) GetBaseInformations() (infos types.NotifierInformation) {
infos.Name = "Telegram"
infos.Key = "telegram"
infos.Config = []types.NotifyConfig{
{Sensitive: false, Key: "chat_id", Text: "Chat ID"},
{Sensitive: true, Key: "token", Text: "Bot ID"},
}
return
}
func (n *TelegramNotifier) Notify(hit models.XssHit) error {
url := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", n.GetConfig("token"))
var msg string
if hit.Url == "" {
msg = fmt.Sprintf("\xF0\x9F\x94\xA5 Uncomplete Hit received!\nIP: %s\nHandler: %s/%s", hit.Ip, hit.Handler.Domain, hit.Handler.Path)
} else {
msg = fmt.Sprintf("\xF0\x9F\x94\xA5 Hit received!\nIP: %s\nUrl: %s", hit.Ip, hit.Url)
}
body, _ := json.Marshal(map[string]string{
"chat_id": n.GetConfig("chat_id"),
"text": msg,
})
_, err := http.Post(url, "application/json", bytes.NewBuffer(body))
if err != nil {
fmt.Println(err)
return err
}
return nil
}