diff --git a/go.mod b/go.mod index cf37694..286ee4d 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.20 require ( github.com/go-resty/resty/v2 v2.7.0 - github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 github.com/json-iterator/go v1.1.12 + github.com/nyaruka/phonenumbers v1.1.6 golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 ) @@ -13,8 +13,6 @@ require ( github.com/golang/protobuf v1.3.2 // indirect github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/nyaruka/phonenumbers v1.1.6 // indirect - github.com/stretchr/testify v1.7.1 // indirect golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect golang.org/x/text v0.3.7 // indirect ) diff --git a/go.sum b/go.sum index 52d511f..0563ea1 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY= github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I= -github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc= -github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -21,7 +19,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 h1:pVgRXcIictcr+lBQIFeiwuwtDIs4eL21OuM9nyAADmo= golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/net v0.0.0-20211029224645-99673261e6eb h1:pirldcYWx7rx7kE5r+9WsOXPXK0+WH5+uZ7uPmJ44uM= @@ -33,6 +30,4 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/ami/ami_tool.go b/pkg/ami/ami_helper.go similarity index 100% rename from pkg/ami/ami_tool.go rename to pkg/ami/ami_helper.go diff --git a/pkg/bot/telegram/telegram_bot.go b/pkg/bot/telegram/telegram_bot.go deleted file mode 100644 index a0918a3..0000000 --- a/pkg/bot/telegram/telegram_bot.go +++ /dev/null @@ -1,135 +0,0 @@ -package telegram - -import ( - "encoding/json" - "errors" - "log" - "strings" - - telegramBot "github.com/go-telegram-bot-api/telegram-bot-api/v5" -) - -var preTelegram *telegramBot.BotAPI - -func NewBotWith(token string, chatId int64) (*telegramBot.BotAPI, error) { - t := &TelegramBot{ - Token: token, - ChatId: chatId, - DebugMode: true, - Enabled: true, - } - return t.NewBot() -} - -func NewBotWithMultiChatId(token string, chatId []int64) (*telegramBot.BotAPI, error) { - t := &TelegramBot{ - Token: token, - MultiChatId: chatId, - DebugMode: true, - Enabled: true, - } - return t.NewBot() -} - -func (t *TelegramBot) NewBot() (*telegramBot.BotAPI, error) { - - if !t.Enabled { - return &telegramBot.BotAPI{}, errors.New("Telegram Bot unavailable") - } - - if strings.EqualFold(t.Token, "") { - return &telegramBot.BotAPI{}, errors.New("Token telegram bot must be provided") - } - - if preTelegram != nil { - return preTelegram, nil - } - - bot, err := telegramBot.NewBotAPI(t.Token) - bot.Debug = t.DebugMode - preTelegram = bot - return bot, err -} - -func (t *TelegramBot) ResetBot() { - preTelegram = nil -} - -func (t *TelegramBot) ToJson(data interface{}) string { - s, ok := data.(string) - - if ok { - return s - } - - result, err := json.Marshal(data) - - if err != nil { - log.Printf(err.Error()) - return "" - } - - return string(result) -} - -// Send message as simple -// message will be sent to only one channel or group via chat id -func (t *TelegramBot) SendMessage(message interface{}) (telegramBot.Message, error) { - if t.ChatId == 0 { - return telegramBot.Message{}, errors.New("Chat Id must be provided") - } - - bot, err := t.NewBot() - if err != nil { - return telegramBot.Message{}, err - } - - content := t.ToJson(message) - _message := telegramBot.NewMessage(t.ChatId, content) - _message.ParseMode = telegramBot.ModeHTML - response, err := bot.Send(_message) - return response, err -} - -// Send message to multi chat id (group or channel) -// refer `mode` from telegram_config.go -func (t *TelegramBot) SendMessages(mode string, message interface{}) ([]telegramBot.Message, error) { - var response []telegramBot.Message - - if len(t.MultiChatId) == 0 { - return response, errors.New("Multi chat Id must be provided") - } - - bot, err := t.NewBot() - if err != nil { - log.Fatal(err) - return response, err - } - - key, ok := TelegramMessageMode[mode] - - if !ok { - key = telegramBot.ModeHTML - } - - content := t.ToJson(message) - for _, v := range t.MultiChatId { - _message := telegramBot.NewMessage(v, content) - _message.ParseMode = key - _response, err := bot.Send(_message) - - if err != nil { - log.Fatal(err) - return response, err - } - response = append(response, _response) - } - - return response, nil -} - -// Send message to multi chat id (group or channel) -// refer `mode` from telegram_config.go -func (t *TelegramBot) SendMessagesWith(message interface{}) ([]telegramBot.Message, error) { - return t.SendMessages("html", message) -} diff --git a/pkg/bot/telegram/telegram_config.go b/pkg/bot/telegram/telegram_config.go deleted file mode 100644 index 66bf333..0000000 --- a/pkg/bot/telegram/telegram_config.go +++ /dev/null @@ -1,11 +0,0 @@ -package telegram - -import telegramBot "github.com/go-telegram-bot-api/telegram-bot-api/v5" - -var ( - TelegramMessageMode map[string]string = map[string]string{ - "markdown_v1": telegramBot.ModeMarkdown, - "markdown_v2": telegramBot.ModeMarkdownV2, - "html": telegramBot.ModeHTML, - } -) diff --git a/pkg/bot/telegram/telegram_model.go b/pkg/bot/telegram/telegram_model.go deleted file mode 100644 index 5f7ff27..0000000 --- a/pkg/bot/telegram/telegram_model.go +++ /dev/null @@ -1,9 +0,0 @@ -package telegram - -type TelegramBot struct { - Enabled bool `json:"enabled"` - Token string `json:"telegram_bot_token"` - ChatId int64 `json:"telegram_chat_id"` - DebugMode bool `json:"debug_mode"` - MultiChatId []int64 `json:"multi_chat_id"` -}