Bot framework
Project description
TTAgent
Утилита для создания чат бота на базе SSE протокола.
Переподключается при сетевых сбоях или временного отключения сервера.
Для работы с АПИ, в т.ч. ответных постов, используется клиентская библиотека ttclient
(устанавливается как зависимость).
INSTALL
Достаточно установить библиотеку ttagent
$ pip install ttagent
CODE
Create agent.py
from ttagent import Action, Post, TTAgent
class MyAgent(TTAgent):
async def post_handler(self, post: Post) -> None:
''' Called when bot mentioned in post '''
post.user_id # int, who send post
post.user_unique_name # str, who send post
post.chat_id # int, in what chat
post.post_no # int, post number
post.team_id # int | None, if chat from team
post.text # str, post text
post.text_parsed # list[dict], parsed post text
post.attachments # list[str], guids of attached files
post.reply_no # int, if post has reply to other post (number)
post.reply_text # str, if post has reply to other post (text)
post.file_name # str, if post is file filename here
post.file_guid # str, if post is file guid here
async def action_handler(self, action: Action) -> None:
''' Called when user clicks on bot action link or button '''
action.action # str, action name
action.params # dict, params of action
action.user_id # int, who send post
action.user_unique_name # str, who send post
action.chat_id # int, in what chat
action.post_no # int, post number
action.team_id # int | None, if chat from team
RUN
SECRET given when bot created
DOMAIN of server hostname
SECRET=<...> API_HOST=<hostname> ttagent example.agent:MyAgent
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ttagent-0.1.tar.gz.
File metadata
- Download URL: ttagent-0.1.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
556009d1eee6256a63a7fcc9439ce2720eceda29a721f29b24d744b29e71292c
|
|
| MD5 |
1930cdaaf1567b007d1d2b6a5fa3b6ec
|
|
| BLAKE2b-256 |
7da0bd6c1cfd528912b918f23605e02940df4d1373a947c07ddfe09d2ac56d7a
|
File details
Details for the file ttagent-0.1-py3-none-any.whl.
File metadata
- Download URL: ttagent-0.1-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28edc9e1cb8fd36f841480a377fae276938660a704c8bf6bb03aceec780ddc27
|
|
| MD5 |
49792d891df11b01e932f9b9870052f6
|
|
| BLAKE2b-256 |
32c6bc1dcab1be546d2875fdb9dbd0892192036090c3688d48d257ba5b181b4e
|