This is a library for creating bots in the 1C-Connect environment
Project description
aio-connect
aio-connect — пакет предназначенный для создания ботов в среде 1С-Коннект.
За основу для написания пакета была заимствована библиотека aiogram.
Установка
Установить с помощью pip:
pip install aio-1c-connect
Использование
Пример реализации бота с использованием данного пакета: aio-connect-simple-bot
Пример создания бота:
import sys
import logging
from aiohttp import web
from config_reader import config
from aio_connect.types import HookType
from aio_connect import Bot, Dispatcher, Router, types, F
from aio_connect.webhook.aiohttp_server import SimpleRequestHandler, setup_application
SERVER_API = config.SERVER_API
# host
BASE_WEBHOOK_URL = config.BASE_WEBHOOK_URL
WEBHOOK_PATH = config.WEBHOOK_PATH
# listen
WEB_SERVER_HOST = config.WEB_SERVER_HOST
WEB_SERVER_PORT = config.WEB_SERVER_PORT
# line
LINE_ID = config.LINE_ID
bot = Bot(
api_login=config.API_LOGIN.get_secret_value(),
api_password=config.API_PASSSWORD.get_secret_value(),
line_id=LINE_ID,
base=SERVER_API
)
async def on_startup() -> None:
await bot.set_hook(type=HookType.BOT, id=LINE_ID, url=BASE_WEBHOOK_URL + WEBHOOK_PATH + LINE_ID)
router = Router()
@router.line(F.text)
async def text_handler(line: types.TypeLine) -> None:
if line.user_id == line.author_id:
await bot.send_message_line(line_id=line.line_id, user_id=line.user_id, text=line.text)
def main() -> None:
dp = Dispatcher()
dp.include_router(router)
dp.startup.register(on_startup)
app = web.Application()
webhook_requests_handler = SimpleRequestHandler(
dispatcher=dp,
bot=bot,
)
# Register webhook handler on application
webhook_requests_handler.register(app, path=WEBHOOK_PATH + LINE_ID)
# Mount dispatcher startup and shutdown hooks to aiohttp application
setup_application(app, dp, bot=bot)
# And finally start webserver
web.run_app(app, host=WEB_SERVER_HOST, port=WEB_SERVER_PORT)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
main()
Документация
Написание пакета основывалось на: Документации для разработчиков.
Лицензия
Пакет распространяется под лицензией MIT. Подробности можно узнать в файле LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aio-1c-connect-0.0.3.tar.gz
(55.6 kB
view details)
Built Distribution
File details
Details for the file aio-1c-connect-0.0.3.tar.gz
.
File metadata
- Download URL: aio-1c-connect-0.0.3.tar.gz
- Upload date:
- Size: 55.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a1d2b70b189ce8a78fc45782f74fbd6349cac065ba11d96dfdf97cdc80a3072 |
|
MD5 | d42682383b086486703b891d2025716a |
|
BLAKE2b-256 | c93881357ee9db91c38d0c5f865617ff8c112b79f76c7db64fc42f850b7b14c4 |
File details
Details for the file aio_1c_connect-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: aio_1c_connect-0.0.3-py3-none-any.whl
- Upload date:
- Size: 107.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 295d6794aa0d221ca5166cc804b7a9da943928a2f790f6f13de499442a414d0b |
|
MD5 | 5807f62bc0817e8a77c1e6df808cdd6c |
|
BLAKE2b-256 | 7a79c3d105d2b51ca5a6e73c242e5d079405e102017875118eea1c403256e00b |