-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* From #28 * Fixed api * Fixed subscription * Deleted chats table, added html templates, a handler, changed initialization * Added chat init log * Added unit files * Altered ping message * Updated messages Co-authored-by: Nikolay Eskov <[email protected]>
- Loading branch information
Showing
16 changed files
with
267 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,44 @@ | ||
package handlers | ||
|
||
import ( | ||
"log" | ||
"fmt" | ||
|
||
tele "gopkg.in/telebot.v3" | ||
"nodemon/cmd/tg_bot/internal" | ||
"nodemon/cmd/tg_bot/internal/base_messages" | ||
"nodemon/pkg/entities" | ||
"nodemon/cmd/tg_bot/internal/messages" | ||
) | ||
|
||
func InitHandlers(bot *tele.Bot, environment *internal.TelegramBotEnvironment) { | ||
bot.Handle("/hello", func(c tele.Context) error { | ||
oldChatID, err := environment.ChatStorage.FindChatID(entities.TelegramPlatform) | ||
if err != nil { | ||
log.Printf("failed to insert chat id into db: %v", err) | ||
return c.Send("An error occurred while finding the chat id in database") | ||
} | ||
if oldChatID != nil { | ||
return c.Send("Hello! I remember this chat.") | ||
} | ||
chatID := entities.ChatID(c.Chat().ID) | ||
|
||
err = environment.ChatStorage.InsertChatID(chatID, entities.TelegramPlatform) | ||
if err != nil { | ||
log.Printf("failed to insert chat id into db: %v", err) | ||
return c.Send("I failed to save this chat id") | ||
} | ||
return c.Send("Hello! This new chat has been saved for alerting.") | ||
bot.Handle("/chat", func(c tele.Context) error { | ||
return c.Send(fmt.Sprintf("I am sending alerts through %d chat id", environment.ChatID)) | ||
}) | ||
|
||
bot.Handle("/ping", func(c tele.Context) error { | ||
return c.Send("pong!") | ||
if environment.Mute { | ||
return c.Send(messages.PongText + " I am currently sleeping" + messages.SleepingMsg) | ||
} | ||
return c.Send(messages.PongText + " I am monitoring" + messages.MonitoringMsg) | ||
}) | ||
|
||
bot.Handle("/start", func(c tele.Context) error { | ||
environment.Mute = true | ||
return c.Send("Started working...") | ||
if environment.Mute { | ||
environment.Mute = false | ||
return c.Send("I had been asleep, but started monitoring now... " + messages.MonitoringMsg) | ||
} | ||
return c.Send("I had already been monitoring" + messages.MonitoringMsg) | ||
}) | ||
|
||
bot.Handle("/mute", func(c tele.Context) error { | ||
environment.Mute = false | ||
return c.Send("Say no more..") | ||
if environment.Mute { | ||
return c.Send("I had already been sleeping, continue sleeping.." + messages.SleepingMsg) | ||
} | ||
environment.Mute = true | ||
return c.Send("I had been monitoring, but going to sleep now.." + messages.SleepingMsg) | ||
}) | ||
|
||
bot.Handle("/help", func(c tele.Context) error { | ||
replyKeyboard := base_messages.HelpCommandKeyboard() | ||
return c.Send( | ||
base_messages.HelpInfoText2, | ||
&tele.SendOptions{ | ||
ParseMode: tele.ModeHTML, | ||
ReplyMarkup: &tele.ReplyMarkup{ | ||
OneTimeKeyboard: true, | ||
ResizeKeyboard: true, | ||
ReplyKeyboard: replyKeyboard, | ||
}, | ||
}) | ||
messages.HelpInfoText, | ||
&tele.SendOptions{ParseMode: tele.ModeHTML}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package messages | ||
|
||
const ( | ||
ErrorMsg = "❌" | ||
infoMsg = "ℹ️" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package messages | ||
|
||
const ( | ||
MonitoringMsg = "📡" | ||
SleepingMsg = "💤" | ||
PongMsg = "🏓" | ||
|
||
HelpInfoText = infoMsg + " This is a bot for monitoring Waves nodes. The next commands are available:\n\n" + | ||
"/ping - the command to check whether the bot is available and what his current state is\n" + | ||
"/hello - the command to make the bot <b>save this chat for alerts</b>. Needs to be done first time\n" + | ||
"/start - the command to make the bot <b>start getting alerts</b>\n" + | ||
"/mute - the command to make the bot <b>stop listening to alerts</b>" + | ||
"/help - the command to see <b>information about bot</b> and available commands" | ||
|
||
MuteText = "Say no more..." + SleepingMsg | ||
PongText = "Pong!" + PongMsg | ||
StartText = "Started monitoring..." + MonitoringMsg | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<b>Alert type:</b> {{ .AlertType}} | ||
|
||
<b>Severity:</b> {{ .Severity}} | ||
|
||
<b>Details:</b> {{ .Details}} |
Oops, something went wrong.