-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
616fb02
Add telegram notification support
sohm22 46bde55
refactor the notification workflow
sohm22 a81356b
resolve merge conflict
sohm22 3d1f96e
resolve merge conflict-1
sohm22 726e1e4
create document for telegram bot integration with covaccine-notifier
sohm22 f9aa7f4
Update README.md
sohm22 8d964f1
add sub-command for each notifier
sohm22 a2e1942
remove new line character
sohm22 454120b
send telegram notification as file if message length exceeds 4096 cha…
sohm22 a2d6d22
update README.md
sohm22 e21e3b1
address review comments
sohm22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,44 @@ | ||
# Telegram Intergration with Covaccine Notifier | ||
|
||
The way to setup telegram bot with covaccine notifier | ||
|
||
* **Step 1 : Create Telegram bot** | ||
* Conduct search for ```@Botfather``` or you can directly open the URL https://telegram.me/botfather to start conversations with BotFather. BotFather will then introduce itself and will display a START button at the bottom for the user. | ||
|
||
![bot image 1](./images/telegram-bot-creation-1.jpg) | ||
|
||
* Once you click on the START button, BotFather will provide you with all the commands that can be used for creating a new bot, as shown in the following screenshot | ||
|
||
![bot image 2](./images/telegram-bot-creation-2.jpg) | ||
|
||
* Now, click on the link /newbot from your conversation with BotFather. With this command, BotFather will ask you to choose a name for your bot. | ||
|
||
![bot image 3](./images/telegram-bot-creation-3.jpg) | ||
|
||
At this point, BotFather has created your bot and has also provided a token for your bot. This token(blurred with yellow color) can be used whilst wiring up your bot with Telegram bot APIs. | ||
|
||
|
||
* **Step 2 : Start conversation with newly created bot** | ||
|
||
* To start conversation with newly created bot click on link recevied in above message | ||
|
||
![bot image 4](./images/telegram-bot-creation-4.jpg) | ||
|
||
|
||
* Check whether username is set for your telegram account ? | ||
If not set the username. | ||
|
||
* **Step 3 : Start covaccine-notifier with following command** | ||
|
||
``` | ||
covaccine-notifier telegram --pincode 444002 --age 47 --token <telegram-token> --username <telegram-username> | ||
``` | ||
|
||
Sample Screenshot | ||
|
||
![bot image 5](./images/telegram-bot-creation-5.jpg) | ||
|
||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//Package notify has functions and types used for sending notifications on different communication channel | ||
package notify | ||
|
||
import ( | ||
"fmt" | ||
"net/smtp" | ||
) | ||
|
||
const ( | ||
smtpServerAddress = "smtp.gmail.com" | ||
smtpServerPort = "587" | ||
) | ||
|
||
type Email struct { | ||
ID string | ||
Pass string | ||
} | ||
|
||
// NewEmail returns the instance of Email | ||
func NewEmail(id, pass string) Notifier { | ||
return &Email{ | ||
ID: id, | ||
Pass: pass, | ||
} | ||
} | ||
|
||
// SendMessage takes message body and send it to the given email-id | ||
func (e *Email) SendMessage(body string) error { | ||
msg := "From: " + e.ID + "\n" + | ||
"To: " + e.ID + "\n" + | ||
"Subject: Vaccination slots are available\n\n" + | ||
"Vaccination slots are available at the following centers:\n\n" + | ||
body | ||
|
||
err := smtp.SendMail(fmt.Sprintf("%s:%s", smtpServerAddress, smtpServerPort), | ||
smtp.PlainAuth("", e.ID, e.Pass, smtpServerAddress), | ||
e.ID, []string{e.ID}, []byte(msg)) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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,7 @@ | ||
// Package notify has functions and types used for sending notifications on different communication channel | ||
package notify | ||
|
||
// Notifier can be any type that can SendMessage | ||
type Notifier interface { | ||
SendMessage(string) error | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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