Skip to content

Commit

Permalink
pybotx 0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nsidnev committed Jan 20, 2020
1 parent 7c3da42 commit 8048619
Show file tree
Hide file tree
Showing 159 changed files with 9,211 additions and 5,867 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ cache: pip
python:
- "3.6"
- "3.7"
- "3.8"

install:
- pip install poetry
- poetry config settings.virtualenvs.create false
- poetry install
- poetry config virtualenvs.create false
- poetry install --extras tests

script:
- bash scripts/test.sh
- bash scripts/test
55 changes: 28 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
<h1 align="center">pybotx</h1>
<p align="center">
<em>A little python library for building bots for Express</em>
<em>A little python framework for building bots for eXpress messenger.</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>
<a href="https://github.com/ambv/black">
<img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code Style">
</a>
<a href="https://pypi.org/project/botx/">
<img src="https://badge.fury.io/py/botx.svg" alt="Package version">
</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>
</p>


---

# Introduction

`pybotx` is a framework for building bots for Express providing a mechanism for simple integration with your favourite web frameworks.
`pybotx` is a framework for building bots for eXpress providing a mechanism for simple
integration with your favourite web frameworks.

Main features:

* Simple integration with your web apps.
* Asynchronous API with synchronous as a fallback option.
* 100% test coverage.
* 100% type annotated codebase.


**NOTE**: *This library is under active development and its API may be unstable. Please lock the version you are using at the minor update level. For example, like this in `poetry`.*

**Note**: *This library is under active development and its API may be unstable. Please lock the version you are using at the minor update level. For example, like this in `poetry`.*
```
```toml
[tool.poetry.dependencies]
...
botx = "^0.12.0"
...
botx = "^0.13.0"
```

---

## Requirements
Expand All @@ -49,13 +51,20 @@ Python 3.6+
* <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.
* **Optional**. <a href="https://github.com/encode/starlette" target="_blank">Starlette</a> for tests.

## Installation
```bash
$ pip install botx
```

You will also need a web framework to create bots as the current BotX API only works with webhooks.
Or if you are going to write tests:

```bash
$ pip install botx[tests]
```

You will also need a web framework to create bots as the current BotX API only works with webhooks.
This documentation will use <a href="https://github.com/tiangolo/fastapi" target="_blank">FastAPI</a> for the examples bellow.
```bash
$ pip install fastapi uvicorn
Expand All @@ -66,38 +75,30 @@ $ pip install fastapi uvicorn
Let's create a simple echo bot.

* Create a file `main.py` with following content:
```Python3
from botx import Bot, CTS, Message, Status
```python3
from botx import Bot, ExpressServer, IncomingMessage, Message, Status
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
from starlette.status import HTTP_202_ACCEPTED

bot = Bot()
bot.add_cts(CTS(host="cts.example.com", secret_key="secret"))
bot = Bot(known_hosts=[ExpressServer(host="cts.example.com", secret_key="secret")])


@bot.default_handler
async def echo_handler(message: Message, bot: Bot):
@bot.default(include_in_status=False)
async def echo_handler(message: Message) -> None:
await bot.answer_message(message.body, message)


app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.add_event_handler("shutdown", bot.shutdown)


@app.get("/status", response_model=Status)
async def bot_status():
async def bot_status() -> Status:
return await bot.status()


@app.post("/command", status_code=HTTP_202_ACCEPTED)
async def bot_command(message: Message):
async def bot_command(message: IncomingMessage) -> None:
await bot.execute_command(message.dict())
```

Expand Down
128 changes: 55 additions & 73 deletions botx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,89 +1,71 @@
from loguru import logger
from pydantic import ValidationError
"""A little python framework for building bots for Express."""

from .bots import AsyncBot as Bot
from .collectors import HandlersCollector
from .dependencies import Depends
from .exceptions import (
BotXAPIException,
BotXDependencyFailure,
BotXException,
BotXValidationError,
from botx.bots import Bot
from botx.clients import AsyncClient, Client
from botx.collecting import Collector
from botx.exceptions import BotXAPIError, DependencyFailure, ServerUnknownError
from botx.models.buttons import BubbleElement, KeyboardElement
from botx.models.credentials import ExpressServer, ServerCredentials
from botx.models.enums import (
ChatTypes,
CommandTypes,
Recipients,
Statuses,
SystemEvents,
UserKinds,
)
from .models import (
CTS,
BotCredentials,
BubbleElement,
ChatCreatedData,
ChatTypeEnum,
CommandCallback,
CommandHandler,
CommandTypeEnum,
CommandUIElement,
CTSCredentials,
File,
KeyboardElement,
Mention,
MentionTypeEnum,
MentionUser,
MenuCommand,
Message,
MessageCommand,
from botx.models.errors import BotDisabledErrorData, BotDisabledResponse
from botx.models.events import ChatCreatedEvent
from botx.models.files import File
from botx.models.mentions import ChatMention, Mention, MentionTypes, UserMention
from botx.models.menu import Status
from botx.models.messages import Message, SendingMessage
from botx.models.receiving import IncomingMessage
from botx.models.sending import (
MessageMarkup,
MessageOptions,
MessageUser,
NotificationOpts,
ReplyMessage,
ResponseRecipientsEnum,
MessagePayload,
NotificationOptions,
SendingCredentials,
Status,
StatusEnum,
StatusResult,
SystemEventsEnum,
UserInChatCreated,
UserKindEnum,
UpdatePayload,
)

logger.disable("botx")
from botx.params import Depends

__all__ = (
"BotXDependencyFailure",
"Depends",
"Bot",
"HandlersCollector",
"BotXException",
"ValidationError",
"CTS",
"SystemEventsEnum",
"BotCredentials",
"ChatTypeEnum",
"CommandUIElement",
"CTSCredentials",
"AsyncClient",
"Client",
"Collector",
"BotXAPIError",
"ServerUnknownError",
"DependencyFailure",
"Depends",
"BubbleElement",
"KeyboardElement",
"ExpressServer",
"ServerCredentials",
"Statuses",
"Recipients",
"UserKinds",
"ChatTypes",
"CommandTypes",
"SystemEvents",
"BotDisabledErrorData",
"BotDisabledResponse",
"ChatCreatedEvent",
"File",
"CommandTypeEnum",
"Mention",
"MentionTypeEnum",
"MentionUser",
"MenuCommand",
"Message",
"MessageCommand",
"MessageUser",
"ChatMention",
"UserMention",
"MentionTypes",
"Status",
"StatusEnum",
"StatusResult",
"CommandHandler",
"ReplyMessage",
"BubbleElement",
"KeyboardElement",
"NotificationOpts",
"ResponseRecipientsEnum",
"CommandCallback",
"ChatCreatedData",
"UserInChatCreated",
"Message",
"SendingMessage",
"IncomingMessage",
"MessageMarkup",
"MessageOptions",
"MessagePayload",
"NotificationOptions",
"UpdatePayload",
"SendingCredentials",
"BotXAPIException",
"BotXValidationError",
"UserKindEnum",
)
Loading

0 comments on commit 8048619

Please sign in to comment.