📜 ⬆️ ⬇️

How to get alerts from Jupyter notebook in Telegram?

Pretty simple. We need our telegram bot, one packet and one line of code
And the result will be:


How to create a bot?


It is enough to write to the private telegram user @BotFather. He will give a list of commands that he understands, but we are interested in /newbot


It will be necessary to specify the name of the bot ("human") and its username (which will then be accessible via @). In my example, this is the "Best Bot" and "habra_test_bot".



In the answer of the bot we are interested in the link t.me/habra_test_bot and 2 lines:


Use this token to access the HTTP API:

442932741: AAGIBZeHev3I5d0S_cWszRYKMw898Ft9uac

For now, just remember that here it is, the token.


What else is missing?


We lack the telegram-send package. It is put through pip . In the console you need to run


pip install telegram-send


Collecting telegram-send
Using cached telegram_send-0.18-py2.py3-none-any.whl
Requirement already satisfied: appdirs in c: \ python \ anaconda3 \ lib \ site-packages (from telegram-send)
Requirement already satisfied: python-telegram-bot> = 5.0 in c: \ python \ anaconda3 \ lib \ site-packages (from telegram-send)
Requirement already satisfied: colorama in c: \ python \ anaconda3 \ lib \ site-packages (from telegram-send)
Requirement already satisfied: certifi in c: \ python \ anaconda3 \ lib \ site-packages (from python-telegram-bot> = 5.0-> telegram-send)
Requirement already satisfied: future> = 0.16.0 in c: \ python \ anaconda3 \ lib \ site-packages (from python-telegram-bot> = 5.0-> telegram-send)
Installing collected packages: telegram-send
Successfully installed telegram-send-0.18

Next, you need to configure the telegram-send , so that he knows where to write. To do this again in the console:


telegram-send --configure


This is where we need the token that was reported to @BotFather (it will need to be sent in response to an invitation to the console):


Talk with the BotFather on Telegram ( https://telegram.me/BotFather ), create a bot and insert the token
[35m> [0m442932741: AAGIBZeHev3I5d0S_cWszRYKMw898Ft9uac
Connected with habra_test_bot.

Please add habra_test_bot on Telegram ( https://telegram.me/habra_test_bot ) and send it the password: 43165

But the password ( 43165 ) will need to be sent in private to our bot. To do this, follow the link from the same @BotFather ( t.me/habra_test_bot ) and press START:




After that, to send a message, you need to contact Jupyter Notebook via ! to telegram-send :


')

Source: https://habr.com/ru/post/339682/


All Articles