Skip to content
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

Telegram Notification Functionality Added #2

Closed
wants to merge 1 commit into from

Conversation

0xSh1v4
Copy link

@0xSh1v4 0xSh1v4 commented Feb 1, 2022

Description

The telegram notification functionality is added to the existing application. Therefore, one can setup his telegram bot and receive the message every 30 seconds regarding the status. If the appointment dates are available, then the person will receive the message along with the available dates and appointment URL.

Screenshot

telegram

Output

The next appointment for flat registration is available on the following dates 29-Mar-2022 Please use this URL to book the appointment faster: (https://service.berlin.de/terminvereinbarung/termin/tag.php?termin=1&anliegen[]=120686&dienstleisterlist=122210,122217,327316,122219,327312,122227,327314,122231,122243,327348,122252,329742,122260,329745,122262,329748,122254,329751,122271,327278,122273,327274,122277,327276,330436,122280,327294,122282,327290,122284,327292,327539,122291,327270,122285,327266,122286,327264,122296,327268,150230,329760,122301,327282,122297,327286,122294,327284,122312,329763,122314,329775,122304,327330,122311,327334,122309,327332,122281,327352,122279,329772,122276,327324,122274,327326,122267,329766,122246,327318,122251,327320,122257,327322,122208,327298,122226,327300&herkunft=http%3A%2F%2Fservice.berlin.de%2Fdienstleistung%2F120686%2F)

@nicbou
Copy link
Collaborator

nicbou commented Feb 9, 2022

This looks great! At the moment, the project is waiting for the city's approval, so I will wait before putting more effort into it.

Here are a few notes about the changes:

  • Telegram supports Markdown formatting for links. We could display a clickable text instead of a raw URL. You can also use https://allaboutberlin.com/out/appointment-anmeldung. It's redirect I used all over the website, and keep updated.
  • Since it's a script, it should take its input as command line flags (for options) and as environment variables (for credentials). This makes it easier to use the script inside a larger application.
  • Don't forget to add telegram to the requirements.txt file, or the project won't run for others.

@nicbou
Copy link
Collaborator

nicbou commented Feb 9, 2022

One more thing: there's no need to notify someone when nothing is found. The function only needs to be called if something is new.

Copy link

@inverse inverse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, minor comments 👍


Now it is possible to get notified via telegram regarding the appointment dates along with the appointment url. Just click on it and book it right away.

- Go to config directory and rename the config.bak.json to config.json
Copy link

@inverse inverse Jun 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Go to config directory and rename the config.bak.json to config.json
- Go to config directory and rename the `config.example.json` to `config.json`

This might provide more clarity about the file vs bak implying a backup


Now it is possible to get notified via telegram regarding the appointment dates along with the appointment url. Just click on it and book it right away.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Now it is possible to get notified via telegram regarding the appointment dates along with the appointment url. Just click on it and book it right away.
Now it is possible to get notified via Telegram regarding the appointment dates along with the appointment URL. Just click on it and book it right away.


- Go to config directory and rename the config.bak.json to config.json

- Add the telegram api key and the chat id in config.json
Copy link

@inverse inverse Jun 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Add the telegram api key and the chat id in config.json
- Add the Telegram API key and the chat ID in `config.json`

It might be worth describing how to obtain these too - e.g. https://github.com/inverse/termin#telegram


async def main():
global last_message
async with websockets.serve(on_connect, port=80):
while True:
last_message = look_for_appointments()
telegram_notify(last_message) # Telegram Notification
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
telegram_notify(last_message) # Telegram Notification
telegram_notify(last_message)

Comment adds little value

# Loads the Json results
available_dates = []
available_datestring = []
if not last_message['appointmentDates']: # To check if its an empty array
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @nicbou comment - we shouldn't notify on no appointments

@@ -11,7 +11,7 @@
import requests
import time
import websockets

import telegram
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be added to requirements.txt?

available_dates_str = ','.join(available_dates)
available_datestring.append(dates)
notify_str= "The next appointment for flat registration is available on the following dates "+available_dates_str+". Please use this URL to book the appointment faster: "+appointments_url
notify.sendMessage(chat_id=chat_id, text=notify_str)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What library are you using here? perhaps we could format the message with Markdown for better readability.

# Telegram Notifcation Added by Siva Rajendran

def telegram_notify(message):
with open('./config/config.json', 'r') as config_file:
Copy link

@inverse inverse Jun 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to guard against non-existing config files/invalid config and only continue when notify Bot created.

Could extract the init to another function for better readability.

@nicbou
Copy link
Collaborator

nicbou commented Jun 23, 2022

Since the tool now has permission to exist, a Telegram bot is a great idea.

But wouldn't it be more sensible to create a separate Telegram bot that listens to the websocket server? This lets people use the websocket server for other purposes, without running the Telegram bot.

@nicbou nicbou closed this Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants