🔋 A framework for building bots
$ pip install bottery
$ bottery startproject librarybot
This will create a librarybot directory in your current directory with three files inside:
librarybot/
__init__.py
patterns.py
settings.py
- The outer librarybot/ root directory is just a container for your project. Its name doesn’t matter to Bottery; you can rename it to anything you like.
- librarybot/__init__.py: An empty file that tells Python that this directory should be considered a Python package. If you’re a Python beginner, read more about packages in the official Python docs;
- librarybot/patterns.py: The Pattern declarations for this Bottery project;
- library/settings.py: Settings/configuration for this Bottery project.
We can get new messages from two different ways: defining a webhook with SSL implemented on Telegram or through polling. For now, Bottery implements the first way and because of that you need to define a valid and accessible externally hostname on settings.py:
# settings.py
HOSTNAME = 'mybot.example.com'
If you're developing or testing your bot, you can use a tunnel to expose Bottery. Services like ngrok helps a lot to do that.
Bottery register the telegram webhook url (that uses the HOSTNAME
variable on settings) and Telegram uses that url send the new messages that your bot receives.
The Bottery setup with ngrok is simple. Once it is installed, run $ ngrok http 8000
(if you need help running ngrok, check its documentation. This command will give you two urls (http
and https
) of the created tunnel. Get the hostname (full url without https://
part) and fill HOSTNAME
on settings.py
.
Now, you just need to get your bot token the fill on settings.py
:
# settings.py
PLATFORMS = {
'telegram': {
'ENGINE': 'bottery.platform.telegram',
'OPTIONS': {
'token': 'your-token-here',
}
},
}
ENGINE
: For now, only Telegram is available.
token
: A token provided by @BotFather. Do not share it!
$ bottery run --debug
Please see our contribution guide.