Framework for creating command interfaces for control bot
Project description
Control bot actuator (cba)
Library for creating actuator modules for Control bot.
Example of a simple actuator:
from cba import Actuator
from cba.commands import HumanCallableCommandWithArgs, arguments
from cba.dispatcher import CommandsDispatcher
from cba.consumers import SSEConsumer
from cba.publishers import HTTPPublisher
ACTUATOR_NAME = "echo"
DESCRIPTION = "Echo actuator"
dispatcher = CommandsDispatcher()
publisher = HTTPPublisher(url="http://localhost:8081/inbox")
consumer = SSEConsumer(sse_url=f"http://localhost:8081/sse/{ACTUATOR_NAME}/events")
@dispatcher.register_callable_command
class EchoCmd(HumanCallableCommandWithArgs):
""" Echo command """
CMD = "echo"
ARGS = (
arguments.String("text", "Input text"),
)
async def _execute(self):
""" Your pretty business logic is here ! :) """
await self.send_message(
text=f"Your text is: '{self.text}'"
)
if __name__ == '__main__':
actuator = Actuator(
name=ACTUATOR_NAME,
dispatcher=dispatcher,
publishers=publisher,
consumer=consumer
)
actuator.run()
and in the bot we get the following logic:
Documentation
Preparing the environment
The actuator must receive commands (from the bot or from the outside world), execute business logic, and send messages to the bot with the result of the work.
Command description
Commands are the core of the library. It is in them that the business logic is described.
- Commands are described as classes.
Starting the actuator
For the actuator to work, the following objects must be launched in conjunction: Consumer, Publisher, Dispatcher. This can be done manually using the appropriate methods for each class. Or you can use the special aggregate class Actuator (see example above).
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 cba-2.0.0.tar.gz
.
File metadata
- Download URL: cba-2.0.0.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97dda175f00b0fe308b2b0b4cd2f1485f1c7d8f94fb5f1975b5ade88d70b56aa |
|
MD5 | 490ac3ed9385f265c10d1e8121bd1431 |
|
BLAKE2b-256 | c3a87e39547053e0cfa7d2d9e31826386d2fb226b361a0e9f5bd867a3e1a0864 |
File details
Details for the file cba-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: cba-2.0.0-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca12e367d05eb6263207bfd19d2eb498d67def9296d80a5090f75fe3ac64c313 |
|
MD5 | 3ebfec831013cd358197d2be3890e264 |
|
BLAKE2b-256 | f79c15802553669e4179b76990c49ab47cd0612f8601004840f778ec802c620b |