No project description provided
Project description
Chaban
Python chat-bot framework. Uses very much concepts from django.
Links
Current state
Under heavy development. Chaban supposed to be framework for developing bots for many platforms. Now working on telegram bots. Also this project needs to have strong CLI, which is also in development.
Installation
pip install chaban
Usage
Project structure
To bootstrap a new project, I recommend using cookiecutter.
pip install cookiecutter
For now, CLI is not developed, but I hope it will be available soon.
Now, run this command to get your chaban template:
cookiecutter gh:ibrag8998/cookiecutter-chaban
And answer to the question it asks :D.
The project looks like this:
project_slug
+-- project_slug
| +-- __init__.py
| +-- handlers.py
| +-- actions.py
| +-- text.py
+-- settings
| +-- __init__.py
| +-- base.py
| +-- dev.py
+-- requirements
| +-- base.txt
| +-- testing.txt
| +-- local.txt
+-- scripts
| +-- installdeps.sh
| +-- mkenv.sh
+-- run.py
+-- ...
Now run mkenv.sh
script to make .env
file which stores some configuration and secret keys:
cd scripts
./mkenv.sh
-
settings/
contains any settings you want, but there some required ones, likeDEBUG
. Put base settings inbase.py
and development-only ones indev.py
, the rest will be done for you. How? Readsettings/__init__.py
file. -
requirements/
contains separate requirements.base.txt
are base, project will not work without them.testing.txt
only used for tests.local.txt
contains requirements for direct developer, for example: linter, formatter. -
scripts/
contains bash scripts to manage your project. -
run.py
is a file that you will run to start up your bot. -
project_slug/
is actual core:handlers.py
contains message handlers.actions.py
contains logic that will be invoked by message handler.text.py
contains text snippet to send in messages.
Actual code
First, define a message handler in handlers.py
like this:
from chaban.handlers import CommandMH
class StartCommandMH(CommandMH):
command = 'start'
Now, when a message comes, and your handler looks like the message can be handled by it
(checked by using regex, more info in source code), the action
will be called. But wait.
We didn't define any action! Head over to actions.py
and add one:
from chaban.actions import Action
class StartCommandAction(Action):
def act(self, message: dict) -> None:
self.tbot.send_message(message['chat']['id'], 'Welcome!')
Well, action is defined, now let's link the handler with the action.
Open handlers.py
file and action attribute like this:
...
from .actions import StartCommandAction
class StartCommandMH(CommandMH):
...
action = StartCommandAction()
That's all for basics :D. Now open up your terminal and start bot:
python run.py
Write to your bot with message "/start" and see it works.
Contributing
Please, help.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file chaban-0.1.1.tar.gz
.
File metadata
- Download URL: chaban-0.1.1.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78271b9a74cbe6f5a7bbbe32dd967db57e3bb994e7be3c9e94e23b6e7a3a30b9 |
|
MD5 | 8c7bb4b32e79241555da0f9895b08876 |
|
BLAKE2b-256 | 32a48f8380ccdb7f041aa1f7323359ea5dce070a3831dfc4ca5150fba6c5b543 |
File details
Details for the file chaban-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: chaban-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26c486549470f14a525c4eaac3302c64b214965372baa8da474596785ca17f69 |
|
MD5 | 36298718bbe4c42347ef38cabd6d99eb |
|
BLAKE2b-256 | ae5f78f8f6cd50e6479352b8551334c57c9fe2bbe8bfaa5c473f44780793fed6 |