Skip to content

Commit

Permalink
add di in changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidnev Nikolaj committed Aug 12, 2019
1 parent ae976b7 commit 35ee8b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 48 deletions.
59 changes: 11 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<em>A little python library for building bots for Express</em>
</p>
<p align="center">
<a href="https://travis-ci.org/ExpressApp/pybotx">
<img src="https://travis-ci.org/ExpressApp/pybotx.svg?branch=master" alt="Travis-CI">
</a>
<a href="https://github.com/ExpressApp/pybotx/blob/master/LICENSE">
<img src="https://img.shields.io/github/license/Naereen/StrapDown.js.svg" alt="License">
</a>
Expand All @@ -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.

Expand All @@ -36,10 +39,9 @@ Python 3.6+

`pybotx` use the following libraries:

* <a href="https://github.com/samuelcolvin/pydantic" target="_blank">Pydantic</a> for the data parts.
* <a href="https://github.com/kennethreitz/requests" target="_blank">Requests</a> for making synchronous calls to BotX API.
* <a href="https://github.com/aio-libs/aiohttp" target="_blank">Aiohttp</a> for making asynchronous calls to BotX API.
* <a href="https://github.com/aio-libs/aiojobs" target="_blank">Aiojobs</a> for dispatching asynchronous tasks.
* <a href="https://github.com/samuelcolvin/pydantic" target="_blank">pydantic</a> for the data parts.
* <a href="https://github.com/encode/httpx" target="_blank">httpx</a> for making HTTP calls to BotX API.
* <a href="https://github.com/Delgan/loguru" target="_blank">loguru</a> for beautiful and powerful logs.

## Installation
```bash
Expand All @@ -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())
```
<details markdown="1">
<summary>Or use <code>async def</code></summary>

```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
Expand All @@ -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())
```
</details>

* Deploy a bot on your server using uvicorn and set the url for the webhook in Express.
```bash
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ depending on different conditions defined in the handlers (to be added to future
* Added mechanism for catching exceptions.
* <b>Changed methods signatures</b>. See [api-reference](/api-reference/bots/) for details.
* Fixed `opts` shape.
* Added dependency injection system

## 0.11.3

Expand Down

0 comments on commit 35ee8b0

Please sign in to comment.