-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add telegram notification support #33
Conversation
main.go
Outdated
@@ -13,6 +13,7 @@ import ( | |||
|
|||
var ( | |||
pinCode, state, district, email, password, date, vaccine, fee string | |||
notifier, tgApiToken, tgUsername string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's declare a interface Notifier
which implements Send()
method. We can have a separate package notifier
for this. Let's refactor the notification workflow
pkg/notify/telegram.go
Outdated
if len(body) > 4096 { | ||
log.Printf("message body too long, trimming it") | ||
body = body[:4095] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when started notifier using state and district name
I have encountered error for message greater than 4096 characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we split and send messages into 2 parts? Or send message as a file?
I think we should add subcommand for each notifier type instead of adding flags, something like -
|
address review comments
README.md
Outdated
covaccine-notifier [command] | ||
|
||
Available Commands: | ||
email Notify slots avaliability using email |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
email Notify slots avaliability using email | |
email Notify slots availability using email |
README.md
Outdated
Available Commands: | ||
email Notify slots avaliability using email | ||
help Help about any command | ||
telegram Notify slots availability using telegram |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
telegram Notify slots availability using telegram | |
telegram Notify slots availability using Telegram |
main.go
Outdated
Use: "telegram [FLAGS]", | ||
Short: "Notify slots availability using telegram", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
notifierType = NotifierType(TelegramNotifierType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to typecast, TelegramNotifierType and EmailNotifierType is already of type NotifierType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just initialize and pass notifier.Notifier
as an arg to Run from here
main.go
Outdated
EmailNotifierType NotifierType = "email" | ||
TelegramNotifierType NotifierType = "telegram" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets move this to notifier package
main.go
Outdated
func Run(args []string) error { | ||
if err := checkFlags(); err != nil { | ||
return err | ||
} | ||
if err := checkSlots(); err != nil { | ||
notifier, err := getNotifier() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can pass notify.Notifier
as a arg to Run(). We don't need getNotifier()
pkg/notify/email.go
Outdated
) | ||
|
||
type Email struct { | ||
Id string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Id string | |
ID string |
just a Go way of naming variables :)
@@ -0,0 +1,5 @@ | |||
package notify | |||
|
|||
type Notifier interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment on exported functions and types. This applies to other changes as well
pkg/notify/telegram.go
Outdated
log.Printf("Authorized on account %s", bot.Self.UserName) | ||
|
||
u := tgbotapi.NewUpdate(0) | ||
u.Timeout = 60 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please declare timeout value as const and use here
pkg/notify/telegram.go
Outdated
if len(body) > 4096 { | ||
log.Printf("message body too long, trimming it") | ||
body = body[:4095] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we split and send messages into 2 parts? Or send message as a file?
search.go
Outdated
if err := notifier.SendMessage(buf.String()); err != nil { | ||
return err | ||
} | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err := notifier.SendMessage(buf.String()); err != nil { | |
return err | |
} | |
return nil | |
return notifier.SendMessage(buf.String()) |
…racters add comment on exported functions
README.md
Outdated
``` | ||
|
||
**Note:** Gmail password won't work for 2FA enabled accounts. Follow [this](https://support.google.com/accounts/answer/185833?p=InvalidSecondFactor&visit_id=637554658548216477-2576856839&rd=1) guide to generate app token password and use it with `--password` arg | ||
|
||
**Note:** For telegram bot integration with covaccine-notifier follow [this](./docs/telegram-integration.md). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a sub heading - Integration with Telegram
--notifier-type telegram
--telegram-token --telegram-username