-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegram.go
More file actions
43 lines (31 loc) · 800 Bytes
/
telegram.go
File metadata and controls
43 lines (31 loc) · 800 Bytes
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
package main
import (
"fmt"
"os"
"strconv"
telegram "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
var telegramBot *telegram.BotAPI
func initTelegram() error {
tokenTelegram := os.Getenv("TELEGRAM_TOKEN")
var err error
telegramBot, err = telegram.NewBotAPI(tokenTelegram)
if err != nil {
return err
}
return nil
}
func sendTelegramMessage(sistema, mensagem string) error {
chatEnv := os.Getenv("TELEGRAM_CHAT")
telegramChatID, err := strconv.ParseInt(chatEnv, 10, 64)
if err != nil {
return err
}
mensagemFormatada := fmt.Sprintf("Erro no container *%s*:\n```\n%s\n```", sistema, mensagem)
msg := telegram.NewMessage(telegramChatID, mensagemFormatada)
msg.ParseMode = "Markdown"
if _, err := telegramBot.Send(msg); err != nil {
return err
}
return nil
}