Get notified on telegram#
This example shows how to set-up a telegram bot. First, you need to setup things in telegram.
Create your own bot#
On Telegram, search
@ BotFather
and send him a/start
message;Type
/newbot
and BotFather will guide you through the creation of a new bot;Your bot is now ready: annotate your API token!
On Telegram, search your bot (by the username you just created), and send a
/start
message
Set-up a TeleBot
#
Now that your bot is ready, you need to store your token on your machine and link
it to codebots
. Piece of cakeā¦ ;)
Open your Terminal and type the following (remove the < > when pasting your token):
telebot set-token <paste-your-token-here>
DONE! if everything went smooth, you should be able to send messages over slack. Try it:
telebot send "ciao mamma!"
In action#
This type of bot is most useful inside scripts (for example to send a message at
some function completion). This is an example implementation (but check the
decorator
section):
from codebots.bots import TeleBot
# Create a TeleBot instance from the credentials that you have set-up before
# (if you don't know how, check the documentation page)
bot = TeleBot()
# # or create a bot an access token file ".tokens/telegram.json"
# bot = TeleBot('.tokens/telegram.json')
# Ask the bot to send a test message
bot.send_message('ciao mamma')
If you are using the command line to run your code, then you can concatenate the
telebot
at the end of your command, like this:
dir && telebot send "done!"
Here there are instructions for the several options to concatenate commands in bash, powershell and cmd