Designed for personal use, not interactive. Example: notify yourself when there are changes on a website.
- register a Telegram bot, [follow the instructions] (https://core.telegram.org/bots), keep your bot token safe
- start a chat with your bot
- find your personal
chat_id
, openhttps://api.telegram.org/bot<bot_token>/getUpdates
in a browser or usingcurl
:
{
"ok":true,
"result":[
{
"update_id":59xxxxx05,
"message":
{
"message_id":xxxx,
"from":
{
"id":1xxxxxx4,
"is_bot":false,
"first_name":"John",
"last_name":"Doe",
"username":"jdoe",
"language_code":"en-US"
},
"chat":
{
----> "id":1xxxxxx4,
"first_name":"John",
"last_name":"Doe",
"username":"jdoe",
"type":"private"
},
"date":1xxxxxxxx6,
"text":"foo"
}
}]
}
Installation using pipenv
create a .env
file with the follwing contents:
TELEGRAM_BOT_NAME=<your_bot_name>
TELEGRAM_BOT_TOKEN=<your_bots_secret_token>
TELEGRAM_BOT_HANDLE=@<handle>Bot
TELEGRAM_BOT_DEFAULT_CHAT_ID=<chat_id>
$ cd SimpleTelegramBot
$ pipenv install -e .
$ pipenv install
Note: On a RaspberryPi the creation of the virtual environment may take long enough to run into a timeout. To avoid this export PIPENV_TIMEOUT=2400
before executing any pipenv
commands.
$ pipenv shell
$ python3 utils/send_message.py "foo bar"
# or
$ pipenv run python3 utils/send_message.py "foo bar"
$ pipenv run python3 utils/send_file.py test.txt
create a urls.json
file containing websites you want to be notified about:
{
"URLs": [
{
"name": "Example",
"URL": "https://www.example.com",
"diffIgnore": ["<meta name=\"date\""]
},
{
"name": "Google",
"URL": "https://www.google.com",
"diffIgnore": []
}
]
}
Note the diffIgnore
field. This can be used to ignore any changes that contain certain substrings. As in the example above, this can be useful for <meta>
tags that may change with each request.
Periodically execute:
$ pipenv run python3 utils/url_notifier.py
Cronjobs example
$ crontab -e
# EDITOR
# ...
# execute every 15 minutes
*/15 * * * * bash -lc "cd /path/to/SimpleTelegramBot && /path/to/pipenv run python3 utils/url_notifier.py >> /path/to/SimpleTelegramBot/logs/log.txt 2>&1"