Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ttagent-0.1.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ttagent-0.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

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

Hashes for ttagent-0.1.tar.gz
Algorithm Hash digest
SHA256 556009d1eee6256a63a7fcc9439ce2720eceda29a721f29b24d744b29e71292c
MD5 1930cdaaf1567b007d1d2b6a5fa3b6ec
BLAKE2b-256 7da0bd6c1cfd528912b918f23605e02940df4d1373a947c07ddfe09d2ac56d7a

See more details on using hashes here.

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

Hashes for ttagent-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 28edc9e1cb8fd36f841480a377fae276938660a704c8bf6bb03aceec780ddc27
MD5 49792d891df11b01e932f9b9870052f6
BLAKE2b-256 32c6bc1dcab1be546d2875fdb9dbd0892192036090c3688d48d257ba5b181b4e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page