diff --git a/README.md b/README.md index 01df3156..42043f1e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ A little python library for building bots for Express
+
+
+
@@ -24,7 +27,7 @@
Main features:
* Simple integration with your web apps.
- * Synchronous API as well as asynchronous.
+ * Asynchronous API with synchronous as a fallback option.
* 100% test coverage.
* 100% type annotated codebase.
@@ -36,10 +39,9 @@ Python 3.6+
`pybotx` use the following libraries:
-* Pydantic for the data parts.
-* Requests for making synchronous calls to BotX API.
-* Aiohttp for making asynchronous calls to BotX API.
-* Aiojobs for dispatching asynchronous tasks.
+* pydantic for the data parts.
+* httpx for making HTTP calls to BotX API.
+* loguru for beautiful and powerful logs.
## Installation
```bash
@@ -58,48 +60,13 @@ Let's create a simple echo bot.
* Create a file `main.py` with following content:
```Python3
-from botx import Bot, Message, Status
+from botx import Bot, CTS, Message, Status
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
from starlette.status import HTTP_202_ACCEPTED
-bot = Bot(disable_credentials=True)
-
-
-@bot.default_handler
-def echo_handler(message: Message, bot: Bot):
- bot.answer_message(message.body, message)
-
-
-app = FastAPI()
-app.add_middleware(
- CORSMiddleware,
- allow_origins=["*"],
- allow_credentials=True,
- allow_methods=["*"],
- allow_headers=["*"],
-)
-
-
-@app.get("/status", response_model=Status)
-def bot_status():
- return bot.status
-
-
-@app.post("/command", status_code=HTTP_202_ACCEPTED)
-def bot_command(message: Message):
- bot.execute_command(message.dict())
-```
-
Or use
-
-```Python3 hl_lines="1 6 10 11 23 24 28 33 34"
-from botx import AsyncBot, Message, Status
-from fastapi import FastAPI
-from starlette.middleware.cors import CORSMiddleware
-from starlette.status import HTTP_202_ACCEPTED
-
-bot = AsyncBot(disable_credentials=True)
+bot = Bot()
+bot.add_cts(CTS(host="cts.example.com", secret_key="secret"))
@bot.default_handler
@@ -116,20 +83,16 @@ app.add_middleware(
allow_headers=["*"],
)
-app.add_event_handler("startup", bot.start)
-app.add_event_handler("shutdown", bot.stop)
-
@app.get("/status", response_model=Status)
async def bot_status():
- return bot.status
+ return await bot.status()
@app.post("/command", status_code=HTTP_202_ACCEPTED)
async def bot_command(message: Message):
await bot.execute_command(message.dict())
```
-async def