2022-09-10 00:45:41 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
2022-09-10 11:57:42 +00:00
|
|
|
"strconv"
|
2022-09-10 00:45:41 +00:00
|
|
|
|
|
|
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Token string `json:"token"`
|
|
|
|
ChatId int64 `json:"chat_id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func readConfig() (Config, error) {
|
|
|
|
config := Config{}
|
|
|
|
|
2022-09-10 11:57:42 +00:00
|
|
|
config.Token = os.Getenv("TELEGRAM_BOT_TOKEN")
|
2022-09-10 00:45:41 +00:00
|
|
|
|
2022-09-10 11:57:42 +00:00
|
|
|
var err error
|
|
|
|
config.ChatId, err = strconv.ParseInt(os.Getenv("TELEGRAM_CHAT_ID"), 10, 64)
|
2022-09-10 00:45:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return config, err
|
|
|
|
}
|
2022-09-10 11:57:42 +00:00
|
|
|
|
2022-09-10 00:45:41 +00:00
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
config, err := readConfig()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bot, err := tgbotapi.NewBotAPI(config.Token)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
text := "No se especificó un mensaje."
|
|
|
|
if len(os.Args) > 1 {
|
|
|
|
text = os.Args[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
for true {
|
|
|
|
msg := tgbotapi.NewMessage(config.ChatId, text)
|
|
|
|
|
|
|
|
if _, err := bot.Send(msg); err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|