@@ -0,0 +1,26 @@
|
||||
APP__ORIGINS=["http://locahost:3000"]
|
||||
DB__URL=postgres://user:password@localhost:5432/tgex
|
||||
|
||||
LOGGER__APP_NAME=tgex-backend
|
||||
LOGGER__APP_VERSION=0.0.0
|
||||
LOGGER__PRETTY_CONSOLE=true
|
||||
LOGGER__LEVEL=info
|
||||
|
||||
JWT__SECRET_KEY=your_secret_key_here_please_generate_a_strong_random_string
|
||||
|
||||
PARSER__URL=http://localhost:8080
|
||||
|
||||
S3__ENDPOINT_URL=http://localhost:9000
|
||||
S3__ACCESS_KEY_ID=user
|
||||
S3__SECRET_ACCESS_KEY=password
|
||||
S3__BUCKET_NAME=tgex-files
|
||||
|
||||
TELEGRAM__TOKEN=your_bot_token_here
|
||||
BACKEND__BASE_URL=http://localhost:8000
|
||||
LOGIN_URL=https://app.example.com/api/v1/auth/complete?token=
|
||||
|
||||
TELEGRAM__API_ID=123456
|
||||
TELEGRAM__API_HASH=your_api_hash_here
|
||||
TELEGRAM__SESSION_FILE=/data/tg_parser.json
|
||||
TELEGRAM__PHONE=+79999999999
|
||||
TELEGRAM__PASSWORD=
|
||||
@@ -0,0 +1,20 @@
|
||||
name: Build & Push
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
packages: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Login to GHCR
|
||||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
||||
|
||||
- name: Build and push
|
||||
run: |
|
||||
docker build -t ghcr.io/${{ github.repository }}/app:latest .
|
||||
docker push ghcr.io/${{ github.repository }}/app:latest
|
||||
@@ -0,0 +1,133 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
.vscode/
|
||||
.idea/
|
||||
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
docker-compose.yml
|
||||
.uv_cache/
|
||||
|
||||
|
||||
session.json
|
||||
tg_parser.json
|
||||
@@ -0,0 +1,416 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Project Overview
|
||||
|
||||
This is a FastAPI + Telegram Bot backend application for managing Telegram channel integrations. The project uses:
|
||||
- **FastAPI** for HTTP API endpoints
|
||||
- **aiogram** for Telegram bot functionality
|
||||
- **Tortoise ORM** (async) for database operations
|
||||
- **PostgreSQL** with asyncpg driver
|
||||
- **aerich** for database migrations
|
||||
- **uv** for Python package management
|
||||
|
||||
## Development Commands
|
||||
|
||||
### Environment Setup
|
||||
```bash
|
||||
# Install dependencies (using uv)
|
||||
uv sync
|
||||
|
||||
# Start PostgreSQL (via Docker Compose)
|
||||
docker-compose up -d
|
||||
|
||||
# Run database migrations
|
||||
make migrate-up # or: export $(cat .env | xargs) && aerich upgrade
|
||||
```
|
||||
|
||||
### Running the Application
|
||||
```bash
|
||||
# Start the FastAPI server
|
||||
uv run uvicorn src.main:app --host 0.0.0.0 --port 8000 --reload
|
||||
```
|
||||
|
||||
### Code Quality
|
||||
```bash
|
||||
# Run linter (Ruff)
|
||||
uv run ruff check .
|
||||
|
||||
# Format code
|
||||
uv run ruff format .
|
||||
|
||||
# Type checking (mypy with strict mode)
|
||||
uv run mypy .
|
||||
```
|
||||
|
||||
### Testing
|
||||
```bash
|
||||
# Run all tests
|
||||
uv run pytest
|
||||
|
||||
# Run a single test file
|
||||
uv run pytest tests/test_file.py
|
||||
|
||||
# Run a specific test
|
||||
uv run pytest tests/test_file.py::test_function_name
|
||||
```
|
||||
|
||||
### Database Migrations
|
||||
```bash
|
||||
# Create a new migration (auto-generated based on model changes)
|
||||
make migrate-create # or: source .env && aerich migrate
|
||||
|
||||
# Apply migrations
|
||||
make migrate-up # or: source .env && aerich upgrade
|
||||
|
||||
# Rollback one migration
|
||||
make migrate-down # or: source .env && aerich downgrade
|
||||
```
|
||||
|
||||
**Important Migration Workflow:**
|
||||
|
||||
1. **For simple model changes**: Let aerich auto-generate the migration:
|
||||
```bash
|
||||
source .env && aerich migrate --name "descriptive_name"
|
||||
```
|
||||
|
||||
2. **For complex refactorings** (table renames, data migration, etc.):
|
||||
- **FIRST**: Update domain models to reflect the new structure
|
||||
- **THEN**: Run `aerich migrate` to auto-generate the migration file
|
||||
- **FINALLY**: Edit the generated file to add data migration logic
|
||||
|
||||
Example workflow:
|
||||
```bash
|
||||
# 1. Update models in src/domain/
|
||||
# 2. Generate migration (will create base ALTER TABLE statements)
|
||||
source .env && aerich migrate --name "refactor_tables"
|
||||
# 3. Edit the generated file in migrations/models/ to add:
|
||||
# - Data migration SQL (INSERT ... SELECT)
|
||||
# - Proper ordering of operations
|
||||
# - Comments explaining complex logic
|
||||
```
|
||||
|
||||
3. **For custom constraints** (CHECK, custom indexes, etc.):
|
||||
```bash
|
||||
source .env && aerich migrate --name "add_check_constraint" --empty
|
||||
# Then edit and add: # ruff: noqa and # mypy: ignore-errors at the top
|
||||
```
|
||||
|
||||
**Migration Best Practices:**
|
||||
- Always test migrations on a copy of production data
|
||||
- Use transactions (`RUN_IN_TRANSACTION = True`)
|
||||
- Add comments explaining complex data transformations
|
||||
- For table renames with data migration:
|
||||
1. Rename old table to `old_*`
|
||||
2. Create new table structure
|
||||
3. Migrate data with `INSERT INTO new SELECT ... FROM old`
|
||||
4. Drop old table last
|
||||
- Include proper downgrade logic (even if it loses some data)
|
||||
|
||||
## Architecture
|
||||
|
||||
### Layered Architecture
|
||||
|
||||
The codebase follows a clean architecture pattern with clear separation of concerns:
|
||||
|
||||
1. **Domain Layer** (`src/domain/`)
|
||||
- Tortoise ORM models that represent database entities
|
||||
- All models inherit from `domain.base.TimestampedModel` which provides:
|
||||
- Auto-generated `id` (UUID primary key)
|
||||
- Timestamps: `created_at`, `updated_at`, `deleted_at`
|
||||
- Timezone-aware datetime fields
|
||||
- Use `class Meta: table = 'table_name'` for explicit table naming
|
||||
|
||||
2. **Use Case Layer** (`src/usecase/`)
|
||||
- Business logic functions organized by feature
|
||||
- Each use case is a standalone function with signature: `async def use_case_name(self: 'Usecase', ...) -> ReturnType`
|
||||
- Depends on Protocol interfaces (Database, TelegramBotWriter, JWTEncoder)
|
||||
- Use cases are assembled in the `Usecase` dataclass for dependency injection
|
||||
- **IMPORTANT RULES:**
|
||||
- Один use case отвечает за полноценный сценарий «от триггера до завершения»
|
||||
- Use case НЕ должен вызывать другие use cases (общую логику выносить в хелперы/сервисы)
|
||||
- Use case содержит ВСЮ бизнес-логику, включая управление состояниями диалога
|
||||
- Use case может отправлять сообщения пользователям через `self.telegram_bot` protocol
|
||||
- Всегда оборачивать операции БД в `async with self.database.transaction()`
|
||||
|
||||
3. **Adapter Layer** (`src/adapter/`)
|
||||
- Concrete implementations of protocol interfaces:
|
||||
- `Postgres`: Database operations (implements Database protocol)
|
||||
- `Telegram`: Telegram bot integration (implements TelegramWriter protocol)
|
||||
- `JWT`: Token encoding/decoding (implements JWTEncoder protocol)
|
||||
|
||||
4. **Controller Layer** (`src/controller/`)
|
||||
- **HTTP controllers** (`src/controller/http/`): FastAPI route handlers
|
||||
- **Telegram callbacks** (`src/controller/telegram_callback/`): Telegram event handlers
|
||||
- **ВАЖНО: Controllers - это тонкий слой роутинга**
|
||||
- Контроллер только извлекает данные из событий (HTTP request / Telegram update)
|
||||
- Валидирует базовые параметры (user exists, message not empty)
|
||||
- Вызывает соответствующий use case
|
||||
- НЕ содержит бизнес-логику
|
||||
- НЕ обращается к базе данных напрямую
|
||||
- НЕ отправляет сообщения пользователям
|
||||
- Все handlers регистрируются через декораторы на `telegram_callback_router`
|
||||
- Handlers импортируются в `__init__.py` для auto-регистрации
|
||||
|
||||
5. **DTO Layer** (`src/dto/`)
|
||||
- Pydantic models for request/response validation
|
||||
- Separate from domain models to decouple API contracts from database schema
|
||||
|
||||
### Key Architectural Patterns
|
||||
|
||||
**Dependency Injection via Protocols:**
|
||||
- Use cases depend on Protocol interfaces, not concrete implementations
|
||||
- Allows for easy testing and swapping implementations
|
||||
- See `src/usecase/__init__.py` for protocol definitions
|
||||
|
||||
**Transaction Management:**
|
||||
- Database uses context-aware transactions via `DatabaseBase.transaction()`
|
||||
- Session stored in ContextVar (`_session_ctx`) for implicit session access
|
||||
- Always use `async with database.transaction()` for database operations
|
||||
- The session is accessible via `database.session` within transaction context
|
||||
|
||||
**Shared Base Classes:**
|
||||
- `shared/datebase_base.py`: Base database class with connection pooling and migration checking
|
||||
- `shared/telegram_base.py`: Base Telegram bot class with polling lifecycle
|
||||
- `shared/logger/`: Structured logging with JSON and console formatters
|
||||
|
||||
**Configuration:**
|
||||
- All config in `src/config.py` using Pydantic Settings
|
||||
- Environment variables loaded from `.env` file
|
||||
- Nested config via double underscore: `DB__URL`, `TELEGRAM__TOKEN`
|
||||
|
||||
### Application Lifecycle
|
||||
|
||||
1. **Startup** (in `src/main.py`):
|
||||
- Logger initialized
|
||||
- Adapters instantiated (Postgres, Telegram, JWT)
|
||||
- Usecase dataclass created with adapter dependencies
|
||||
- FastAPI lifespan context:
|
||||
- Connect to database (includes migration check)
|
||||
- Start Telegram bot polling
|
||||
|
||||
2. **Request Flow**:
|
||||
- HTTP: FastAPI route → Controller → Usecase → Adapter → Database
|
||||
- Telegram: Event → Telegram callback → Usecase → Adapter → Database
|
||||
|
||||
3. **Shutdown**:
|
||||
- Stop Telegram bot polling
|
||||
- Close database connections
|
||||
|
||||
### Important Implementation Details
|
||||
|
||||
**Database Session Management:**
|
||||
- DO NOT create sessions manually
|
||||
- Use `async with database.transaction()` which handles begin/commit/rollback
|
||||
- Access session via `database.session` property within transaction context
|
||||
- Session lifecycle is managed by ContextVars for thread-safety
|
||||
|
||||
**Telegram Bot Integration:**
|
||||
- Bot runs in polling mode (not webhook)
|
||||
- Routers registered in `src/controller/telegram_callback/`
|
||||
- Base class handles graceful shutdown of polling task
|
||||
|
||||
**Authentication:**
|
||||
- JWT-based authentication for HTTP endpoints
|
||||
- Login flow: Telegram bot → Login token → JWT access token
|
||||
- Use `get_current_user` dependency for protected routes
|
||||
|
||||
**Code Style:**
|
||||
- Single quotes for strings (configured in Ruff)
|
||||
- Line length: 120 characters
|
||||
- Python 3.13+ syntax
|
||||
- Strict mypy typing enabled
|
||||
|
||||
### Telegram Bot Patterns
|
||||
|
||||
**State Management:**
|
||||
- Состояния хранятся в БД через модель `TelegramState`
|
||||
- Используется `TelegramStateEnum` для типизации состояний (не строки!)
|
||||
- Database protocol методы: `get_telegram_state()`, `set_telegram_state()`, `clear_telegram_state()`
|
||||
|
||||
**Controller Pattern (Telegram):**
|
||||
```python
|
||||
from aiogram import F
|
||||
from aiogram.filters import Command
|
||||
from aiogram.types import Message
|
||||
|
||||
@telegram_callback_router.message(Command('command_name'))
|
||||
async def cmd_handler(message: Message) -> None:
|
||||
if not message.from_user:
|
||||
log.error('Failed to get user data')
|
||||
return
|
||||
|
||||
usecase = dependencies.get_usecase()
|
||||
await usecase.some_use_case(
|
||||
telegram_id=message.from_user.id,
|
||||
chat_id=message.chat.id
|
||||
)
|
||||
```
|
||||
|
||||
**Use Case Pattern (Telegram):**
|
||||
```python
|
||||
from src import domain
|
||||
|
||||
async def some_use_case(self: 'Usecase', telegram_id: int, chat_id: int) -> None:
|
||||
async with self.database.transaction():
|
||||
# 1. Получить/проверить пользователя
|
||||
user = await self.database.get_user(telegram_id=telegram_id)
|
||||
if not user:
|
||||
await self.telegram_bot.send_message('❌ Не авторизован', chat_id=chat_id)
|
||||
return
|
||||
|
||||
# 2. Получить состояние (если нужно)
|
||||
state = await self.database.get_telegram_state(telegram_id)
|
||||
|
||||
# 3. Бизнес-логика
|
||||
# ...
|
||||
|
||||
# 4. Обновить состояние
|
||||
await self.database.set_telegram_state(
|
||||
telegram_id=telegram_id,
|
||||
state=domain.TelegramStateEnum.SOME_STATE,
|
||||
context={'key': 'value'}
|
||||
)
|
||||
|
||||
# 5. Отправить сообщение
|
||||
await self.telegram_bot.send_message('✅ Успешно', chat_id=chat_id)
|
||||
```
|
||||
|
||||
**Inline Keyboard Pattern:**
|
||||
```python
|
||||
from aiogram.types import InlineKeyboardButton
|
||||
|
||||
# В use case:
|
||||
buttons = [
|
||||
[InlineKeyboardButton(text='Кнопка', callback_data='callback_id:value')]
|
||||
for item in items
|
||||
]
|
||||
await self.telegram_bot.send_message_with_inline_keyboard(
|
||||
'Выберите опцию:', chat_id=chat_id, buttons=buttons
|
||||
)
|
||||
```
|
||||
|
||||
**Callback Query Handler:**
|
||||
```python
|
||||
@telegram_callback_router.callback_query(F.data.startswith('prefix:'))
|
||||
async def callback_handler(callback: CallbackQuery) -> None:
|
||||
if not callback.from_user or not callback.data:
|
||||
return
|
||||
|
||||
usecase = dependencies.get_usecase()
|
||||
await usecase.handle_callback(
|
||||
telegram_id=callback.from_user.id,
|
||||
chat_id=callback.message.chat.id,
|
||||
callback_data=callback.data,
|
||||
message_id=callback.message.message_id
|
||||
)
|
||||
await callback.answer() # Убрать "loading" на кнопке
|
||||
```
|
||||
|
||||
**Text Message Filters:**
|
||||
```python
|
||||
# Обрабатывать только не-команды
|
||||
@telegram_callback_router.message(F.text & ~F.text.startswith('/'))
|
||||
async def text_handler(message: Message) -> None:
|
||||
# Этот handler НЕ сработает для команд типа /start
|
||||
...
|
||||
```
|
||||
|
||||
**Важные правила для Telegram handlers:**
|
||||
- Специфичные фильтры (Command) регистрировать РАНЬШЕ общих (F.text)
|
||||
- Использовать `~F.text.startswith('/')` для исключения команд в текстовых handlers
|
||||
- Всегда проверять `message.from_user` перед использованием
|
||||
- Callback handlers должны вызывать `await callback.answer()` в конце
|
||||
- НЕ импортировать aiogram типы в usecase layer (только через TYPE_CHECKING в Protocol)
|
||||
|
||||
### Adding New Protocol Methods
|
||||
|
||||
When adding new functionality that requires protocol methods:
|
||||
|
||||
**1. Define Protocol in usecase layer (`src/usecase/__init__.py`):**
|
||||
```python
|
||||
if typing.TYPE_CHECKING:
|
||||
from aiogram.types import InlineKeyboardButton # Импорт только для типов
|
||||
|
||||
class TelegramBotWriter(typing.Protocol):
|
||||
async def send_message_with_inline_keyboard(
|
||||
self, text: str, chat_id: int, buttons: list[list['InlineKeyboardButton']]
|
||||
) -> None: ...
|
||||
```
|
||||
|
||||
**2. Implement in adapter (`src/adapter/telegram_bot.py`):**
|
||||
```python
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
class TelegramBot(TelegramBase):
|
||||
async def send_message_with_inline_keyboard(
|
||||
self, text: str, chat_id: int, buttons: list[list[InlineKeyboardButton]]
|
||||
) -> None:
|
||||
keyboard = InlineKeyboardMarkup(inline_keyboard=buttons)
|
||||
await self.bot.send_message(chat_id=chat_id, text=text, reply_markup=keyboard)
|
||||
```
|
||||
|
||||
**3. Use in use case:**
|
||||
```python
|
||||
from aiogram.types import InlineKeyboardButton # Можно импортировать в use case
|
||||
|
||||
buttons = [[InlineKeyboardButton(text='Text', callback_data='data')]]
|
||||
await self.telegram_bot.send_message_with_inline_keyboard('Message', chat_id, buttons)
|
||||
```
|
||||
|
||||
**Типизация Enum в Domain:**
|
||||
- Используйте `enum.StrEnum` для строковых enum (Python 3.11+)
|
||||
- Enum значения в lowercase с underscores
|
||||
- Используйте `fields.CharEnumField()` в Tortoise ORM
|
||||
|
||||
```python
|
||||
import enum
|
||||
from tortoise import fields
|
||||
from .base import TimestampedModel
|
||||
|
||||
class TelegramStateEnum(enum.StrEnum):
|
||||
CREATIVE_WAITING_CHANNEL = 'creative_waiting_channel'
|
||||
CREATIVE_WAITING_NAME = 'creative_waiting_name'
|
||||
|
||||
class TelegramState(TimestampedModel):
|
||||
state = fields.CharEnumField(TelegramStateEnum, max_length=26)
|
||||
|
||||
class Meta:
|
||||
table = 'telegram_state'
|
||||
```
|
||||
|
||||
**Database Constraints:**
|
||||
- Foreign keys: Use `fields.ForeignKeyField()` with `on_delete=fields.CASCADE`
|
||||
- Unique constraints: Use `unique=True` or `unique_together` in Meta
|
||||
- CHECK constraints: Cannot be defined in Tortoise models - create manual migrations
|
||||
- Indexes: Use `index=True` on fields or define in Meta
|
||||
|
||||
Example with CHECK constraint:
|
||||
```bash
|
||||
# Create empty migration
|
||||
export $(cat .env | xargs) && aerich migrate --name "add_check_constraint" --empty
|
||||
```
|
||||
|
||||
Then edit the created file:
|
||||
```python
|
||||
# migrations/models/1_xxx_add_check_constraint.py
|
||||
# ruff: noqa
|
||||
# mypy: ignore-errors
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "table_name"
|
||||
ADD CONSTRAINT "constraint_name"
|
||||
CHECK (your_condition);
|
||||
"""
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "table_name"
|
||||
DROP CONSTRAINT IF EXISTS "constraint_name";
|
||||
"""
|
||||
```
|
||||
@@ -0,0 +1,19 @@
|
||||
FROM python:3.13-slim-bookworm
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY pyproject.toml uv.lock ./
|
||||
RUN uv sync --frozen
|
||||
|
||||
COPY src ./src
|
||||
COPY shared ./shared
|
||||
COPY migrations ./migrations
|
||||
|
||||
ENV PYTHONPATH=/shared:/src
|
||||
ARG GIT_COMMIT=unknown
|
||||
ENV GIT_COMMIT=${GIT_COMMIT}
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD [".venv/bin/uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
@@ -0,0 +1,37 @@
|
||||
test:
|
||||
pytest --no-header
|
||||
|
||||
build-parser:
|
||||
docker build --platform linux/amd64 -f ./tg_parser/Dockerfile -t tg-parser:latest .
|
||||
docker save tg-parser:latest -o tg-parser-x86.tar
|
||||
|
||||
env:
|
||||
cp .env.example .env
|
||||
|
||||
run:
|
||||
uv run uvicorn src.main:app
|
||||
|
||||
up:
|
||||
GIT_COMMIT_COUNT=$$(git rev-list --count HEAD 2>/dev/null) docker compose up --build -d --force-recreate
|
||||
docker compose logs -f
|
||||
|
||||
migrate-init:
|
||||
export $$(cat .env | xargs) && aerich init-db
|
||||
|
||||
migrate-create:
|
||||
export $$(cat .env | xargs) && aerich migrate
|
||||
|
||||
migrate-up:
|
||||
export $$(cat .env | xargs) && aerich upgrade
|
||||
|
||||
down:
|
||||
docker compose down
|
||||
|
||||
clean:
|
||||
@docker rm -f $$(docker ps -aq) 2>/dev/null || true
|
||||
@docker rmi -f $$(docker images --filter "dangling=true" -q) 2>/dev/null || true
|
||||
@docker images --format "{{.Repository}}:{{.Tag}}" | grep -E "^(crm|local)" | xargs -r docker rmi -f 2>/dev/null || true
|
||||
@docker volume rm $$(docker volume ls -q) 2>/dev/null || true
|
||||
@docker network rm $$(docker network ls -q | grep -vE 'bridge|host|none') 2>/dev/null || true
|
||||
@docker system prune --volumes -f
|
||||
@echo "${GREEN}Docker очистка завершена. Базовые образы из registry сохранены.${NC}"
|
||||
@@ -0,0 +1,45 @@
|
||||
# tgex-backend
|
||||
|
||||
## Быстрый старт
|
||||
|
||||
```bash
|
||||
# Установить зависимости
|
||||
uv sync
|
||||
|
||||
# Скопировать примеры конфигов
|
||||
cp docker-compose.yml.example docker-compose.yml
|
||||
cp .env.example .env
|
||||
|
||||
# Поднять Postgres и сервисы
|
||||
make up
|
||||
|
||||
# (первый запуск) проинициализировать базу и таблицы aerich
|
||||
make migrate-init
|
||||
|
||||
# Применить актуальные миграции
|
||||
make migrate-up
|
||||
```
|
||||
|
||||
Открыть:
|
||||
- API: http://localhost:8000
|
||||
- Swagger: http://localhost:8000/docs
|
||||
|
||||
## Полезные команды
|
||||
|
||||
```bash
|
||||
make up # поднять приложение и Postgres
|
||||
make down # остановить контейнеры
|
||||
make migrate-init # однократная инициализация базы (aerich init-db)
|
||||
make migrate-up # применить миграции (aerich upgrade)
|
||||
make migrate-create # сгенерировать новую миграцию (aerich migrate)
|
||||
make test # pytest
|
||||
uv run ruff check . # линтер
|
||||
uv run mypy . # типизация
|
||||
```
|
||||
|
||||
## Архитектура
|
||||
|
||||
- FastAPI + PostgreSQL + Tortoise ORM, aiogram 3.x для бота
|
||||
- Слои: `domain` (модели/правила), `usecase` (бизнес-логика), `adapter` (БД/бот/JWT), `controller` (HTTP + Telegram), `dto`
|
||||
- Все use case оборачиваются в `self.database.transaction()` и проверяют права через `domain.WorkspacePermissions`
|
||||
- Миграции и схема БД управляются aerich (`migrations/models`)
|
||||
@@ -0,0 +1,73 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:15
|
||||
environment:
|
||||
POSTGRES_USER: "user"
|
||||
POSTGRES_PASSWORD: "password"
|
||||
POSTGRES_DB: "tgex"
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
command: server /data --console-address ":9001"
|
||||
environment:
|
||||
MINIO_ROOT_USER: "user"
|
||||
MINIO_ROOT_PASSWORD: "password"
|
||||
ports:
|
||||
- "9001:9001" # Web Console
|
||||
volumes:
|
||||
- minio_data:/data
|
||||
|
||||
backend:
|
||||
build:
|
||||
context: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
depends_on:
|
||||
- postgres
|
||||
- minio
|
||||
environment:
|
||||
DB__URL: "postgres://user:password@postgres:5432/tgex"
|
||||
S3__ENDPOINT_URL: "http://minio:9000"
|
||||
PARSER__URL: "http://tg_parser:8080"
|
||||
GIT_COMMIT_COUNT: "${GIT_COMMIT_COUNT:-}"
|
||||
env_file:
|
||||
- .env
|
||||
restart: unless-stopped
|
||||
|
||||
tg_bot:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: tg_bot/Dockerfile
|
||||
depends_on:
|
||||
- backend
|
||||
environment:
|
||||
BACKEND__BASE_URL: "http://backend:8000"
|
||||
env_file:
|
||||
- .env
|
||||
restart: unless-stopped
|
||||
|
||||
tg_parser:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: tg_parser/Dockerfile
|
||||
depends_on:
|
||||
- postgres
|
||||
environment:
|
||||
DB__URL: "postgres://user:password@postgres:5432/tgex"
|
||||
LOGGER__LEVEL: "info"
|
||||
LOGGER__PRETTY_CONSOLE: "true"
|
||||
expose:
|
||||
- 8080
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- ./tg_parser.json:/data/tg_parser.json
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
minio_data:
|
||||
@@ -0,0 +1,343 @@
|
||||
# ruff: noqa
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
CREATE TABLE IF NOT EXISTS "channel" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"telegram_id" BIGINT NOT NULL UNIQUE,
|
||||
"title" VARCHAR(255) NOT NULL,
|
||||
"username" VARCHAR(255) NOT NULL UNIQUE,
|
||||
"access_hash" BIGINT,
|
||||
"pts" INT
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_channel_telegra_414c3b" ON "channel" ("telegram_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_channel_usernam_7fd87a" ON "channel" ("username");
|
||||
CREATE TABLE IF NOT EXISTS "post" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"message_id" INT NOT NULL,
|
||||
"text" TEXT NOT NULL,
|
||||
"deleted_from_channel_at" TIMESTAMPTZ,
|
||||
"channel_id" UUID NOT NULL REFERENCES "channel" ("id") ON DELETE CASCADE,
|
||||
CONSTRAINT "uid_post_channel_0a2cba" UNIQUE ("channel_id", "message_id")
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_post_channel_197bed" ON "post" ("channel_id");
|
||||
CREATE TABLE IF NOT EXISTS "post_views_history" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"views_count" INT NOT NULL,
|
||||
"fetched_at" TIMESTAMPTZ NOT NULL,
|
||||
"post_id" UUID NOT NULL REFERENCES "post" ("id") ON DELETE CASCADE,
|
||||
CONSTRAINT "uid_post_views__post_id_c6cc9f" UNIQUE ("post_id", "fetched_at")
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_post_views__fetched_103eb5" ON "post_views_history" ("fetched_at");
|
||||
CREATE INDEX IF NOT EXISTS "idx_post_views__post_id_dfb1ca" ON "post_views_history" ("post_id");
|
||||
CREATE TABLE IF NOT EXISTS "telegram_user" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"telegram_id" BIGINT NOT NULL UNIQUE,
|
||||
"username" VARCHAR(255),
|
||||
"first_name" VARCHAR(255),
|
||||
"last_name" VARCHAR(255)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_telegram_us_telegra_3a3100" ON "telegram_user" ("telegram_id");
|
||||
CREATE TABLE IF NOT EXISTS "user" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"telegram_user_id" UUID NOT NULL UNIQUE REFERENCES "telegram_user" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_user_telegra_444a03" ON "user" ("telegram_user_id");
|
||||
CREATE TABLE IF NOT EXISTS "login_token" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"token" VARCHAR(255) NOT NULL UNIQUE,
|
||||
"expires_at" TIMESTAMPTZ NOT NULL,
|
||||
"used_at" TIMESTAMPTZ,
|
||||
"user_id" UUID NOT NULL REFERENCES "user" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_login_token_token_2582d2" ON "login_token" ("token");
|
||||
CREATE INDEX IF NOT EXISTS "idx_login_token_user_id_c85d7c" ON "login_token" ("user_id");
|
||||
CREATE TABLE IF NOT EXISTS "workspace" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"name" VARCHAR(255) NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS "project" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"status" VARCHAR(8) NOT NULL DEFAULT 'active',
|
||||
"purchase_invite_type_default" VARCHAR(10) NOT NULL DEFAULT 'approval',
|
||||
"channel_id" UUID NOT NULL REFERENCES "channel" ("id") ON DELETE CASCADE,
|
||||
"workspace_id" UUID NOT NULL REFERENCES "workspace" ("id") ON DELETE CASCADE,
|
||||
CONSTRAINT "uid_project_workspa_2f80f2" UNIQUE ("workspace_id", "channel_id")
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_project_channel_ce2466" ON "project" ("channel_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_project_workspa_2354fd" ON "project" ("workspace_id");
|
||||
COMMENT ON COLUMN "project"."status" IS 'ACTIVE: active\nINACTIVE: inactive\nARCHIVED: archived';
|
||||
COMMENT ON COLUMN "project"."purchase_invite_type_default" IS 'PUBLIC: public\nAPPROVAL: approval';
|
||||
CREATE TABLE IF NOT EXISTS "creative" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"name" VARCHAR(255) NOT NULL,
|
||||
"text" TEXT NOT NULL,
|
||||
"media_type" VARCHAR(32),
|
||||
"media_file_id" VARCHAR(512),
|
||||
"media_s3_key" VARCHAR(512),
|
||||
"buttons" JSONB NOT NULL,
|
||||
"status" VARCHAR(8) NOT NULL DEFAULT 'active',
|
||||
"project_id" UUID NOT NULL REFERENCES "project" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_creative_project_0766a6" ON "creative" ("project_id");
|
||||
COMMENT ON COLUMN "creative"."status" IS 'ACTIVE: active\nARCHIVED: archived';
|
||||
CREATE TABLE IF NOT EXISTS "purchase" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"status" VARCHAR(8) NOT NULL DEFAULT 'active',
|
||||
"placement_at" TIMESTAMPTZ,
|
||||
"payment_at" TIMESTAMPTZ,
|
||||
"cost_type" VARCHAR(8),
|
||||
"cost_value" DOUBLE PRECISION,
|
||||
"cost_before_bargain" DOUBLE PRECISION,
|
||||
"purchase_type" VARCHAR(16),
|
||||
"format" TEXT,
|
||||
"comment" TEXT,
|
||||
"creative_id" UUID NOT NULL REFERENCES "creative" ("id") ON DELETE CASCADE,
|
||||
"project_id" UUID NOT NULL REFERENCES "project" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_purchase_creativ_6829cd" ON "purchase" ("creative_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_purchase_project_95b1c2" ON "purchase" ("project_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_purchase_project_dee224" ON "purchase" ("project_id", "status");
|
||||
COMMENT ON COLUMN "purchase"."status" IS 'ACTIVE: active\nARCHIVED: archived';
|
||||
COMMENT ON COLUMN "purchase"."cost_type" IS 'FIXED: fixed\nCPM: cpm';
|
||||
COMMENT ON COLUMN "purchase"."purchase_type" IS 'SELF_PROMO: self_promo\nSTANDARD: standard';
|
||||
CREATE TABLE IF NOT EXISTS "purchase_channel" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"status" VARCHAR(11) NOT NULL DEFAULT 'planned',
|
||||
"placement_at" TIMESTAMPTZ,
|
||||
"cost_type" VARCHAR(8),
|
||||
"cost_value" DOUBLE PRECISION,
|
||||
"cost_before_bargain" DOUBLE PRECISION,
|
||||
"format" TEXT,
|
||||
"comment" TEXT,
|
||||
"invite_link" VARCHAR(512) NOT NULL,
|
||||
"invite_link_type" VARCHAR(8) NOT NULL,
|
||||
"channel_id" UUID NOT NULL REFERENCES "channel" ("id") ON DELETE CASCADE,
|
||||
"purchase_id" UUID NOT NULL REFERENCES "purchase" ("id") ON DELETE CASCADE,
|
||||
CONSTRAINT "uid_purchase_ch_purchas_f7c86e" UNIQUE ("purchase_id", "channel_id")
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_purchase_ch_channel_2b1264" ON "purchase_channel" ("channel_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_purchase_ch_purchas_1fe84a" ON "purchase_channel" ("purchase_id");
|
||||
COMMENT ON COLUMN "purchase_channel"."status" IS 'PLANNED: planned\nAPPROVED: approved\nREJECTED: rejected\nIN_PROGRESS: in_progress\nCOMPLETED: completed';
|
||||
COMMENT ON COLUMN "purchase_channel"."cost_type" IS 'FIXED: fixed\nCPM: cpm';
|
||||
COMMENT ON COLUMN "purchase_channel"."invite_link_type" IS 'PUBLIC: public\nAPPROVAL: approval';
|
||||
CREATE TABLE IF NOT EXISTS "placement" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"wanted_placement_date" TIMESTAMPTZ NOT NULL,
|
||||
"cost" DOUBLE PRECISION,
|
||||
"comment" TEXT,
|
||||
"status" VARCHAR(8) NOT NULL DEFAULT 'active',
|
||||
"creative_id" UUID NOT NULL REFERENCES "creative" ("id") ON DELETE CASCADE,
|
||||
"post_id" UUID REFERENCES "post" ("id") ON DELETE SET NULL,
|
||||
"project_id" UUID NOT NULL REFERENCES "project" ("id") ON DELETE CASCADE,
|
||||
"purchase_channel_id" UUID NOT NULL REFERENCES "purchase_channel" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_placement_creativ_32111d" ON "placement" ("creative_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_placement_post_id_e4a16e" ON "placement" ("post_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_placement_project_2c6aa4" ON "placement" ("project_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_placement_purchas_61f9e6" ON "placement" ("purchase_channel_id");
|
||||
COMMENT ON COLUMN "placement"."status" IS 'ACTIVE: active\nARCHIVED: archived';
|
||||
CREATE TABLE IF NOT EXISTS "subscription" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"invite_link" VARCHAR(512) NOT NULL,
|
||||
"status" VARCHAR(12) NOT NULL DEFAULT 'active',
|
||||
"unsubscribed_at" TIMESTAMPTZ,
|
||||
"placement_id" UUID NOT NULL REFERENCES "placement" ("id") ON DELETE CASCADE,
|
||||
"telegram_user_id" UUID NOT NULL REFERENCES "telegram_user" ("id") ON DELETE CASCADE,
|
||||
CONSTRAINT "uid_subscriptio_placeme_75b40b" UNIQUE ("placement_id", "telegram_user_id")
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_subscriptio_invite__f2058d" ON "subscription" ("invite_link");
|
||||
CREATE INDEX IF NOT EXISTS "idx_subscriptio_placeme_5decb2" ON "subscription" ("placement_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_subscriptio_telegra_8be9bb" ON "subscription" ("telegram_user_id");
|
||||
COMMENT ON COLUMN "subscription"."status" IS 'ACTIVE: active\nUNSUBSCRIBED: unsubscribed';
|
||||
CREATE TABLE IF NOT EXISTS "workspace_invite" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"status" VARCHAR(8) NOT NULL DEFAULT 'pending',
|
||||
"invited_by_id" UUID NOT NULL REFERENCES "user" ("id") ON DELETE CASCADE,
|
||||
"user_id" UUID NOT NULL REFERENCES "user" ("id") ON DELETE CASCADE,
|
||||
"workspace_id" UUID NOT NULL REFERENCES "workspace" ("id") ON DELETE CASCADE,
|
||||
CONSTRAINT "uid_workspace_i_workspa_abd9c4" UNIQUE ("workspace_id", "user_id")
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_workspace_i_invited_3ed9f8" ON "workspace_invite" ("invited_by_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_workspace_i_user_id_a96e1e" ON "workspace_invite" ("user_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_workspace_i_workspa_71e9d2" ON "workspace_invite" ("workspace_id");
|
||||
COMMENT ON COLUMN "workspace_invite"."status" IS 'PENDING: pending\nACCEPTED: accepted\nREVOKED: revoked';
|
||||
CREATE TABLE IF NOT EXISTS "workspace_user" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"status" VARCHAR(7) NOT NULL DEFAULT 'active',
|
||||
"user_id" UUID NOT NULL REFERENCES "user" ("id") ON DELETE CASCADE,
|
||||
"workspace_id" UUID NOT NULL REFERENCES "workspace" ("id") ON DELETE CASCADE,
|
||||
CONSTRAINT "uid_workspace_u_workspa_13c46c" UNIQUE ("workspace_id", "user_id")
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_workspace_u_user_id_246318" ON "workspace_user" ("user_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_workspace_u_workspa_a403b0" ON "workspace_user" ("workspace_id");
|
||||
COMMENT ON COLUMN "workspace_user"."status" IS 'ACTIVE: active\nINVITED: invited\nBLOCKED: blocked';
|
||||
CREATE TABLE IF NOT EXISTS "workspace_user_permission" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"permission" VARCHAR(24) NOT NULL,
|
||||
"workspace_user_id" UUID NOT NULL REFERENCES "workspace_user" ("id") ON DELETE CASCADE,
|
||||
CONSTRAINT "uid_workspace_u_workspa_86f574" UNIQUE ("workspace_user_id", "permission")
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_workspace_u_workspa_b9b7b0" ON "workspace_user_permission" ("workspace_user_id");
|
||||
COMMENT ON COLUMN "workspace_user_permission"."permission" IS 'ADMIN_FULL: admin_full\nPROJECTS_READ: projects_read\nPROJECTS_WRITE: projects_write\nCREATIVES_READ: creatives_read\nCREATIVES_WRITE: creatives_write\nPLACEMENTS_READ: placements_read\nPLACEMENTS_WRITE: placements_write\nANALYTICS_READ: analytics_read\nANALYTICS_WITHOUT_CLICKS: analytics_without_clicks\nCHANNELS_READ: channels_read\nCHANNELS_WRITE: channels_write';
|
||||
CREATE TABLE IF NOT EXISTS "workspace_user_permission_scope" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"permission" VARCHAR(24) NOT NULL,
|
||||
"channel_id" UUID REFERENCES "channel" ("id") ON DELETE CASCADE,
|
||||
"creative_id" UUID REFERENCES "creative" ("id") ON DELETE CASCADE,
|
||||
"placement_id" UUID REFERENCES "placement" ("id") ON DELETE CASCADE,
|
||||
"project_id" UUID REFERENCES "project" ("id") ON DELETE CASCADE,
|
||||
"workspace_user_id" UUID NOT NULL REFERENCES "workspace_user" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_workspace_u_channel_d94b48" ON "workspace_user_permission_scope" ("channel_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_workspace_u_creativ_8da562" ON "workspace_user_permission_scope" ("creative_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_workspace_u_placeme_ea1846" ON "workspace_user_permission_scope" ("placement_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_workspace_u_project_bd7fea" ON "workspace_user_permission_scope" ("project_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_workspace_u_workspa_82a35a" ON "workspace_user_permission_scope" ("workspace_user_id");
|
||||
COMMENT ON COLUMN "workspace_user_permission_scope"."permission" IS 'ADMIN_FULL: admin_full\nPROJECTS_READ: projects_read\nPROJECTS_WRITE: projects_write\nCREATIVES_READ: creatives_read\nCREATIVES_WRITE: creatives_write\nPLACEMENTS_READ: placements_read\nPLACEMENTS_WRITE: placements_write\nANALYTICS_READ: analytics_read\nANALYTICS_WITHOUT_CLICKS: analytics_without_clicks\nCHANNELS_READ: channels_read\nCHANNELS_WRITE: channels_write';
|
||||
CREATE TABLE IF NOT EXISTS "aerich" (
|
||||
"id" SERIAL NOT NULL PRIMARY KEY,
|
||||
"version" VARCHAR(255) NOT NULL,
|
||||
"app" VARCHAR(100) NOT NULL,
|
||||
"content" JSONB NOT NULL
|
||||
);"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
'eJztXWlv2zoW/SuGP/UBmSJx1lcMBrAdt/WrYxte0s5rCkGWGUcTWfLTkjQo+t+HlLWQ1G'
|
||||
'JttiX7fgkckpeSzuV2z70kf9WX2hwpxvv2k6iqSKl/qP2qq+IS4R981kmtLq5WfgZJMMWZ'
|
||||
'YpeVqEIzw9RFycTJj6JiIJw0R4akyytT1lScqlqKQhI1CReU1YWfZKnyPxYSTG2BzCek44'
|
||||
'zvP3CyrM7RT2S4/66ehUcZKXPmZeU5ebadLphvKzttOu3efrRLksfNBElTrKXql169mU+a'
|
||||
'6hW3LHn+nsiQvAVSkS6aaE59BnlL54PdpPUb4wRTt5D3qnM/YY4eRUshYNT//WipEsGgZj'
|
||||
'+J/Ln4Tz0FPJKmEmhl1SRY/Pq9/ir/m+3UOnlU+3Nz9O786g/7KzXDXOh2po1I/bctKJri'
|
||||
'WtTG1QdS0hH5bEE0g4De4hxTXqJwUFlJDty5I/re/ZEFZDfBR9lvYS7MLnzZMK3jb5gPVO'
|
||||
'XN0WAMxpPuXWc8ad4NyZcsDeMfxYaoOemQnIad+salvlurRMP9Y91vvEpqX7uTzzXyb+3v'
|
||||
'Qb/DK84rN/m7Tt5JtExNULVXQZxTjc1NdYHBJX3FWqt5RsWykqDYvSrWeXlfr3gsRtn0yk'
|
||||
'oWoFfnbXeo1oqo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JtcUo5DWLFiW6M76AWE/0igPYD2AOsYaA9QLNAeh057sDNtFu'
|
||||
'qDrWHf98Y1b++6feHjtEduipsvZVV4xOUe1OFoQC5zHgujTpPc++xEjQukh1K5X0fdSYfK'
|
||||
'ftVlEz2obSxFKBVX3J515Bfkyvv5TgV+AaeGYa/Z7tx1+v4beLckue/gl3Dfwi/i1NLsN3'
|
||||
'v/nXTbbiV4uaa8mbLk1uHnk5YzmE6Edq/b/jKmS77KWEOWKUiKLD2Te6s/k7uwe96nrW+B'
|
||||
'8r7MzXU/zM223ygLbdS4SLJb4CJ6s8AFzxyFrufSsyHHxyYloUSKOkJ6CzH0e+dGquB85m'
|
||||
'3a5BabZwNnMNvWtnnxxhtYZlsYBsAyO/gFPFhmB6pYsMzAMgPLDCyzclpme74gffMAVBpT'
|
||||
'jEHNaaJpYWPFjg+3ElxjVlXk1qNqWtwYqeNDDXgn4J3KyTuF9O0CoEx+SMq+OvTmq/SYIW'
|
||||
'szeO6cWgB6baqqqsLHLTESNL49XeZYWgTT3+XorIaLaIF+TVWFjzUNykS6N5EuS0/1EHrd'
|
||||
'yTmJI9JFv0xp+PLIe62SXmflKDAfT56T51vfZtU4u7i+uDm/uvAusfJS4qLY3XuqounxF6'
|
||||
'RHMzTh6FEiR37eGz3Kka6RAkSneDUBPDs9TQAgLhV9KzvJ40gDTTVD59m/xoN+BGHgi3BA'
|
||||
'TlX8gd/nsmSe1BTZMH+UE9YYFMlXM0yvC967u+Y3Htd2b9DiTRVSQSvdoYTFTy+//w9A8z'
|
||||
'v0'
|
||||
)
|
||||
@@ -0,0 +1,149 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
DROP INDEX IF EXISTS "idx_workspace_u_channel_d94b48";
|
||||
ALTER TABLE "workspace_user_permission_scope" DROP CONSTRAINT IF EXISTS "fk_workspac_channel_e039fdfd";
|
||||
ALTER TABLE "creative" ADD "created_by_user_id" UUID;
|
||||
COMMENT ON COLUMN "workspace_user_permission"."permission" IS 'ADMIN_FULL: admin_full
|
||||
PROJECTS_READ: projects_read
|
||||
PROJECTS_WRITE: projects_write
|
||||
CREATIVES_READ: creatives_read
|
||||
CREATIVES_WRITE: creatives_write
|
||||
PLACEMENTS_READ: placements_read
|
||||
PLACEMENTS_WRITE: placements_write
|
||||
ANALYTICS_READ: analytics_read
|
||||
ANALYTICS_WITHOUT_CLICKS: analytics_without_clicks
|
||||
ANALYTICS_OWN_CREATIVES: analytics_own_creatives';
|
||||
ALTER TABLE "workspace_user_permission_scope" DROP COLUMN "channel_id";
|
||||
COMMENT ON COLUMN "workspace_user_permission_scope"."permission" IS 'ADMIN_FULL: admin_full
|
||||
PROJECTS_READ: projects_read
|
||||
PROJECTS_WRITE: projects_write
|
||||
CREATIVES_READ: creatives_read
|
||||
CREATIVES_WRITE: creatives_write
|
||||
PLACEMENTS_READ: placements_read
|
||||
PLACEMENTS_WRITE: placements_write
|
||||
ANALYTICS_READ: analytics_read
|
||||
ANALYTICS_WITHOUT_CLICKS: analytics_without_clicks
|
||||
ANALYTICS_OWN_CREATIVES: analytics_own_creatives';
|
||||
ALTER TABLE "creative" ADD CONSTRAINT "fk_creative_user_2ed7d825" FOREIGN KEY ("created_by_user_id") REFERENCES "user" ("id") ON DELETE SET NULL;
|
||||
CREATE INDEX IF NOT EXISTS "idx_creative_created_2d9564" ON "creative" ("created_by_user_id");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "uid_creative_me_creativ_b07496" ON "creative_media" ("creative_id", "position");"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
DROP INDEX IF EXISTS "uid_creative_me_creativ_b07496";
|
||||
DROP INDEX IF EXISTS "idx_creative_created_2d9564";
|
||||
ALTER TABLE "creative" DROP CONSTRAINT IF EXISTS "fk_creative_user_2ed7d825";
|
||||
ALTER TABLE "creative" DROP COLUMN "created_by_user_id";
|
||||
COMMENT ON COLUMN "workspace_user_permission"."permission" IS 'ADMIN_FULL: admin_full
|
||||
PROJECTS_READ: projects_read
|
||||
PROJECTS_WRITE: projects_write
|
||||
CREATIVES_READ: creatives_read
|
||||
CREATIVES_WRITE: creatives_write
|
||||
PLACEMENTS_READ: placements_read
|
||||
PLACEMENTS_WRITE: placements_write
|
||||
ANALYTICS_READ: analytics_read
|
||||
ANALYTICS_WITHOUT_CLICKS: analytics_without_clicks
|
||||
CHANNELS_READ: channels_read
|
||||
CHANNELS_WRITE: channels_write';
|
||||
ALTER TABLE "workspace_user_permission_scope" ADD "channel_id" UUID;
|
||||
COMMENT ON COLUMN "workspace_user_permission_scope"."permission" IS 'ADMIN_FULL: admin_full
|
||||
PROJECTS_READ: projects_read
|
||||
PROJECTS_WRITE: projects_write
|
||||
CREATIVES_READ: creatives_read
|
||||
CREATIVES_WRITE: creatives_write
|
||||
PLACEMENTS_READ: placements_read
|
||||
PLACEMENTS_WRITE: placements_write
|
||||
ANALYTICS_READ: analytics_read
|
||||
ANALYTICS_WITHOUT_CLICKS: analytics_without_clicks
|
||||
CHANNELS_READ: channels_read
|
||||
CHANNELS_WRITE: channels_write';
|
||||
ALTER TABLE "workspace_user_permission_scope" ADD CONSTRAINT "fk_workspac_channel_e039fdfd" FOREIGN KEY ("channel_id") REFERENCES "channel" ("id") ON DELETE CASCADE;
|
||||
CREATE INDEX IF NOT EXISTS "idx_workspace_u_channel_d94b48" ON "workspace_user_permission_scope" ("channel_id");"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
"eJztXWtz2rga/isMn7ozOZ0ESMhmzpwZQmjXWwIMkLS7TcdjjEJ8Ymxqm6SZnfz3lXzBkm"
|
||||
"yDb4AN7xeaSnpl+dH1efRK/qc616dINT+2nyRNQ2r1qvJPVZPmCP/BR51UqtJi4UeQAEua"
|
||||
"qHZamUo0MS1Dki0c/CipJsJBU2TKhrKwFF3DodpSVUmgLuOE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SHBkkr7vJt+A3v3c9pAwbzjyPjc/SVrw3BVVz+Hj+"
|
||||
"hA3Y2BaGAWBjB79oBzZ2oBULbAzYGLAxYGPFYWNecRLyMM4sw2Js87BTGAIW/tW3tB98O1"
|
||||
"rknDEhKW6M1fGhBqoJqCbFVE1C+nYOUMa/1mNfHXrzZwaZIWszeN6cmgN6ud4ouyf4uCVG"
|
||||
"jMbnTa15ND86r7IiyK81iqR6tpChyE/VEH3TjTlZp2RKfprCCJaRX6yK+6EqtwqzCZUZhR"
|
||||
"bnO1W1s0azcVm/aKw+T7UKWec67H2BKlqffEFGNEUOR48ygYvL/IvLcNdIAKKbvJwAnp2e"
|
||||
"xgAQp4r+DjuJ43ivrlmhU8Wfo34vgvP6JhyQdxp+we9TRbZOKqpiWj+KCesaFMlbM1KbB9"
|
||||
"6H29Y3Htd2t3/Nr7ZJBtfJboLLf3p5/xfKHDK4"
|
||||
)
|
||||
@@ -0,0 +1,149 @@
|
||||
# ruff: noqa
|
||||
# mypy: ignore-errors
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
-- 1. Drop old constraints
|
||||
ALTER TABLE "subscription" DROP CONSTRAINT IF EXISTS "uid_subscriptio_placeme_aba67c";
|
||||
ALTER TABLE "subscription" DROP CONSTRAINT IF EXISTS "fk_subscrip_placemen_f35fb6bb";
|
||||
|
||||
-- 2. Add new column for placement_id
|
||||
ALTER TABLE "subscription" ADD COLUMN "placement_id" UUID;
|
||||
|
||||
-- 3. Populate placement_id from placement_post table
|
||||
UPDATE "subscription" s
|
||||
SET placement_id = pp.placement_id
|
||||
FROM "placement_post" pp
|
||||
WHERE s.placement_post_id = pp.id;
|
||||
|
||||
-- 4. Make NOT NULL (all subscriptions should have a placement via placement_post)
|
||||
ALTER TABLE "subscription" ALTER COLUMN "placement_id" SET NOT NULL;
|
||||
|
||||
-- 5. Add FK constraint to placement table
|
||||
ALTER TABLE "subscription" ADD CONSTRAINT "fk_subscrip_placemen_0b5d8f15"
|
||||
FOREIGN KEY ("placement_id") REFERENCES "placement" ("id") ON DELETE CASCADE;
|
||||
|
||||
-- 6. Create unique index
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "uid_subscriptio_placeme_75b40b"
|
||||
ON "subscription" ("placement_id", "telegram_user_id");
|
||||
|
||||
-- 7. Drop old column
|
||||
ALTER TABLE "subscription" DROP COLUMN "placement_post_id";
|
||||
"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
-- 1. Drop new constraints
|
||||
DROP INDEX IF EXISTS "uid_subscriptio_placeme_75b40b";
|
||||
ALTER TABLE "subscription" DROP CONSTRAINT IF EXISTS "fk_subscrip_placemen_0b5d8f15";
|
||||
|
||||
-- 2. Add back placement_post_id column
|
||||
ALTER TABLE "subscription" ADD COLUMN "placement_post_id" UUID;
|
||||
|
||||
-- 3. Populate from placement_post (best effort - takes first placement_post for the placement)
|
||||
UPDATE "subscription" s
|
||||
SET placement_post_id = pp.id
|
||||
FROM "placement_post" pp
|
||||
WHERE s.placement_id = pp.placement_id;
|
||||
|
||||
-- 4. Make NOT NULL (may fail if no matching placement_post exists)
|
||||
ALTER TABLE "subscription" ALTER COLUMN "placement_post_id" SET NOT NULL;
|
||||
|
||||
-- 5. Add FK constraint back to placement_post
|
||||
ALTER TABLE "subscription" ADD CONSTRAINT "fk_subscrip_placemen_f35fb6bb"
|
||||
FOREIGN KEY ("placement_post_id") REFERENCES "placement_post" ("id") ON DELETE CASCADE;
|
||||
|
||||
-- 6. Restore unique index
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "uid_subscriptio_placeme_aba67c"
|
||||
ON "subscription" ("placement_post_id", "telegram_user_id");
|
||||
|
||||
-- 7. Drop new column
|
||||
ALTER TABLE "subscription" DROP COLUMN "placement_id";
|
||||
"""
|
||||
|
||||
|
||||
MODELS_STATE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9qssmelQ72IpIKq75+si+Y+/FOxl4CZ"
|
||||
"wcBt12h7vjel4J1t8rc8vgpXBL4SVxcmn32t2/xnzHzQQv15Q3U5bcPLx40nL692Oh0+U7"
|
||||
"X0Z0ylcZ19DKFCRFlp4N2qb/tSes34Q20V5V/y0FiY9dNOOcumhGH7posmpR6BouuQJyeg"
|
||||
"pSHBkkr7vJd+A3f3A9pAwbziyPjc/S1rw3BVWz+Xj+hA3Y2A6GAWBjR79oBzZ2pBULbAzY"
|
||||
"GLAxYGPFYWNucRLyMMYsw2Js+7BTGAJWsK+7lRU5e0xIipvP6vRQA9UEVJNiqiYhfTsHKO"
|
||||
"Nf63GoDr39C4O+IWs7eO6cmgN6ud4oeyD4mCVGjMZ3oG9cFhbBeJ+4PIzq2Ua6LD1VQ/RN"
|
||||
"J+Zsk5IpemkKI1hGfrEq7oeqnCrMJlRmFFrs71TVa81W86px2Vx/nmodssl12P0CVbQ++Y"
|
||||
"L0aIocjh5lAheXeReX4a6RAEQneTkBrJ2fxwAQp4r+3jqJY3ivppqhU8Wfo34vgvN6JgyQ"
|
||||
"9yp+we9TWTLPKopsmD+KCesGFMlb+6Q2F7wPd+1vLK6dbv+GXW2TDG6S3QSX//Ty/i8zHy"
|
||||
"al"
|
||||
)
|
||||
@@ -0,0 +1,99 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "creative" ADD "tag" VARCHAR(10) NOT NULL DEFAULT 'testing';
|
||||
ALTER TABLE "post" ADD "published_at" TIMESTAMPTZ;
|
||||
COMMENT ON COLUMN "creative"."tag" IS 'TESTING: testing\nPRODUCTION: production';"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "post" DROP COLUMN "published_at";
|
||||
ALTER TABLE "creative" DROP COLUMN "tag";"""
|
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mkT68ORR8LK"
|
||||
"Devb1jB9yn+z75iuV8JcrcAqd7lEfj4Z9Mbzrhxkz39rpme41zpIe6Yr+O2Snjin5VRR09"
|
||||
"yj1sRSQV23x7ZN+yd+KtDJwEVg6jfrfH3DEDpwTb75XZZXBS2KVwkli5dAfd/l9Ttmdngp"
|
||||
"dr0psuCnYeTjxpOcP7Kdfrs70vE3fKVxHX0EbnBEkUnjW3zfDrgNu+idtEeZW9txQkPnbR"
|
||||
"inPqohV+6KJFq0WBa7jkCsjpKUhxZJC87ibfg9984XpIFTacaR4bn6VteW8Kqmby8fwJG7"
|
||||
"CxPQwDwMaOftEObOxIKxbYGLAxYGPAxsrDxuziJORhlFmGxdjuYac0BKxkX3erKnLmmJAU"
|
||||
"N4/V6aEGqgmoJuVUTQL6dg5Qxr/Wo6gOvfsLg54hazd49pyaA3q53ihbEHzUEiNG4yvoG5"
|
||||
"elRTDeJy6LUT27SBWFp3qAvmnFnEUpmbyTpjSCZegXq+J+qMqqwmxCZUahxfxOVeOi1Wld"
|
||||
"NS9b289TbUOiXIftL1CF65MvSA2nyMHouUzg4jLn4jLcNRKAaCWvJoAX5+cxAMSpwr+3Tu"
|
||||
"Io3qvIeuBU8edkOAjhvI4JBeS9jF/w+1wU9LOaJGr6j3LCGoEieWuP1GaD9+Gu+43Gtdcf"
|
||||
"3tCrbZLBTbKb4PKfXt7/BaQvMYA="
|
||||
)
|
||||
@@ -0,0 +1,98 @@
|
||||
# ruff: noqa
|
||||
# mypy: ignore-errors
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "placement" ADD "invite_link_created_at" TIMESTAMPTZ;"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "placement" DROP COLUMN "invite_link_created_at";"""
|
||||
|
||||
|
||||
MODEL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yqH21TNrxdLq7Gwa+8ZjuTO+gNhHtLkD1A9gB2DLIHNCzIHo"
|
||||
"cue3hX2jTSh7eEgsMC6p2bW27Af7rrk69YzpeSwj/ifA/KaDz8s9edTvhxr3NzVXO8xnky"
|
||||
"QqmrX8fctEddftUkAz0oXWxFJBXHfBOyb9u71+0C3Ax2CaN+p9u77Q3cGmy+V+bUwc3h1M"
|
||||
"LNYpfSGXT6f025rlMI3q7Jb4YkOmW410nPGd5N+W6f636Z0DlfJdxCa4MXZUl81mmb4dcB"
|
||||
"v3kS2kR9VbynFCQOu2jFibpohQddtFi1KHAPl1wBOT4FKY4MktfZ5Dvwmy9cD6nCC2eWx8"
|
||||
"ZnaRvem4KqWXw8f8IGbGwH0wCwsYPftAMbO9CGBTYGbAzYGLCx8rAxpzoJeRhjlmEztn3a"
|
||||
"KQ0BK9nX3aqKnDUnJMXNY3V8qIFqAqpJOVWTgLGdA5Txj/UoakBv/8KgZ8raDp6zpuaAXq"
|
||||
"4nyhYEH7PFiNH5CvrGZWkRjPeJy2JUzw7SJPGpHqBv2ldOopRMwc1TGsEy9ItVcT9UZTdh"
|
||||
"NqEyo9BifaeqcdZqty6bF63N56k2KVGuw84XqML1yRekhVPkYPQoEzi4zD24DA+NBCDa2a"
|
||||
"sJ4NnpaQwAca7w762TawzvVRUjcKn4czIchHBe14QB8k7BD/h9LonGSU2WdONHOWGNQJE8"
|
||||
"tUdqc8D7cNv5xuLa7Q+v2d02KeA62Ulw+S8v7/8CRabNKw=="
|
||||
)
|
||||
@@ -0,0 +1,105 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "channel" ADD "is_accessible" BOOL NOT NULL DEFAULT True;
|
||||
ALTER TABLE "placement_post" ADD "status" VARCHAR(64) NOT NULL DEFAULT 'Без статуса';
|
||||
COMMENT ON COLUMN "placement_post"."status" IS 'NO_STATUS: Без статуса\nSEND_POST: Отправить пост\nPOST_APPROVAL: Согласование поста\nWAITING_SCHEDULE: Ожидание отложки\nSCHEDULED: Запланирован\nPOST_PUBLISHED: Пост вышел\nCOMPLETED_DELETED: Размещение отработало - пост удалён\nCOMPLETED_NOT_DELETED: Размещение отработало - пост не удалён\nCHECK_DELETED_EARLY: Проверить - пост удалён раньше срока\nCHECK_NOT_PUBLISHED: Проверить - пост не вышел\nCHECK_COMPLETED: Размещение отработало';"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "channel" DROP COLUMN "is_accessible";
|
||||
ALTER TABLE "placement_post" DROP COLUMN "status";"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
"eJztXWtz2roW/SsMn3pmejoJkJBm7twZHm7LKQGGR9pzmo7HGIX4xtgc2zTNdPrfr+QHlu"
|
||||
"UHtjHYhv2FprK2LK2t117aW/5VXakLJOvvOk+CoiC5elv5VVWEFcJ/sI/eVqrCeu0+IAmG"
|
||||
"MJfNvCKVaa4bmiAaOPlRkHWEkxZIFzVpbUiqglOVjSyTRFXEGSVl6SZtFOnfDeINdYmMJ6"
|
||||
"ThB9++42RJWaCfSHf+u37mHyUkLzyVlRbk3WY6b7yuzbTZrNf9YOYkr5vzoipvVoqbe/1q"
|
||||
"PKnKNvtmIy3eERnybIkUpAkGWlDNILW0G+wkWTXGCYa2QduqLtyEBXoUNjIBo/qfx40iEg"
|
||||
"wq5pvIT+O/1QTwiKpCoJUUg2Dx67fVKrfNZmqVvKrzqTV+U7/+w2ylqhtLzXxoIlL9bQoK"
|
||||
"hmCJmri6QIoaIs3mBcMPaBc/MaQVCgbVK8mAu7BF3zl/pAHZSXBRdnuYA7MDXzpMq7gNi6"
|
||||
"Eiv9oajMB42rvjJtPW3Yi0ZKXr/8omRK0pR57UzNRXJvWNpRIVjw9r3GwLqXzpTT9VyH8r"
|
||||
"/wwHHKu4bb7pP1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N+Wd5/bBbgZ7BJG/VaHu+MGbg223ytz6uDmcGrhZr"
|
||||
"FLaQ1a/b+nvY5TCN6uya+GJDpluM9JzxnOpnyn3+t8ntA5XySsoY3Bi7IkPuu0zPDLgN+2"
|
||||
"hBZRXxTvLQWJwy4acaIuGuFBFw2WLQrcwyVnQM6PQYpDg2R1N/kB/OZz50PKcODM2rHxrb"
|
||||
"St3ZvCVLPs8ewNNrDGDjANgDV28pt2sMZOVLFgjYE1BtYYWGPFscac6iS0wxixPTZju6ed"
|
||||
"whhgBfu6W1mRs+aEpLh5pM4PNWBNgDUpJmsSMLYzgDL+tR55DejdXxj0TFm7wXPW1AzQy/"
|
||||
"RG2ZzgY7YYMTpfTt+4LCyC8T5xmQ/r2UKaJD5VA/hN+8nbKCZTcPMUhrAM/WJV3A9V2Src"
|
||||
"j6jck2ixvlNVu2w0Gzf168b281TblCjXYecLVOH85A+khZvIwehRInBxmXtxGR4aCUC0s5"
|
||||
"cTwMuLixgA4lzh31snzxi7V1WMwKXir8lwEGLzuiIMkDMFN/DbQhKNtxVZ0o3vxYQ1AkXS"
|
||||
"ag/V5oD35q71lcW10x+22d02KaCd7Ca47JeX3/8HQeRRtg=="
|
||||
)
|
||||
@@ -0,0 +1,103 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "placement" ADD "cost_before_bargain_type" VARCHAR(8);
|
||||
COMMENT ON COLUMN "placement"."cost_before_bargain_type" IS 'FIXED: fixed\nCPM: cpm';"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "placement" DROP COLUMN "cost_before_bargain_type";"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
"eJztXWtz2roW/SsMn3pmejoJkJBm7twZHm7LKQGGR9pzmo7HGIX4xtgc2zTNdPrfr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gA4lzh31snzxi7V1WMwKXir8lwEGLzuiIMkDMFN/DbQhKN"
|
||||
"txVZ0o3vxYQ1AkXSag/V5oD35q71lcW10x+22d02KaCd7Ca4/JeX3/8Ha9nRLA=="
|
||||
)
|
||||
@@ -0,0 +1,105 @@
|
||||
# ruff: noqa
|
||||
# mypy: ignore-errors
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "placement" ADD "invite_link_name" VARCHAR(32);"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "placement" DROP COLUMN "invite_link_name";"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
"eJztXWtz2roW/SsMn3pmejoJkJBm7twZHm7LKQGGR9pzmo7HGIX4xtgc2zTNdPrfr+QHlu"
|
||||
"UHfgE27C80lbRlaW299tKW9Ku6UhdI1t91ngRFQXL1tvKrqggrhP9go95WqsJ67UaQAEOY"
|
||||
"y2ZakUo01w1NEA0c/CjIOsJBC6SLmrQ2JFXBocpGlkmgKuKEkrJ0gzaK9O8G8Ya6RMYT0n"
|
||||
"DEt+84WFIW6CfSnf+un/lHCckLT2GlBfm2Gc4br2szbDbrdT+YKcnn5ryoypuV4qZevxpP"
|
||||
"qrJNvtlIi3dEhsQtkYI0wUALqhqklHaFnSCrxDjA0DZoW9SFG7BAj8JGJmBU//O4UUSCQc"
|
||||
"X8Evlp/LeaAB5RVQi0kmIQLH79tmrl1tkMrZJPdT61xm/q13+YtVR1Y6mZkSYi1d+moGAI"
|
||||
"lqiJqwukqCFSbV4w/IB2cYwhrVAwqF5JBtyFLfrO+SMNyE6Ai7LbwhyYHfjSYVrFdVgMFf"
|
||||
"nV1mAExtPeHTeZtu5GpCYrXf9XNiFqTTkSUzNDX5nQN5ZKVNw/rH6zzaTypTf9VCH/rfwz"
|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6B2U0Hv7FdaYTfsy1urcVx2ucJz2Uiv0y7k05KvpFkwz0oHSwFKFUHPHtkX1b3o23M3"
|
||||
"AT2DmM+q0Od8cN3BJs3ytzyuCmcErhJrFzaQ1a/b+nvY6TCV6uya+GJDp5uPGk5QxnU77T"
|
||||
"73U+T+iULxLW0MbgRVkSn3VaZvhlwG9rQouoL4r3loLExy4acU5dNMIPXTRYtihwDZecAT"
|
||||
"k/BikODZLX3eR78Js/Oh9Shg1n1o6Nb6Vt7d4Uppplj+dvsIE1todhAKyxk1+0gzV2oooF"
|
||||
"awysMbDGwBorjjXmFCehHcaIZViM7R52CmOAFex1t7IiZ40JSXHzSJ0fasCaAGtSTNYkoG"
|
||||
"/nAGX8az2O1aF3vzDoGbJ2g+fMqTmgl+uNskeCj1lixGh8R3rjsrAIxnvi8jisZwtpkvhU"
|
||||
"DeA37Zi3UUym4KYpDGEZ+mJV3IeqbBVmIyozEi3WO1W1y0azcVO/bmyfp9qGRLkOOy9Qhf"
|
||||
"OTP5AWbiIHo0eJwMVl7sVluGskANFOXk4ALy8uYgCIU4W/t07iGLtXVYzAqeKvyXAQYvO6"
|
||||
"IgyQMwVX8NtCEo23FVnSje/FhDUCRVJrD9XmgPfmrvWVxbXTH7bZ1TbJoJ3sJrj8p5ff/w"
|
||||
"cQREBB"
|
||||
)
|
||||
@@ -0,0 +1,120 @@
|
||||
# ruff: noqa
|
||||
# mypy: ignore-errors
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
-- Drop old constraint (replaced by stricter one)
|
||||
ALTER TABLE "channel" DROP CONSTRAINT IF EXISTS "channel_identity_required";
|
||||
|
||||
-- Add CHECK constraint: channel must have exactly one of username or invite_link
|
||||
ALTER TABLE "channel"
|
||||
ADD CONSTRAINT "check_channel_username_xor_invite_link"
|
||||
CHECK (
|
||||
(username IS NOT NULL AND invite_link IS NULL) OR
|
||||
(username IS NULL AND invite_link IS NOT NULL)
|
||||
);
|
||||
|
||||
COMMENT ON CONSTRAINT "check_channel_username_xor_invite_link" ON "channel"
|
||||
IS 'Ensures channel has exactly one identifier: username OR invite_link (not both, not neither)';
|
||||
"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "channel"
|
||||
DROP CONSTRAINT IF EXISTS "check_channel_username_xor_invite_link";
|
||||
"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
"eJztXWtz2roW/SsMn3pmejoJkJBm7twZHm7LKQGGR9pzmo7HGIX4xtgc2zTNdPrfr+QHlu"
|
||||
"UHfgE27C80lbRlaW299tKW9Ku6UhdI1t91ngRFQXL1tvKrqggrhP9go95WqsJ67UaQAEOY"
|
||||
"y2ZakUo01w1NEA0c/CjIOsJBC6SLmrQ2JFXBocpGlkmgKuKEkrJ0gzaK9O8G8Ya6RMYT0n"
|
||||
"DEt+84WFIW6CfSnf+un/lHCckLT2GlBfm2Gc4br2szbDbrdT+YKcnn5ryoypuV4qZevxpP"
|
||||
"qrJNvtlIi3dEhsQtkYI0wUALqhqklHaFnSCrxDjA0DZoW9SFG7BAj8JGJmBU//O4UUSCQc"
|
||||
"X8Evlp/LeaAB5RVQi0kmIQLH79tmrl1tkMrZJPdT61xm/q13+YtVR1Y6mZkSYi1d+moGAI"
|
||||
"lqiJqwukqCFSbV4w/IB2cYwhrVAwqF5JBtyFLfrO+SMNyE6Ai7LbwhyYHfjSYVrFdVgMFf"
|
||||
"nV1mAExtPeHTeZtu5GpCYrXf9XNiFqTTkSUzNDX5nQN5ZKVNw/rH6zzaTypTf9VCH/rfwz"
|
||||
"HHCs4rbppv9USZmEjaHyivrCCwuqsTmhDjA4pavYzXqRUrFeSVDsURVrF97VKx6LUTq9ei"
|
||||
"Vz0Ktd2gOqtSRqdKod2UENrI6lJqz4oLmsLS17ihGsR0aQUSSGaj8TWsYOuSRf+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U77T"
|
||||
"73U+T+iULxLW0MbgRVkSn3VaZvhlwG9rQouoL4r3loLExy4acU5dNMIPXTRYtihwDZecAT"
|
||||
"k/BikODZLX3eR78Js/Oh9Shg1n1o6Nb6Vt7d4Uppplj+dvsIE1todhAKyxk1+0gzV2oooF"
|
||||
"awysMbDGwBorjjXmFCehHcaIZViM7R52CmOAFex1t7IiZ40JSXHzSJ0fasCaAGtSTNYkoG"
|
||||
"/nAGX8az2O1aF3vzDoGbJ2g+fMqTmgl+uNskeCj1lixGh8R3rjsrAIxnvi8jisZwtpkvhU"
|
||||
"DeA37Zi3UUym4KYpDGEZ+mJV3IeqbBVmIyozEi3WO1W1y0azcVO/bmyfp9qGRLkOOy9Qhf"
|
||||
"OTP5AWbiIHo0eJwMVl7sVluGskANFOXk4ALy8uYgCIU4W/t07iGLtXVYzAqeKvyXAQYvO6"
|
||||
"IgyQMwVX8NtCEo23FVnSje/FhDUCRVJrD9XmgPfmrvWVxbXTH7bZ1TbJoJ3sJrj8p5ff/w"
|
||||
"cQREBB"
|
||||
)
|
||||
@@ -0,0 +1,165 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "placement" ADD "feed_time_minutes" INT;
|
||||
ALTER TABLE "placement" ADD "top_time_minutes" INT;
|
||||
|
||||
-- Migrate known patterns: "X / Y" where X is top hours, Y is feed hours
|
||||
-- Pattern: "1 / 24", "1/24"
|
||||
UPDATE "placement" SET top_time_minutes = 60, feed_time_minutes = 1440
|
||||
WHERE format IS NOT NULL AND lower(trim(format)) ~ '^1\\s*/\\s*24$';
|
||||
|
||||
-- Pattern: "1 / 36", "1/36"
|
||||
UPDATE "placement" SET top_time_minutes = 60, feed_time_minutes = 2160
|
||||
WHERE format IS NOT NULL AND lower(trim(format)) ~ '^1\\s*/\\s*36$';
|
||||
|
||||
-- Pattern: "1 / 48", "1/48"
|
||||
UPDATE "placement" SET top_time_minutes = 60, feed_time_minutes = 2880
|
||||
WHERE format IS NOT NULL AND lower(trim(format)) ~ '^1\\s*/\\s*48$';
|
||||
|
||||
-- Pattern: "1 / 72", "1/72"
|
||||
UPDATE "placement" SET top_time_minutes = 60, feed_time_minutes = 4320
|
||||
WHERE format IS NOT NULL AND lower(trim(format)) ~ '^1\\s*/\\s*72$';
|
||||
|
||||
-- Pattern: "2 / 24", "2/24"
|
||||
UPDATE "placement" SET top_time_minutes = 120, feed_time_minutes = 1440
|
||||
WHERE format IS NOT NULL AND lower(trim(format)) ~ '^2\\s*/\\s*24$';
|
||||
|
||||
-- Pattern: "2 / 36", "2/36"
|
||||
UPDATE "placement" SET top_time_minutes = 120, feed_time_minutes = 2160
|
||||
WHERE format IS NOT NULL AND lower(trim(format)) ~ '^2\\s*/\\s*36$';
|
||||
|
||||
-- Pattern: "2 / 48", "2/48"
|
||||
UPDATE "placement" SET top_time_minutes = 120, feed_time_minutes = 2880
|
||||
WHERE format IS NOT NULL AND lower(trim(format)) ~ '^2\\s*/\\s*48$';
|
||||
|
||||
-- Pattern: "2 / 72", "2/72"
|
||||
UPDATE "placement" SET top_time_minutes = 120, feed_time_minutes = 4320
|
||||
WHERE format IS NOT NULL AND lower(trim(format)) ~ '^2\\s*/\\s*72$';
|
||||
|
||||
-- Pattern: "X / (N дней)" or "X / (N дн)"
|
||||
UPDATE "placement" SET
|
||||
top_time_minutes = CASE
|
||||
WHEN substring(lower(trim(format)) from '^(\\d+)\\s*/') ~ '^\\d+$'
|
||||
AND (substring(lower(trim(format)) from '^(\\d+)\\s*/'))::int <= 12
|
||||
THEN (substring(lower(trim(format)) from '^(\\d+)\\s*/'))::int * 60
|
||||
ELSE (substring(lower(trim(format)) from '^(\\d+)\\s*/'))::int
|
||||
END,
|
||||
feed_time_minutes = (substring(lower(trim(format)) from '(\\d+)\\s*дн'))::int * 24 * 60
|
||||
WHERE format IS NOT NULL
|
||||
AND top_time_minutes IS NULL
|
||||
AND lower(trim(format)) ~ '^\\d+\\s*/.*\\d+\\s*дн';
|
||||
|
||||
-- Pattern: "X / (без удаления)" or "X / без удаления"
|
||||
UPDATE "placement" SET
|
||||
top_time_minutes = CASE
|
||||
WHEN substring(lower(trim(format)) from '^(\\d+)\\s*/') ~ '^\\d+$'
|
||||
AND (substring(lower(trim(format)) from '^(\\d+)\\s*/'))::int <= 12
|
||||
THEN (substring(lower(trim(format)) from '^(\\d+)\\s*/'))::int * 60
|
||||
ELSE (substring(lower(trim(format)) from '^(\\d+)\\s*/'))::int
|
||||
END,
|
||||
feed_time_minutes = 0
|
||||
WHERE format IS NOT NULL
|
||||
AND top_time_minutes IS NULL
|
||||
AND lower(trim(format)) ~ 'без удаления';
|
||||
"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "placement" DROP COLUMN IF EXISTS "feed_time_minutes";
|
||||
ALTER TABLE "placement" DROP COLUMN IF EXISTS "top_time_minutes";"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
"eJztXWtz2roW/SsMn3pmejoJkJBm7twZHm7LKQGGR9pzmo7HGIX4xtgc2zTNdPrfr+QHlu"
|
||||
"UHfgE27C80lbVla2299tLe0q/qSl0gWX/XeRIUBcnV28qvqiKsEP6DffS2UhXWa/cBSTCE"
|
||||
"uWzmFalMc93QBNHAyY+CrCOctEC6qElrQ1IVnKpsZJkkqiLOKClLN2mjSP9uEG+oS2Q8IQ"
|
||||
"0/+PYdJ0vKAv1EuvPf9TP/KCF54flYaUHebabzxuvaTJvNet0PZk7yujkvqvJmpbi516/G"
|
||||
"k6pss2820uIdkSHPlkhBmmCgBVUN8pV2hZ0k64txgqFt0PZTF27CAj0KG5mAUf3P40YRCQ"
|
||||
"YV803kp/HfagJ4RFUh0EqKQbD49duqlVtnM7VKXtX51Bq/qV//YdZS1Y2lZj40Ean+NgUF"
|
||||
"Q7BETVxdIEUNkWrzguEH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wq5Jb9GCQZjZIgw"
|
||||
"7w38/R/cVcJcZy7CjW3QZFQulgfAbVjnYxG94mF5fj4Ndesb3RHfQCwn0l0B5Ae4B1DLQH"
|
||||
"KBZoj1OnPbwzbRrqw1vCkcMCqq3uXW/Af5j1yS2Wi5Wk8I8434MyGg//4jrTCT/mWt3biu"
|
||||
"M1zpMeSj39Mu5NOerxiyYZ6EHpYClCqTji25B9W959bhfgZrBLGPVbHe6OG7hfsL2vzPkG"
|
||||
"N4fzFW4Wu5TWoNX/e9rrOIXg5Zr8akiiU4b7nLSc4WzKd/q9zucJnfNFwhraGLwoS+KzTs"
|
||||
"sMvwz4bU1oEfVF8Z5SkDjsohEn6qIRHnTRYNmiwDVccgbk/BikODRIXmeT78Fv/uh8SBk2"
|
||||
"nFk7Nr6VtrV7U5hqlj2ev8EG1tgehgGwxk5+0Q7W2IkqFqwxsMbAGgNrrDjWmPM5Ce0wRi"
|
||||
"zDYmz3sFMYA6xgt7uVFTlrTEiKm0fq/FAD1gRYk2KyJgF9Owco4x/rcawOvfuGQc+QtRs8"
|
||||
"Z07NAb1cT5Q9EnzMEiNG4zvSHZeFRTDeFZfHYT1bSJPEp2oAv2k/eRvFZApunsIQlqE3Vs"
|
||||
"W9qMpWYTaiMiPRYt1TVbtsNBs39evG9nqqbUqU67BzA1U4P/kDaeEmcjB6lAgcXOYeXIa7"
|
||||
"RgIQ7ezlBPDy4iIGgDhX+H3r5Blj96qKEThV/DUZDkJsXleEAXKm4Ap+W0ii8bYiS7rxvZ"
|
||||
"iwRqBIau2h2hzw3ty1vrK4dvrDNrvaJgW0k50El//08vv/Hh8R5A=="
|
||||
)
|
||||
@@ -0,0 +1,108 @@
|
||||
# ruff: noqa
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
-- Add CHECK constraint: exactly one FK must be set
|
||||
ALTER TABLE "workspace_user_permission_scope"
|
||||
ADD CONSTRAINT "check_exactly_one_scope"
|
||||
CHECK (
|
||||
(("project_id" IS NOT NULL)::int +
|
||||
("creative_id" IS NOT NULL)::int +
|
||||
("placement_id" IS NOT NULL)::int +
|
||||
("channel_id" IS NOT NULL)::int) = 1
|
||||
);
|
||||
|
||||
COMMENT ON TABLE "workspace_user_permission_scope"
|
||||
IS 'Permission scoped to specific entity (project/creative/placement/channel)'; \
|
||||
"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "workspace_user_permission_scope"
|
||||
DROP CONSTRAINT IF EXISTS "check_exactly_one_scope"; \
|
||||
"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
'eJztXWlv2zoW/SuGP/UBmSJx1lcMBrAdt/WrYxte0s5rCkGWGUcTWfLTkjQo+t+HlLWQ1G'
|
||||
'JttiX7fgkckpeSzuV2z70kf9WX2hwpxvv2k6iqSKl/qP2qq+IS4R981kmtLq5WfgZJMMWZ'
|
||||
'YpeVqEIzw9RFycTJj6JiIJw0R4akyytT1lScqlqKQhI1CReU1YWfZKnyPxYSTG2BzCek44'
|
||||
'zvP3CyrM7RT2S4/66ehUcZKXPmZeU5ebadLphvKzttOu3efrRLksfNBElTrKXql169mU+a'
|
||||
'6hW3LHn+nsiQvAVSkS6aaE59BnlL54PdpPUb4wRTt5D3qnM/YY4eRUshYNT//WipEsGgZj'
|
||||
'+J/Ln4Tz0FPJKmEmhl1SRY/Pq9/ir/m+3UOnlU+3Nz9O786g/7KzXDXOh2po1I/bctKJri'
|
||||
'WtTG1QdS0hH5bEE0g4De4hxTXqJwUFlJDty5I/re/ZEFZDfBR9lvYS7MLnzZMK3jb5gPVO'
|
||||
'XN0WAMxpPuXWc8ad4NyZcsDeMfxYaoOemQnIad+salvlurRMP9Y91vvEpqX7uTzzXyb+3v'
|
||||
'Qb/DK84rN/m7Tt5JtExNULVXQZxTjc1NdYHBJX3FWqt5RsW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FNjhQyMYkrYqLOKF'
|
||||
'BWhMqq4YSjvjM6h2tInZYJtcUo5DWLFiW6M76AWE/0igPYD2AOsYaA9QLNAeh057sDNtFu'
|
||||
'qDrWHf98Y1b++6feHjtEduipsvZVV4xOUe1OFoQC5zHgujTpPc++xEjQukh1K5X0fdSYfK'
|
||||
'ftVlEz2obSxFKBVX3J515Bfkyvv5TgV+AaeGYa/Z7tx1+v4beLckue/gl3Dfwi/i1NLsN3'
|
||||
'v/nXTbbiV4uaa8mbLk1uHnk5YzmE6Edq/b/jKmS77KWEOWKUiKLD2Te6s/k7uwe96nrW+B'
|
||||
'8r7MzXU/zM223ygLbdS4SLJb4CJ6s8AFzxyFrufSsyHHxyYloUSKOkJ6CzH0e+dGquB85m'
|
||||
'3a5BabZwNnMNvWtnnxxhtYZlsYBsAyO/gFPFhmB6pYsMzAMgPLDCyzclpme74gffMAVBpT'
|
||||
'jEHNaaJpYWPFjg+3ElxjVlXk1qNqWtwYqeNDDXgn4J3KyTuF9O0CoEx+SMq+OvTmq/SYIW'
|
||||
'szeO6cWgB6baqqqsLHLTESNL49XeZYWgTT3+XorIaLaIF+TVWFjzUNykS6N5EuS0/1EHrd'
|
||||
'yTmJI9JFv0xp+PLIe62SXmflKDAfT56T51vfZtU4u7i+uDm/uvAusfJS4qLY3XuqounxF6'
|
||||
'RHMzTh6FEiR37eGz3Kka6RAkSneDUBPDs9TQAgLhV9KzvJ40gDTTVD59m/xoN+BGHgi3BA'
|
||||
'TlX8gd/nsmSe1BTZMH+UE9YYFMlXM0yvC967u+Y3Htd2b9DiTRVSQSvdoYTFTy+//w9A8z'
|
||||
'v0'
|
||||
)
|
||||
@@ -0,0 +1,412 @@
|
||||
# ruff: noqa
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
-- Шаг 1: Переименовать старую таблицу placement в old_placement
|
||||
ALTER TABLE "placement" RENAME TO "old_placement";
|
||||
|
||||
-- Шаг 2: Создать новую таблицу placement (объединение purchase + purchase_channel)
|
||||
CREATE TABLE "placement" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"status" VARCHAR(11) NOT NULL DEFAULT 'planned',
|
||||
"placement_at" TIMESTAMPTZ,
|
||||
"payment_at" TIMESTAMPTZ,
|
||||
"cost_type" VARCHAR(8),
|
||||
"cost_value" DOUBLE PRECISION,
|
||||
"cost_before_bargain" DOUBLE PRECISION,
|
||||
"placement_type" VARCHAR(16),
|
||||
"format" TEXT,
|
||||
"comment" TEXT,
|
||||
"invite_link" VARCHAR(512) NOT NULL,
|
||||
"invite_link_type" VARCHAR(8) NOT NULL,
|
||||
"project_id" UUID NOT NULL REFERENCES "project" ("id") ON DELETE CASCADE,
|
||||
"creative_id" UUID NOT NULL REFERENCES "creative" ("id") ON DELETE CASCADE,
|
||||
"channel_id" UUID NOT NULL REFERENCES "channel" ("id") ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Шаг 3: Мигрировать данные из purchase_channel + purchase в новый placement
|
||||
INSERT INTO "placement" (
|
||||
"id", "created_at", "updated_at", "deleted_at",
|
||||
"status", "placement_at", "payment_at",
|
||||
"cost_type", "cost_value", "cost_before_bargain",
|
||||
"placement_type", "format", "comment",
|
||||
"invite_link", "invite_link_type",
|
||||
"project_id", "creative_id", "channel_id"
|
||||
)
|
||||
SELECT
|
||||
pc.id, pc.created_at, pc.updated_at, pc.deleted_at,
|
||||
pc.status,
|
||||
COALESCE(pc.placement_at, p.placement_at),
|
||||
p.payment_at,
|
||||
COALESCE(pc.cost_type, p.cost_type),
|
||||
COALESCE(pc.cost_value, p.cost_value),
|
||||
COALESCE(pc.cost_before_bargain, p.cost_before_bargain),
|
||||
p.purchase_type,
|
||||
COALESCE(pc.format, p.format),
|
||||
COALESCE(pc.comment, p.comment),
|
||||
pc.invite_link, pc.invite_link_type,
|
||||
p.project_id, p.creative_id, pc.channel_id
|
||||
FROM "purchase_channel" pc
|
||||
JOIN "purchase" p ON pc.purchase_id = p.id;
|
||||
|
||||
-- Шаг 4: Создать таблицу placement_post (бывший placement)
|
||||
CREATE TABLE "placement_post" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"wanted_placement_date" TIMESTAMPTZ NOT NULL,
|
||||
"cost" DOUBLE PRECISION,
|
||||
"comment" TEXT,
|
||||
"status" VARCHAR(8) NOT NULL DEFAULT 'active',
|
||||
"creative_id" UUID NOT NULL REFERENCES "creative" ("id") ON DELETE CASCADE,
|
||||
"placement_id" UUID NOT NULL REFERENCES "placement" ("id") ON DELETE CASCADE,
|
||||
"post_id" UUID REFERENCES "post" ("id") ON DELETE SET NULL,
|
||||
"project_id" UUID NOT NULL REFERENCES "project" ("id") ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Шаг 5: Мигрировать данные из old_placement в placement_post
|
||||
INSERT INTO "placement_post" (
|
||||
"id", "created_at", "updated_at", "deleted_at",
|
||||
"wanted_placement_date", "cost", "comment", "status",
|
||||
"creative_id", "placement_id", "post_id", "project_id"
|
||||
)
|
||||
SELECT
|
||||
op.id, op.created_at, op.updated_at, op.deleted_at,
|
||||
op.wanted_placement_date, op.cost, op.comment, op.status,
|
||||
op.creative_id, op.purchase_channel_id, op.post_id, op.project_id
|
||||
FROM "old_placement" op;
|
||||
|
||||
-- Шаг 6: Обновить foreign keys для таблиц, ссылающихся на old_placement
|
||||
|
||||
-- 6.1: Обновить subscription (placement_id -> placement_post_id)
|
||||
-- Удалить constraint ДО переименования колонки
|
||||
ALTER TABLE "subscription"
|
||||
DROP CONSTRAINT IF EXISTS "subscription_placement_id_fkey";
|
||||
|
||||
-- Переименовать колонку
|
||||
ALTER TABLE "subscription" RENAME COLUMN "placement_id" TO "placement_post_id";
|
||||
|
||||
-- 6.2: Обновить workspace_user_permission_scope.placement_id
|
||||
-- Удалить старый foreign key constraint ДО обновления данных
|
||||
ALTER TABLE "workspace_user_permission_scope"
|
||||
DROP CONSTRAINT IF EXISTS "workspace_user_permission_scope_placement_id_fkey";
|
||||
|
||||
-- Обновить данные: старые placement_id -> новые placement_id (через purchase_channel_id)
|
||||
UPDATE "workspace_user_permission_scope" wups
|
||||
SET placement_id = op.purchase_channel_id
|
||||
FROM "old_placement" op
|
||||
WHERE wups.placement_id = op.id;
|
||||
|
||||
-- Шаг 7: Создать индексы и constraints
|
||||
CREATE INDEX "idx_placement_project_4155ce"
|
||||
ON "placement" ("project_id", "status");
|
||||
CREATE INDEX "idx_placement_channel_fb3968"
|
||||
ON "placement" ("channel_id");
|
||||
CREATE INDEX "idx_placement_post_creativ_1c6807"
|
||||
ON "placement_post" ("creative_id");
|
||||
CREATE INDEX "idx_placement_post_placeme_bd5bc9"
|
||||
ON "placement_post" ("placement_id");
|
||||
CREATE INDEX "idx_placement_post_post_id_998755"
|
||||
ON "placement_post" ("post_id");
|
||||
CREATE INDEX "idx_placement_post_project_94129d"
|
||||
ON "placement_post" ("project_id");
|
||||
|
||||
ALTER TABLE "subscription"
|
||||
ADD CONSTRAINT "fk_subscrip_placem_1959be9e"
|
||||
FOREIGN KEY ("placement_post_id")
|
||||
REFERENCES "placement_post" ("id") ON DELETE CASCADE;
|
||||
|
||||
CREATE UNIQUE INDEX "uid_subscriptio_placem_578bfb"
|
||||
ON "subscription" ("placement_post_id", "telegram_user_id");
|
||||
|
||||
ALTER TABLE "workspace_user_permission_scope"
|
||||
ADD CONSTRAINT "fk_workspac_placemen_8c5d3f2a"
|
||||
FOREIGN KEY ("placement_id")
|
||||
REFERENCES "placement" ("id") ON DELETE CASCADE;
|
||||
|
||||
-- Шаг 8: Добавить комментарии
|
||||
COMMENT ON TABLE "placement"
|
||||
IS 'Размещение, управляемое пользователем (бывший PurchaseChannel + Purchase)';
|
||||
COMMENT ON COLUMN "placement"."status"
|
||||
IS 'PLANNED: planned
|
||||
APPROVED: approved
|
||||
REJECTED: rejected
|
||||
IN_PROGRESS: in_progress
|
||||
COMPLETED: completed';
|
||||
COMMENT ON COLUMN "placement"."invite_link_type"
|
||||
IS 'PUBLIC: public
|
||||
APPROVAL: approval';
|
||||
COMMENT ON COLUMN "placement"."cost_type"
|
||||
IS 'FIXED: fixed
|
||||
CPM: cpm';
|
||||
COMMENT ON COLUMN "placement"."placement_type"
|
||||
IS 'SELF_PROMO: self_promo
|
||||
STANDARD: standard';
|
||||
|
||||
COMMENT ON TABLE "placement_post"
|
||||
IS 'Публикация, мониторимая системой (бывший Placement)';
|
||||
COMMENT ON COLUMN "placement_post"."status"
|
||||
IS 'ACTIVE: active
|
||||
ARCHIVED: archived';
|
||||
|
||||
-- Шаг 9: Удалить старые таблицы
|
||||
DROP TABLE IF EXISTS "old_placement";
|
||||
DROP TABLE IF EXISTS "purchase_channel";
|
||||
DROP TABLE IF EXISTS "purchase";
|
||||
"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
-- ВНИМАНИЕ: Downgrade может привести к потере данных при объединении placement обратно
|
||||
-- в purchase + purchase_channel (если были созданы placement без привязки к одному purchase)
|
||||
|
||||
-- Шаг 1: Переименовать новую таблицу placement в new_placement
|
||||
ALTER TABLE "placement" RENAME TO "new_placement";
|
||||
|
||||
-- Шаг 2: Воссоздать таблицу purchase
|
||||
CREATE TABLE "purchase" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"status" VARCHAR(8) NOT NULL DEFAULT 'active',
|
||||
"placement_at" TIMESTAMPTZ,
|
||||
"payment_at" TIMESTAMPTZ,
|
||||
"cost_type" VARCHAR(8),
|
||||
"cost_value" DOUBLE PRECISION,
|
||||
"cost_before_bargain" DOUBLE PRECISION,
|
||||
"purchase_type" VARCHAR(16),
|
||||
"format" TEXT,
|
||||
"comment" TEXT,
|
||||
"project_id" UUID NOT NULL REFERENCES "project" ("id") ON DELETE CASCADE,
|
||||
"creative_id" UUID NOT NULL REFERENCES "creative" ("id") ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Шаг 3: Воссоздать таблицу purchase_channel
|
||||
CREATE TABLE "purchase_channel" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"status" VARCHAR(11) NOT NULL DEFAULT 'planned',
|
||||
"placement_at" TIMESTAMPTZ,
|
||||
"cost_type" VARCHAR(8),
|
||||
"cost_value" DOUBLE PRECISION,
|
||||
"cost_before_bargain" DOUBLE PRECISION,
|
||||
"format" TEXT,
|
||||
"comment" TEXT,
|
||||
"invite_link" VARCHAR(512) NOT NULL,
|
||||
"invite_link_type" VARCHAR(8) NOT NULL,
|
||||
"purchase_id" UUID NOT NULL REFERENCES "purchase" ("id") ON DELETE CASCADE,
|
||||
"channel_id" UUID NOT NULL REFERENCES "channel" ("id") ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Шаг 4: Мигрировать данные из new_placement в purchase (сгруппировать)
|
||||
-- Создаем purchase для каждого уникального project_id + creative_id
|
||||
INSERT INTO "purchase" (
|
||||
"id", "created_at", "updated_at", "deleted_at",
|
||||
"status", "placement_at", "payment_at",
|
||||
"cost_type", "cost_value", "cost_before_bargain",
|
||||
"purchase_type", "format", "comment",
|
||||
"project_id", "creative_id"
|
||||
)
|
||||
SELECT
|
||||
gen_random_uuid(),
|
||||
MIN(np.created_at),
|
||||
MAX(np.updated_at),
|
||||
NULL,
|
||||
'active',
|
||||
MIN(np.placement_at),
|
||||
MIN(np.payment_at),
|
||||
MIN(np.cost_type),
|
||||
MIN(np.cost_value),
|
||||
MIN(np.cost_before_bargain),
|
||||
MIN(np.placement_type),
|
||||
MIN(np.format),
|
||||
MIN(np.comment),
|
||||
np.project_id,
|
||||
np.creative_id
|
||||
FROM "new_placement" np
|
||||
GROUP BY np.project_id, np.creative_id;
|
||||
|
||||
-- Шаг 5: Мигрировать данные из new_placement в purchase_channel
|
||||
INSERT INTO "purchase_channel" (
|
||||
"id", "created_at", "updated_at", "deleted_at",
|
||||
"status", "placement_at", "cost_type", "cost_value",
|
||||
"cost_before_bargain", "format", "comment",
|
||||
"invite_link", "invite_link_type",
|
||||
"purchase_id", "channel_id"
|
||||
)
|
||||
SELECT
|
||||
np.id, np.created_at, np.updated_at, np.deleted_at,
|
||||
np.status, np.placement_at, np.cost_type, np.cost_value,
|
||||
np.cost_before_bargain, np.format, np.comment,
|
||||
np.invite_link, np.invite_link_type,
|
||||
p.id, np.channel_id
|
||||
FROM "new_placement" np
|
||||
JOIN "purchase" p
|
||||
ON p.project_id = np.project_id
|
||||
AND p.creative_id = np.creative_id;
|
||||
|
||||
-- Шаг 6: Воссоздать старую таблицу placement
|
||||
CREATE TABLE "placement" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"wanted_placement_date" TIMESTAMPTZ NOT NULL,
|
||||
"cost" DOUBLE PRECISION,
|
||||
"comment" TEXT,
|
||||
"status" VARCHAR(8) NOT NULL DEFAULT 'active',
|
||||
"creative_id" UUID NOT NULL REFERENCES "creative" ("id") ON DELETE CASCADE,
|
||||
"purchase_channel_id" UUID NOT NULL
|
||||
REFERENCES "purchase_channel" ("id") ON DELETE CASCADE,
|
||||
"post_id" UUID REFERENCES "post" ("id") ON DELETE SET NULL,
|
||||
"project_id" UUID NOT NULL REFERENCES "project" ("id") ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Шаг 7: Мигрировать данные из placement_post в placement
|
||||
INSERT INTO "placement" (
|
||||
"id", "created_at", "updated_at", "deleted_at",
|
||||
"wanted_placement_date", "cost", "comment", "status",
|
||||
"creative_id", "purchase_channel_id", "post_id", "project_id"
|
||||
)
|
||||
SELECT
|
||||
pub.id, pub.created_at, pub.updated_at, pub.deleted_at,
|
||||
pub.wanted_placement_date, pub.cost, pub.comment, pub.status,
|
||||
pub.creative_id, pub.placement_id, pub.post_id, pub.project_id
|
||||
FROM "placement_post" pub;
|
||||
|
||||
-- Шаг 8: Обновить foreign keys обратно
|
||||
|
||||
-- 8.1: Обновить subscription (placement_post_id -> placement_id)
|
||||
-- Удалить новый foreign key constraint
|
||||
ALTER TABLE "subscription"
|
||||
DROP CONSTRAINT IF EXISTS "fk_subscrip_placem_1959be9e";
|
||||
|
||||
-- Переименовать колонку обратно
|
||||
ALTER TABLE "subscription" RENAME COLUMN "placement_post_id" TO "placement_id";
|
||||
|
||||
-- 8.2: Обновить workspace_user_permission_scope.placement_id обратно
|
||||
-- Удалить constraint на новый placement
|
||||
ALTER TABLE "workspace_user_permission_scope"
|
||||
DROP CONSTRAINT IF EXISTS "fk_workspac_placemen_8c5d3f2a";
|
||||
|
||||
-- Обновить данные обратно: новые placement_id -> старые placement_id
|
||||
UPDATE "workspace_user_permission_scope" wups
|
||||
SET placement_id = pub.id
|
||||
FROM "placement_post" pub
|
||||
WHERE wups.placement_id = pub.placement_id;
|
||||
|
||||
-- Шаг 9: Создать индексы и constraints
|
||||
CREATE INDEX "idx_purchase_project_status" ON "purchase" ("project_id", "status");
|
||||
CREATE INDEX "idx_placement_purchas_61f9e6"
|
||||
ON "placement" ("purchase_channel_id");
|
||||
CREATE INDEX "idx_placement_post_id_e4a16e" ON "placement" ("post_id");
|
||||
|
||||
ALTER TABLE "subscription"
|
||||
ADD CONSTRAINT "fk_subscrip_placemen_0b5d8f15"
|
||||
FOREIGN KEY ("placement_id")
|
||||
REFERENCES "placement" ("id") ON DELETE CASCADE;
|
||||
|
||||
CREATE UNIQUE INDEX "uid_subscriptio_placeme_75b40b"
|
||||
ON "subscription" ("placement_id", "telegram_user_id");
|
||||
|
||||
ALTER TABLE "workspace_user_permission_scope"
|
||||
ADD CONSTRAINT "fk_workspac_placemen_8c5d3f2a"
|
||||
FOREIGN KEY ("placement_id")
|
||||
REFERENCES "placement" ("id") ON DELETE CASCADE;
|
||||
|
||||
-- Шаг 10: Удалить новые таблицы
|
||||
DROP TABLE IF EXISTS "placement_post";
|
||||
DROP TABLE IF EXISTS "new_placement";
|
||||
"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
'eJztXWtz2roW/SsMn3rm5nbCIwnN3LkzhJCWlgADpO09TcdjjCC+MTbHNkkzZ/rfj+QHlv'
|
||||
'zCL7AN+wtNJW3ZXluvvbS19Xd1pcyRpL3vPPGyjKTqdeXvqsyvEP7DnXVWqfLrtZNBEnR+'
|
||||
'JhllBarQTNNVXtBx8oKXNIST5kgTVHGti4qMU+WNJJFERcAFRXnpJG1k8a8N4nRlifQnpO'
|
||||
'KMHz9xsijP0S+k2f9dP3MLEUlz5mXFOXm2kc7pb2sj7eGhd3tnlCSPm3GCIm1WslN6/aY/'
|
||||
'KfK2+GYjzt8TGZK3RDJSeR3Nqc8gb2l9sJ1kvjFO0NUN2r7q3EmYowW/kQgY1f8sNrJAMK'
|
||||
'gYTyI/zf9WY8AjKDKBVpR1gsXfv82vcr7ZSK2SR3U+tcfvGpd/GF+paPpSNTINRKq/DUFe'
|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2Na6c/vHGbKqSCm3hBCb'
|
||||
'OfXn7/A5u7TFM='
|
||||
)
|
||||
@@ -0,0 +1,91 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "login_token" ADD "message_id" INT;
|
||||
"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "login_token" DROP COLUMN "message_id";
|
||||
"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
'eJztXWuPm7wS/itRPvWV9lS72etbHR0pm2XbtNkkyqXtebsVIsSb5SyBFMheVPW/HxtwwA'
|
||||
'YSbgmQzJdqa3sceMYee54Zm9/1uT5Fqvm+9ShpGlLrH2q/65o0R/gPvuqoVpcWC6+CFFjS'
|
||||
'RLXbyr5GE9MyJNnCxQ+SaiJcNEWmbCgLS9E1XKotVZUU6jJuqGgzr2ipKb+WSLT0GbIekY'
|
||||
'ErfvzExYo2Ra/IpP9dPIkPClKnzMMqU/LbdrlovS3ssvG4fXNrtyQ/NxFlXV3ONa/14s16'
|
||||
'1LVV8+VSmb4nMqRuhjRkSBaa+l6DPKX7wrTIeWJcYBlLtHrUqVcwRQ/SUiVg1P/9sNRkgk'
|
||||
'HN/iXyz9l/6gngkXWNQKtoFsHi9x/nrbx3tkvr5Kdan5qDd6cXf9lvqZvWzLArbUTqf2xB'
|
||||
'yZIcURtXD0jZQOS1RckKAnqDayxljsJBZSU5cKeu6Hv6RxqQaYGHsjfCKMwUvnSY1vE7TH'
|
||||
'ua+uZqcA3Go/adMBw17/rkTeam+Uu1IWqOBFLTsEvfuNJ3jkp0PD+cebPqpPatPfpUI/+t'
|
||||
'/dPrCrziVu1G/9TJM0lLSxc1/UWUpr7BRkspMLilp9jlYppSsawkKLZQxboP7+kV22KUTq'
|
||||
'+sZA56dZ92h2qtiBrpa6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NbtdobN6NedTdas3o7X0xWi1/URpaKPGWZzTAmfRhwXOeOYodD+XnA05PDYpDi'
|
||||
'WS1xXSW8ihL5wbqULwmfdp43tsKx84hdvm+Ob5O2/gmW3BDIBntvcbePDM9lSx4JmBZwae'
|
||||
'GXhm5fTM2O+ex92OsVIZtmWbDVBpXDEGNXeIJoWNFTs83LyPJaX9stnBIudY1aS4MVKHhx'
|
||||
'rwTsA7lZN3CpnbOUAZ/5KUoib05u/pMSZrM3h0Tc0BvZavq6rCx20xYgw+urTmMfz8fVUV'
|
||||
'QX6vEWMIOrvhPEag11NV4WNdgzKR7k1kKPJjPYRed2uO1hHpktemNHx55Het4n7OylVgNp'
|
||||
'48I8/nfM2qcXJ2eXZ1enG2+ojVqmRdFjv9TlU0Pf6MjGiGJhw9n8iB3/fmt3JkaiQA0W1e'
|
||||
'TQBPjo9jAIhbRX+tndRxpIGuWaHr7OdhrxtBGHgiHJBjDb/gj6kiW0c1VTGtn+WEdQ2K5K'
|
||||
'0ZppeC9+6u+Z3HtdXpXfOuCungOtmlhPkvL3/+D2s6rNg='
|
||||
)
|
||||
@@ -0,0 +1,107 @@
|
||||
# ruff: noqa
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
DROP INDEX IF EXISTS "idx_placement_p_creativ_a8f431";
|
||||
DROP INDEX IF EXISTS "idx_placement_p_project_888982";
|
||||
ALTER TABLE "placement_post" DROP CONSTRAINT IF EXISTS "fk_placemen_project_f98a29a5";
|
||||
ALTER TABLE "placement_post" DROP CONSTRAINT IF EXISTS "fk_placemen_creative_db63ad95";
|
||||
ALTER TABLE "placement" ALTER COLUMN "creative_id" DROP NOT NULL;
|
||||
ALTER TABLE "placement_post" DROP COLUMN "comment";
|
||||
ALTER TABLE "placement_post" DROP COLUMN "project_id";
|
||||
ALTER TABLE "placement_post" DROP COLUMN "cost";
|
||||
ALTER TABLE "placement_post" DROP COLUMN "wanted_placement_date";
|
||||
ALTER TABLE "placement_post" DROP COLUMN "creative_id";"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "placement" ALTER COLUMN "creative_id" SET NOT NULL;
|
||||
ALTER TABLE "placement_post" ADD "comment" TEXT;
|
||||
ALTER TABLE "placement_post" ADD "project_id" UUID NOT NULL;
|
||||
ALTER TABLE "placement_post" ADD "cost" DOUBLE PRECISION;
|
||||
ALTER TABLE "placement_post" ADD "wanted_placement_date" TIMESTAMPTZ NOT NULL;
|
||||
ALTER TABLE "placement_post" ADD "creative_id" UUID NOT NULL;
|
||||
ALTER TABLE "placement_post" ADD CONSTRAINT "fk_placemen_creative_db63ad95" FOREIGN KEY ("creative_id") REFERENCES "creative" ("id") ON DELETE CASCADE;
|
||||
ALTER TABLE "placement_post" ADD CONSTRAINT "fk_placemen_project_f98a29a5" FOREIGN KEY ("project_id") REFERENCES "project" ("id") ON DELETE CASCADE;
|
||||
CREATE INDEX IF NOT EXISTS "idx_placement_p_project_888982" ON "placement_post" ("project_id");
|
||||
CREATE INDEX IF NOT EXISTS "idx_placement_p_creativ_a8f431" ON "placement_post" ("creative_id");"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
'eJztXWtz2roW/SsMn3pmcjsJkMfJ3LkzQJyWlgDDo+09TcdjjEJ8Y2xqmzymk/9+JdvClm'
|
||||
'yDbQzYsL90Uklb2GvrtZa25D/lmT5Bqvmx+ShpGlLL16U/ZU2aIfwHn3VSKkvzuZdBEixp'
|
||||
'rNplZV+hsWkZkmzh5AdJNRFOmiBTNpS5pegaTtUWqkoSdRkXVLSpl7TQlN8LJFr6FFmPyM'
|
||||
'AZP3/hZEWboFdk0v/On8QHBakT5mGVCfltO1203uZ22mjUurm1S5KfG4uyri5mmld6/mY9'
|
||||
'6tqy+GKhTD4SG5I3RRoyJAtNfK9BntJ9YZrkPDFOsIwF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eUJpZ3qGrx2tUzbYJhdX4xDnrNnW5A7/AsL7SZA9QPYAdgyyBzgW'
|
||||
'ZI9Dlz3YmTaN9MHWsOcQ9nL95q7VEW9HbfL1wclM0cQHXO5e6/W7X4TmcCD2hfrNdYlGjY'
|
||||
'ukh/pyv/dbQ8GX/WIoFrrXmtiKSCrUfPm5LNfey3cr8Aq4NfTa9aZwJ3S8J1h+Z4o+g1eC'
|
||||
'PoVXxK2l3qm3/ztsNWkleLmmvlmKTOvw8knL6Y6GYrPdan4d+Eu+KNhDC0uUVUV+MvGzf6'
|
||||
'53OkJ7+WrOV9mWb0Zz6YvRbPuJ0shGlVqc0wK16MMCNV45Cl3PJVdDjk9NiiOJZHWF9BZi'
|
||||
'6PeujRRh85nntPEZ25IDp6BtDjfPnrwBM9vCMADM7OAX8MDMDtSxwMyAmQEzA2aWT2bGfu'
|
||||
'I77nKMtdpgWbZ+AMoNFWNQc5toUthYs+PDzftYUtovmx0tcs6omhQ3xur4UAPdCXSnfOpO'
|
||||
'IX07AyjjX5Kyrw69/nt6zJC1Hjw6p2aAXtNXVVHh45YYMRofnVqzaH7+uoqKIL/WiNEEnd'
|
||||
'VwFi3Qq6mo8LHUIE+iex0ZivxYDpHX3ZyTVUK65JXJjV4e+V2ruJ+zch24mU6+oc7nfM2q'
|
||||
'cla7rF1VL2rLj1gtU1ZFsdPvVEXL48/IiFZowtHzmRz5fW/+UY50jQQgusWLCeDZ6WkMAH'
|
||||
'Gp6K+1kzxONNA1K3Se/TLodiIEA8+EA3Kk4Rf8OVFk66SkKqb1K5+wrkCRvDWj9FLwPtzV'
|
||||
'f/C4NtvdBk9VSAWNZJcSZj+9vP8f6Gvh+w=='
|
||||
)
|
||||
@@ -0,0 +1,140 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "placement" ALTER COLUMN "status" SET DEFAULT 'Без статуса';
|
||||
UPDATE "placement"
|
||||
SET "status" = 'Без статуса'
|
||||
WHERE "status" IN ('planned', 'approved', 'in_progress', 'completed', 'rejected');
|
||||
ALTER TABLE "placement" ALTER COLUMN "status" TYPE VARCHAR(64) USING "status"::VARCHAR(64);
|
||||
COMMENT ON COLUMN "placement"."status" IS 'NO_STATUS: Без статуса
|
||||
WRITE: Написать
|
||||
WAITING_RESPONSE: Ждём ответа
|
||||
TERMS_APPROVAL: Согласование условий
|
||||
TO_PAY: Оплатить
|
||||
PAID: Оплачено
|
||||
CANCELED: Отмена
|
||||
PRICE_NOT_OK: Не подходит цена
|
||||
NOT_RELEVANT: Неактуально
|
||||
NO_RESPONSE: Не отвечает';
|
||||
ALTER TABLE "placement" ALTER COLUMN "invite_link" DROP NOT NULL;
|
||||
ALTER TABLE "placement_post" DROP COLUMN IF EXISTS "wanted_placement_date";
|
||||
ALTER TABLE "placement_post" DROP COLUMN IF EXISTS "cost";
|
||||
ALTER TABLE "placement_post" DROP COLUMN IF EXISTS "comment";
|
||||
ALTER TABLE "placement_post" DROP COLUMN IF EXISTS "creative_id";
|
||||
ALTER TABLE "placement_post" DROP COLUMN IF EXISTS "project_id";
|
||||
ALTER TABLE "placement_post" DROP COLUMN IF EXISTS "status";"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "placement" ALTER COLUMN "status" SET DEFAULT 'planned';
|
||||
UPDATE "placement"
|
||||
SET "status" = 'planned'
|
||||
WHERE "status" IN (
|
||||
'Без статуса',
|
||||
'Написать',
|
||||
'Ждём ответа',
|
||||
'Согласование условий',
|
||||
'Оплатить',
|
||||
'Оплачено',
|
||||
'Отмена',
|
||||
'Не подходит цена',
|
||||
'Неактуально',
|
||||
'Не отвечает'
|
||||
);
|
||||
COMMENT ON COLUMN "placement"."status" IS 'PLANNED: planned
|
||||
APPROVED: approved
|
||||
REJECTED: rejected
|
||||
IN_PROGRESS: in_progress
|
||||
COMPLETED: completed';
|
||||
ALTER TABLE "placement" ALTER COLUMN "status" TYPE VARCHAR(11) USING "status"::VARCHAR(11);
|
||||
ALTER TABLE "placement" ALTER COLUMN "invite_link" SET NOT NULL;
|
||||
ALTER TABLE "placement_post" ADD "wanted_placement_date" TIMESTAMPTZ;
|
||||
ALTER TABLE "placement_post" ADD "cost" DOUBLE PRECISION;
|
||||
ALTER TABLE "placement_post" ADD "comment" TEXT;
|
||||
ALTER TABLE "placement_post" ADD "creative_id" UUID;
|
||||
ALTER TABLE "placement_post" ADD "project_id" UUID;
|
||||
ALTER TABLE "placement_post" ADD "status" VARCHAR(8) NOT NULL DEFAULT 'active';
|
||||
COMMENT ON COLUMN "placement_post"."status" IS 'ACTIVE: active\nARCHIVED: archived';"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
'eJztXWtv2soW/SuITz1SbpUACTnR1ZUc4rRuCSAeac9pKsuYgfjG2BzbNI2q/vcz4wee8Q'
|
||||
'NsY8CG/YWmM7PH47XntdY8/Ks61ydINd+3niVNQ2r1pvKrqklzhP8IRp1VqtJi4UeQAEsa'
|
||||
'q3ZamUo0Ni1Dki0cPJVUE+GgCTJlQ1lYiq7hUG2pqiRQl3FCRZv5QUtN+WeJREufIesZGT'
|
||||
'ji23ccrGgT9BOZ3n8XL+JUQeqEKawyIc+2w0XrbWGHjUbC3b2dkjxuLMq6upxrfurFm/Ws'
|
||||
'a6vky6UyeU9sSNwMaciQLDShXoOU0n1hL8gpMQ6wjCVaFXXiB0zQVFqqBIzqf6dLTSYYVO'
|
||||
'wnkZ/G/6op4JF1jUCraBbB4tdv5638d7ZDq+RRrY9c/1396g/7LXXTmhl2pI1I9bdtKFmS'
|
||||
'Y2rj6gMpG4i8tihZYUDvcIylzFE0qKxlANyJa/re+yMLyF6Aj7JfwzyYPfiyYVrF7zDpau'
|
||||
'qb68E1GA+FB34w5B565E3mpvmPakPEDXkSU7ND3wKh7xyX6Lh9OO1mlUnlizD8WCH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12JnfQEwj/kSB7gOwB7BhkD3AsyB7HLnuwI20W6YPN4cBb2Kvc3YPQEe9HbfL1wclc'
|
||||
'0cQpTvek9frdT3xrOBD7PHd3U/F2jYukhVKxX/rCkKeiXw3FQk9aC1sRScUzX30uy7X349'
|
||||
'0M/ARuDr021+If+I5fgtV3prwy+Cm8UvhJ3Fy4Dtf+ayi0vEzwdE19sxTZy8OPJzWnOxqK'
|
||||
'rbbQ+jygU74q2ENLS5RVRX4xcdk/cp0O3169mvNVttWbebHei3nRdomyyEa1RpLTAo34ww'
|
||||
'KNoHIUOZ9Lr4acnpqURBLJ6wrpHeyhP7g2UobF5yCnTc7YVhw4A21zuHn+5A2Y2Q66AWBm'
|
||||
'Rz+BB2Z2pI4FZgbMDJgZMLNiMjP2E99Jp2Os1RbTss0dUGGoGIOaW0XTwsaanR5u/seSsn'
|
||||
'7Z7GSRc3rVtLgxVqeHGuhOoDsVU3eKaNs5QJn8kpRDNejN39NjuqzN4Hljag7otaisygpf'
|
||||
'YIqRoPJ5Q2se1Y/Oq6wIBucaCaqgMxvOowb6OZUVPpYaFEl055ChyM/VCHndjTlbJ6RLfp'
|
||||
'rC6OWx37VK+jkr14Hb6eRb6nzO16xqF41m47p+1Vh9xGoVsm4Xu/edqnh5/Acy4hWaaPQo'
|
||||
'kxO/743u5UjTSAGim7ycAF6cnycAEKeK/1o7iQuIBrpmRY6znwbdToxg4JsEgBxp+AW/TR'
|
||||
'TZOquoiml9Lyasa1Akb80ovR547x64r0FcW+3ubZCqkAxu011KmP/w8vtfpk0r+g=='
|
||||
)
|
||||
@@ -0,0 +1,92 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "workspace" ADD "avatar_s3_key" VARCHAR(512);"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "workspace" DROP COLUMN "avatar_s3_key";"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
'eJztXWtzosga/iuWn2arcqYSNTGbOnWqiCEz7Bi1vGRmdzJFIbaGEwQXMJnU1vz37eYidA'
|
||||
'MKiAr6fnEy3f02zfP27Xn6wj/VuT5Bqvmx9SxpGlKrN5V/qpo0R/gPNuqsUpUWCz+CBFjS'
|
||||
'WLXTyoFEY9MyJNnCwVNJNREOmiBTNpSFpegaDtWWqkoCdRknVLSZH7TUlL+XSLT0GbKekY'
|
||||
'Ejvv/AwYo2QT+R6f138SJOFaROqMIqE/JsO1y03hd22Ggk3N3bKcnjxqKsq8u55qdevFvP'
|
||||
'urZKvlwqk4/EhsTNkIYMyUKTwGuQUrov7AU5JcYBlrFEq6JO/IAJmkpLlYBR/e90qckEg4'
|
||||
'r9JPLT+F81BTyyrhFoFc0iWPzzy3kr/53t0Cp5VOsz1/9Qv/rNfkvdtGaGHWkjUv1lG0qW'
|
||||
'5JjauPpAygYiry1KVhjQOxxjKXMUDSptyYA7cU0/en9kAdkL8FH2a5gHswdfNkyr+B0mXU'
|
||||
'19dz24BuOh8MAPhtxDj7zJ3DT/Vm2IuCFPYmp26DsT+sFxiY7bh9NuVplUvgrDzxXy38pf'
|
||||
'3Q7POm6VbvhXlZRJWlq6qOlvojQJVDYv1AMGp/Qdu1xMMjqWtgTHHtSxbuF9v+K+GGXzK2'
|
||||
'2Zg1/d0u7RrSVxo/faaxuohd0xM6S5GDWW3SozQbOi/cgYMo7EUO1mQNuyQc7IU/7ze61W'
|
||||
'rzdr5/Wr68tGs3l5fX6N09pFCkc117j7VvgkdIa090jALxpjxVJRGF08xzFisPUMGFTxqx'
|
||||
'S0o5tLP0UVaTPrGf+3dnm5BrNHrm/PFHAqpt533KiaE0eDuDSRYf+dAsegTT5Q7ryC7h5I'
|
||||
'SZaRaYrPkvmcrsUzhpla/P4768M0+YVlhsGNRdZNXS5EaxeNZuO6ftVYAbkKWYefg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M3YGY76AaAmR39BB6Y2ZE6FpgZMDNgZsDMisnM6M+mJ52O0V'
|
||||
'ZbTMs2d0CFoWIUam4VTQsbbXZ6uPkfoMr6tbiTRc7pVdPiRlmdHmqgO4HuVEzdKaJt5wBl'
|
||||
'8ktSDtWgN3+jkOqyNoPnjak5oNcKZFVW+JgpRoLK5w2teVS/YF5lRZCdaySogs5sOI8a6O'
|
||||
'dUVvhoalAk0Z1DhiI/VyPkdTfmbJ2QLvlpCqOXx34rLOknwlwHbqeTb6nzOV8Iq100mo3r'
|
||||
'+lVj9WGwVci6Xezet7/i5fFXZMQrNNHoBUzgDj3/Dj3cNFKA6CYvJ4AX5+cJAMSpYgG04x'
|
||||
'jRQNesyHH2j0G3EyMY+CYMkCMNv+D3iSJbZxVVMa0fxYR1DYrkrSml1wPvwwP3jcW11e7e'
|
||||
'slSFZHCb7lLC/IeXX/8CYMWYuQ=='
|
||||
)
|
||||
@@ -0,0 +1,94 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "channel" ADD "invite_link" VARCHAR(1024);
|
||||
ALTER TABLE "channel" ALTER COLUMN "username" DROP NOT NULL;"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "channel" DROP COLUMN "invite_link";
|
||||
ALTER TABLE "channel" ALTER COLUMN "username" SET NOT NULL;"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
"eJztXWtv2soW/SuITz1SbkWAhJzo6kqEOK1bAohH2nOayjJmIL4xNsc2SaMq//3M+IE9Yx"
|
||||
"tsY8CG/YWmM7PH47XntdY8/Ls81yZIMT62nkRVRUr5uvS7rIpzhP9go85KZXGx8CJIgCmO"
|
||||
"FSut5Es0NkxdlEwcPBUVA+GgCTIkXV6YsqbiUHWpKCRQk3BCWZ15QU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9/XkVFkJ1rxKiC9mw4ixro5VRU+GhqkCfRvYl0WXoqh8jrTszZOiFd9NLkRi+P/FZY"
|
||||
"3E+EOQ7cTiffUuezvxBWPa836le1y/rqw2CrkHW72N1vf0XL4y9Ij1ZowtHzmcAdet4der"
|
||||
"hpJADRSV5MAM8rlRgA4lSRAFpxjGigqWboOPtl0O1ECAaeCQPkSMUv+GMiS+ZZSZEN82c+"
|
||||
"YV2DInlrSul1wftw3/zO4tpqd29YqkIyuEl2KWH2w8v7v4yZBKk="
|
||||
)
|
||||
@@ -0,0 +1,96 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "channel"
|
||||
ADD CONSTRAINT "channel_identity_required"
|
||||
CHECK (username IS NOT NULL OR invite_link IS NOT NULL); \
|
||||
"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "channel" DROP CONSTRAINT IF EXISTS "channel_identity_required"; \
|
||||
"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
'eJztXWtv2soW/SuITz1SbkWAhJzo6kqEOK1bAohH2nOayjJmIL4xNsc2SaMq//3M+IE9Yx'
|
||||
'tsY8CG/YWmM7PH47XntdY8/Ls81yZIMT62nkRVRUr5uvS7rIpzhP9go85KZXGx8CJIgCmO'
|
||||
'FSut5Es0NkxdlEwcPBUVA+GgCTIkXV6YsqbiUHWpKCRQk3BCWZ15QUtV/meJBFObIfMJ6T'
|
||||
'jix08cLKsT9AsZ7n8Xz8JURsqEKqw8Ic+2wgXzbWGFjUb87Z2VkjxuLEiaspyrXurFm/mk'
|
||||
'qavky6U8+UhsSNwMqUgXTTTxvQYppfPCbpBdYhxg6ku0KurEC5igqbhUCBjl/06XqkQwKF'
|
||||
'lPIj/1/5UTwCNpKoFWVk2Cxe93+628d7ZCy+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EN82c+'
|
||||
'YV2DInlrSul1wftw3/zO4tpqd29YqkIyuEl2KWH2w8v7v4yZBKk='
|
||||
)
|
||||
@@ -0,0 +1,136 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
RUN_IN_TRANSACTION = True
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
CREATE TABLE IF NOT EXISTS "creative_media" (
|
||||
"id" UUID NOT NULL PRIMARY KEY,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted_at" TIMESTAMPTZ,
|
||||
"media_type" VARCHAR(32) NOT NULL,
|
||||
"media_file_id" VARCHAR(512) NOT NULL,
|
||||
"media_s3_key" VARCHAR(512),
|
||||
"position" INT NOT NULL,
|
||||
"creative_id" UUID NOT NULL REFERENCES "creative" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS "idx_creative_me_creativ_dbd1c4" ON "creative_media" ("creative_id");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "uid_creative_media_creative_pos" ON "creative_media" ("creative_id", "position");
|
||||
INSERT INTO "creative_media" (
|
||||
"id", "created_at", "updated_at", "deleted_at",
|
||||
"media_type", "media_file_id", "media_s3_key", "position", "creative_id"
|
||||
)
|
||||
SELECT
|
||||
gen_random_uuid(),
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
"media_type",
|
||||
"media_file_id",
|
||||
"media_s3_key",
|
||||
0,
|
||||
"id"
|
||||
FROM "creative"
|
||||
WHERE "media_file_id" IS NOT NULL AND "media_type" IS NOT NULL;
|
||||
ALTER TABLE "creative" DROP COLUMN "media_type";
|
||||
ALTER TABLE "creative" DROP COLUMN "media_s3_key";
|
||||
ALTER TABLE "creative" DROP COLUMN "media_file_id";"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
ALTER TABLE "creative" ADD "media_type" VARCHAR(32);
|
||||
ALTER TABLE "creative" ADD "media_s3_key" VARCHAR(512);
|
||||
ALTER TABLE "creative" ADD "media_file_id" VARCHAR(512);
|
||||
UPDATE "creative" AS c
|
||||
SET
|
||||
"media_type" = cm."media_type",
|
||||
"media_s3_key" = cm."media_s3_key",
|
||||
"media_file_id" = cm."media_file_id"
|
||||
FROM "creative_media" AS cm
|
||||
WHERE cm."creative_id" = c."id" AND cm."position" = 0;
|
||||
DROP TABLE IF EXISTS "creative_media";"""
|
||||
|
||||
|
||||
MODELS_STATE = (
|
||||
"eJztXe9zoroa/lccP+2Z6d1p1daezp07Yy27y1mrjtrunrPdYRBTyy2CB7Ddzpn+7ycBIi"
|
||||
"SAAqKCvl/cbpI3hCc/nydvwj/VmTFBmvWx/STrOtKqV5V/qro8Q/gPPuqkUpXncz+CBNjy"
|
||||
"WHPSKoFEY8s2ZcXGwY+yZiEcNEGWYqpzWzV0HKovNI0EGgpOqOpTP2ihq38vkGQbU2Q/IR"
|
||||
"NH/PiJg1V9gn4hi/53/iw9qkibMIVVJ+TZTrhkv82dsLs78eaTk5I8biwphraY6X7q+Zv9"
|
||||
"ZOjL5IuFOvlIbEjcFOnIlG00CbwGKaX3wjTILTEOsM0FWhZ14gdM0KO80AgY1f8+LnSFYF"
|
||||
"BxnkR+Gv+rpoBHMXQCrarbBIt/3t238t/ZCa2SR7W/tAYf6he/OW9pWPbUdCIdRKrvjqFs"
|
||||
"y66pg6sPpGIi8tqSbIcBvcExtjpD0aCylhy4E8/0I/0jC8g0wEfZb2EUZgpfNkyr+B0mPV"
|
||||
"1782pwBcYj8VYYjlq3ffImM8v6W3Mgao0EElNzQt+40A9ulRi4f7j9ZplJ5Zs4+lIh/638"
|
||||
"1esKfMUt043+qpIyyQvbkHTjVZIngcZGQykwOKVfsYv5JGPFspZQsXutWK/wfr3isRhlq1"
|
||||
"fWMod69Uq7w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CCxF"
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
module github.com/TelegramExchange/pkg
|
||||
|
||||
go 1.24.4
|
||||
|
||||
require (
|
||||
github.com/gotd/td v0.136.0
|
||||
github.com/jackc/pgx/v5 v5.7.6
|
||||
github.com/rs/zerolog v1.34.0
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gotd/td v0.136.0/go.mod h1:mStcqs/9FXhNhWnPTguptSwqkQbRIwXLw3SCSpzPJxM=
|
||||
github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
|
||||
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
@@ -0,0 +1,37 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
URL string `envconfig:"DB__URL" required:"true"`
|
||||
}
|
||||
|
||||
type Pool struct {
|
||||
*pgxpool.Pool
|
||||
}
|
||||
|
||||
func New(ctx context.Context, c Config) (*Pool, error) {
|
||||
cfg, err := pgxpool.ParseConfig(c.URL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("pgxpool.ParseConfig: %w", err)
|
||||
}
|
||||
|
||||
pool, err := pgxpool.NewWithConfig(ctx, cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("pgxpool.NewWithConfig: %w", err)
|
||||
}
|
||||
|
||||
return &Pool{Pool: pool}, nil
|
||||
}
|
||||
|
||||
func (p *Pool) Close() {
|
||||
p.Pool.Close()
|
||||
|
||||
log.Info().Msg("Postgres closed")
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/gotd/td/session"
|
||||
"github.com/gotd/td/telegram"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ApiID int `envconfig:"TELEGRAM__API_ID" required:"true"`
|
||||
ApiHash string `envconfig:"TELEGRAM__API_HASH" required:"true"`
|
||||
SessionFile string `envconfig:"TELEGRAM__SESSION_FILE" required:"true"`
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
*telegram.Client
|
||||
cancel context.CancelFunc
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func New(cfg Config) (*Client, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
tg := telegram.NewClient(cfg.ApiID, cfg.ApiHash, telegram.Options{
|
||||
SessionStorage: &session.FileStorage{Path: cfg.SessionFile},
|
||||
})
|
||||
|
||||
runCtx, cancel := context.WithCancel(ctx)
|
||||
|
||||
ready := make(chan struct{})
|
||||
done := make(chan struct{})
|
||||
|
||||
client := &Client{
|
||||
Client: tg,
|
||||
cancel: cancel,
|
||||
done: done,
|
||||
}
|
||||
|
||||
go func() {
|
||||
err := tg.Run(runCtx, func(ctx context.Context) error {
|
||||
status, err := tg.Auth().Status(ctx)
|
||||
if err != nil {
|
||||
close(ready)
|
||||
return fmt.Errorf("telegram.Auth error: %w", err)
|
||||
}
|
||||
if !status.Authorized {
|
||||
close(ready)
|
||||
return fmt.Errorf("session not authorized")
|
||||
}
|
||||
|
||||
// Получаем информацию о текущем пользователе
|
||||
self, err := tg.Self(ctx)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to get user info")
|
||||
} else {
|
||||
log.Info().
|
||||
Int64("id", self.ID).
|
||||
Str("username", "@"+self.Username).
|
||||
Str("first_name", self.FirstName).
|
||||
Str("last_name", self.LastName).
|
||||
Str("phone", self.Phone).
|
||||
Msg("Authorized as user")
|
||||
}
|
||||
|
||||
close(ready)
|
||||
|
||||
<-ctx.Done()
|
||||
return ctx.Err()
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("telegram client stopped")
|
||||
}
|
||||
|
||||
close(done)
|
||||
}()
|
||||
|
||||
<-ready
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func (c *Client) Close() {
|
||||
c.cancel()
|
||||
<-c.done
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package transaction
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/TelegramExchange/pkg/postgres"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var (
|
||||
errMissingInit = errors.New("missing `transaction.Init' call before `transaction.Begin'")
|
||||
errMissingBegin = errors.New("missing `transaction.Begin' call before 'transaction.Get'")
|
||||
)
|
||||
|
||||
var (
|
||||
pool *pgxpool.Pool
|
||||
IsUnitTest bool
|
||||
)
|
||||
|
||||
type ctxKey struct{}
|
||||
|
||||
func Init(p *postgres.Pool) {
|
||||
pool = p.Pool
|
||||
}
|
||||
|
||||
type Transaction struct {
|
||||
pgx.Tx
|
||||
}
|
||||
|
||||
func Begin(ctx context.Context) (context.Context, error) {
|
||||
if IsUnitTest {
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
if pool == nil {
|
||||
return nil, errMissingInit
|
||||
}
|
||||
|
||||
tx, err := pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("pool.Begin: %w", err)
|
||||
}
|
||||
|
||||
ctx = context.WithValue(ctx, ctxKey{}, &Transaction{tx})
|
||||
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
func Rollback(ctx context.Context) {
|
||||
if IsUnitTest {
|
||||
return
|
||||
}
|
||||
|
||||
tx, ok := ctx.Value(ctxKey{}).(*Transaction)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
err := tx.Rollback(ctx)
|
||||
if err != nil && !errors.Is(err, pgx.ErrTxClosed) {
|
||||
log.Error().Err(err).Msg("transaction: Rollback")
|
||||
}
|
||||
}
|
||||
|
||||
func Commit(ctx context.Context) error {
|
||||
if IsUnitTest {
|
||||
return nil
|
||||
}
|
||||
|
||||
tx, ok := ctx.Value(ctxKey{}).(*Transaction)
|
||||
if !ok {
|
||||
return errMissingBegin
|
||||
}
|
||||
|
||||
err := tx.Commit(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("tx.Commit: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type Executor interface {
|
||||
Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
|
||||
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
|
||||
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
|
||||
}
|
||||
|
||||
func TryExtractTX(ctx context.Context) Executor {
|
||||
tx, ok := ctx.Value(ctxKey{}).(*Transaction)
|
||||
if !ok {
|
||||
return pool
|
||||
}
|
||||
|
||||
return tx
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package transaction
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func Wrap(ctx context.Context, fn func(context.Context) error) error {
|
||||
tx, err := pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("pool.Begin: %w", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err = tx.Rollback(ctx)
|
||||
if err != nil && !errors.Is(err, pgx.ErrTxClosed) {
|
||||
log.Error().Err(err).Msg("transaction: Rollback")
|
||||
}
|
||||
}()
|
||||
|
||||
ctx = context.WithValue(ctx, ctxKey{}, &Transaction{tx})
|
||||
|
||||
err = fn(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("fn: %w", err)
|
||||
}
|
||||
|
||||
err = tx.Commit(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("tx.Commit: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
[project]
|
||||
name = "tgex-backend"
|
||||
version = "0.1.0"
|
||||
description = "Add your description here"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.13"
|
||||
dependencies = [
|
||||
"aerich>=0.9.2",
|
||||
"aioboto3>=13.3.0",
|
||||
"aiogram>=3.16.0",
|
||||
"aiolimiter>=1.2.1",
|
||||
"asyncpg>=0.30.0",
|
||||
"beautifulsoup4>=4.14.2",
|
||||
"fastapi>=0.121.0",
|
||||
"fastapi-pagination>=0.15.3",
|
||||
"httpx>=0.28.1",
|
||||
"lxml>=6.0.2",
|
||||
"pydantic-settings>=2.11.0",
|
||||
"pyjwt>=2.10.1",
|
||||
"python-multipart>=0.0.20",
|
||||
"tortoise-orm>=0.25.1",
|
||||
"tortoise-orm-stubs>=1.0.2",
|
||||
"types-aiobotocore-s3>=2.15.2",
|
||||
"uvicorn>=0.38.0",
|
||||
]
|
||||
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"mypy>=1.18.2",
|
||||
"pytest>=8.4.2",
|
||||
"pytest-asyncio>=1.2.0",
|
||||
"ruff>=0.14.4",
|
||||
"ty>=0.0.1a25",
|
||||
"vulture>=2.14",
|
||||
]
|
||||
|
||||
[tool.ruff]
|
||||
exclude = [".venv"]
|
||||
target-version = "py313"
|
||||
line-length = 120
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = [
|
||||
"E", # pycodestyle errors
|
||||
"F", # pyflakes
|
||||
"I", # isort
|
||||
"B", # flake8-bugbear
|
||||
"C4", # flake8-comprehensions
|
||||
"UP", # pyupgrade
|
||||
]
|
||||
ignore = ["B008"]
|
||||
fixable = ["ALL"]
|
||||
unfixable = []
|
||||
|
||||
[tool.ruff.format]
|
||||
quote-style = "single"
|
||||
|
||||
[tool.mypy]
|
||||
strict = true
|
||||
plugins = [
|
||||
"pydantic.mypy",
|
||||
]
|
||||
exclude = [
|
||||
"tests/conftest.py"
|
||||
]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
testpaths = ["tests"]
|
||||
pythonpath = ["src", "."]
|
||||
|
||||
[tool.aerich]
|
||||
tortoise_orm = "shared.datebase_base.TORTOISE_ORM"
|
||||
location = "./migrations"
|
||||
src_folder = "./."
|
||||
@@ -0,0 +1 @@
|
||||
"""Shared utilities package."""
|
||||
@@ -0,0 +1,36 @@
|
||||
import sys
|
||||
|
||||
from pydantic import ValidationError
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
RED = '\033[91m'
|
||||
YELLOW = '\033[33m'
|
||||
RESET = '\033[0m'
|
||||
BOLD = '\033[1m'
|
||||
|
||||
|
||||
def load_settings[T: BaseSettings](settings_class: type[T]) -> T:
|
||||
try:
|
||||
return settings_class()
|
||||
except ValidationError as e:
|
||||
print(f'{RED}{BOLD}Missing environment variables:{RESET}')
|
||||
|
||||
missing: set[str] = set()
|
||||
for err in e.errors():
|
||||
if err['type'] == 'missing' and len(err['loc']) == 1:
|
||||
field_info = settings_class.model_fields.get(str(err['loc'][0]))
|
||||
if field_info and field_info.annotation is not None and hasattr(field_info.annotation, 'model_fields'):
|
||||
annotation_fields = getattr(field_info.annotation, 'model_fields', {})
|
||||
for name, info in annotation_fields.items():
|
||||
if info.is_required():
|
||||
missing.add(f'{err["loc"][0]}__{name}'.upper())
|
||||
else:
|
||||
missing.add('__'.join(str(loc).upper() for loc in err['loc']))
|
||||
else:
|
||||
missing.add('__'.join(str(loc).upper() for loc in err['loc']))
|
||||
|
||||
for field_name in sorted(missing):
|
||||
print(f' {YELLOW}{field_name}{RESET}')
|
||||
|
||||
print(f'\n{RED}Check .env file or set required variables{RESET}')
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,85 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
import pydantic
|
||||
from tortoise import Tortoise
|
||||
|
||||
|
||||
class DatabaseConfig(pydantic.BaseModel):
|
||||
URL: pydantic.PostgresDsn
|
||||
ECHO: bool = False
|
||||
ECHO_POOL: bool = False
|
||||
POOL_SIZE: int = 50
|
||||
MAX_OVERFLOW: int = 10
|
||||
|
||||
|
||||
TORTOISE_ORM = {
|
||||
'connections': {'default': os.getenv('DB__URL')},
|
||||
'apps': {
|
||||
'models': {
|
||||
'models': ['src.domain', 'aerich.models'],
|
||||
'default_connection': 'default',
|
||||
},
|
||||
},
|
||||
'use_tz': True,
|
||||
'timezone': 'UTC',
|
||||
}
|
||||
|
||||
|
||||
class DatabaseBase:
|
||||
def __init__(self, config: DatabaseConfig) -> None:
|
||||
self.config = config
|
||||
|
||||
async def connect(self) -> None:
|
||||
if self.config.ECHO:
|
||||
logging.getLogger('tortoise.db_client').setLevel(logging.DEBUG)
|
||||
logging.getLogger('tortoise').setLevel(logging.DEBUG)
|
||||
|
||||
await Tortoise.init(
|
||||
db_url=str(self.config.URL),
|
||||
modules={'models': ['src.domain', 'aerich.models']},
|
||||
use_tz=True,
|
||||
timezone='UTC',
|
||||
)
|
||||
|
||||
await self.ping()
|
||||
await self._check_migrations()
|
||||
|
||||
async def close(self) -> None:
|
||||
await Tortoise.close_connections()
|
||||
|
||||
async def ping(self) -> None:
|
||||
from tortoise import connections
|
||||
|
||||
conn = connections.get('default')
|
||||
try:
|
||||
await conn.execute_query('SELECT 1')
|
||||
except Exception as e:
|
||||
import logging
|
||||
|
||||
logging.error(f'Database ping failed: {e}')
|
||||
raise
|
||||
|
||||
async def _check_migrations(self) -> None:
|
||||
import logging
|
||||
|
||||
from tortoise import connections
|
||||
|
||||
conn = connections.get('default')
|
||||
|
||||
# Проверяем существование таблицы aerich
|
||||
result = await conn.execute_query(
|
||||
"SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'aerich')"
|
||||
)
|
||||
if not result[1][0]['exists']:
|
||||
logging.warning('Migrations not applied. Run: aerich upgrade')
|
||||
return
|
||||
|
||||
# Получаем последнюю примененную версию
|
||||
try:
|
||||
result = await conn.execute_query('SELECT version, app FROM aerich ORDER BY id DESC LIMIT 1')
|
||||
if result[1]:
|
||||
current_version = result[1][0]['version']
|
||||
logging.info(f'Current migration version: {current_version}')
|
||||
except Exception as e:
|
||||
logging.debug(f'Could not check migration version: {e}')
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Build
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.19.x]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
- run: go build
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
name: Test
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.19.x]
|
||||
os: [ubuntu-latest]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
- run: go test -coverprofile=coverage.out -covermode=atomic
|
||||
|
||||
- uses: codecov/codecov-action@v4
|
||||
with:
|
||||
files: ./coverage.out
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
echotron
|
||||
Copyright (C) 2019 Nicolò Santamaria
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
echotron Copyright (C) 2019 Nicolò Santamaria
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
@@ -0,0 +1,339 @@
|
||||
| <img src="assets/readme_banner.png" alt="logo" width="800"><br/><br/> [](https://golang.org/) [](https://pkg.go.dev/github.com/NicoNex/echotron/v3) [](https://goreportcard.com/report/github.com/NicoNex/echotron/v3) [](https://codecov.io/gh/NicoNex/echotron) [](https://github.com/NicoNex/echotron/blob/master/LICENSE) [](https://github.com/avelino/awesome-go) [](https://t.me/echotronnews) |
|
||||
| :------: |
|
||||
|
||||
**Echotron** is an elegant and concurrent library for the Telegram bot API in Go.
|
||||
|
||||
Fetch with
|
||||
|
||||
```bash
|
||||
go get github.com/NicoNex/echotron/v3
|
||||
```
|
||||
|
||||
## Example
|
||||
### Simplest implementations
|
||||
#### Long polling
|
||||
```golang
|
||||
package main
|
||||
|
||||
import "github.com/NicoNex/echotron/v3"
|
||||
|
||||
const token = "MY TELEGRAM TOKEN"
|
||||
|
||||
func main() {
|
||||
api := echotron.NewAPI(token)
|
||||
|
||||
for u := range echotron.PollingUpdates(token) {
|
||||
if u.Message.Text == "/start" {
|
||||
api.SendMessage("Hello world", u.ChatID(), nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
#### Webhook
|
||||
```golang
|
||||
package main
|
||||
|
||||
import "github.com/NicoNex/echotron/v3"
|
||||
|
||||
const token = "MY TELEGRAM TOKEN"
|
||||
|
||||
func main() {
|
||||
api := echotron.NewAPI(token)
|
||||
|
||||
for u := range echotron.WebhookUpdates("https://example.com:443/my_token", token) {
|
||||
if u.Message.Text == "/start" {
|
||||
api.SendMessage("Hello world", u.ChatID(), nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
For more scalable and recommended implementations see the other examples.
|
||||
|
||||
### Long Polling
|
||||
|
||||
```golang
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/NicoNex/echotron/v3"
|
||||
)
|
||||
|
||||
// Struct useful for managing internal states in your bot, but it could be of
|
||||
// any type such as `type bot int64` if you only need to store the chatID.
|
||||
type bot struct {
|
||||
chatID int64
|
||||
echotron.API
|
||||
}
|
||||
|
||||
const token = "MY TELEGRAM TOKEN"
|
||||
|
||||
// This function needs to be of type 'echotron.NewBotFn' and is called by
|
||||
// the echotron dispatcher upon any new message from a chatID that has never
|
||||
// interacted with the bot before.
|
||||
// This means that echotron keeps one instance of the echotron.Bot implementation
|
||||
// for each chat where the bot is used.
|
||||
func newBot(chatID int64) echotron.Bot {
|
||||
return &bot{
|
||||
chatID,
|
||||
echotron.NewAPI(token),
|
||||
}
|
||||
}
|
||||
|
||||
// This method is needed to implement the echotron.Bot interface.
|
||||
func (b *bot) Update(update *echotron.Update) {
|
||||
if update.Message.Text == "/start" {
|
||||
b.SendMessage("Hello world", b.chatID, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// This is the entry point of echotron library.
|
||||
dsp := echotron.NewDispatcher(token, newBot)
|
||||
for {
|
||||
log.Println(dsp.Poll())
|
||||
// In case of connection issues wait 5 seconds before trying to reconnect.
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Design
|
||||
|
||||
**Echotron** makes a new instance of the struct bot for each open chat with a Telegram user, channel or group.
|
||||
This allows to:
|
||||
- safely call the `Update(*echotron.Update)` method concurrently
|
||||
- give to the user a convenient way to manage the bot internal states across all the chats
|
||||
- make sure that, even if one instance of the bot is deadlocked, the other ones keep running just fine, making the bot work for other users without any issues and/or slowdowns.
|
||||
|
||||
Please note that the the aforementioned behaviour is dictated by the `echotron.Dispatcher` object whose usage is not mandatory and for special needs can be ignored and implemented in different ways still keeping all the methods in the `echotron.API` object.
|
||||
|
||||
**Echotron** is designed to be as similar to the official [Telegram API](https://core.telegram.org/bots/api) as possible, but there are some things to take into account before starting to work with this library.
|
||||
|
||||
- The methods have the exact same name, but with a capital first letter, since in Go methods have to start with a capital letter to be exported.
|
||||
_Example: `sendMessage` becomes `SendMessage`_
|
||||
- The order of the parameters in some methods is different than in the official Telegram API, so refer to the [docs](https://pkg.go.dev/github.com/NicoNex/echotron/v3) for the correct one.
|
||||
- The only `chat_id` (or, in this case, `chatID`) type supported is `int64`, instead of the "Integer or String" requirement of the official API. That's because numeric IDs can't change in any way, which isn't the case with text-based usernames.
|
||||
- In some methods, you might find a `InputFile` type parameter. [`InputFile`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#InputFile) is a struct with unexported fields, since only three combination of fields are valid, which can be obtained through the methods [`NewInputFileID`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#NewInputFileID), [`NewInputFilePath`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#NewInputFilePath) and [`NewInputFileBytes`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#NewInputFileBytes).
|
||||
- In some methods, you might find a `MessageIDOptions` type parameter. [`MessageIDOptions`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#MessageIDOptions) is another struct with unexported fields, since only two combination of field are valid, which can be obtained through the methods [`NewMessageID`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#NewMessageID) and [`NewInlineMessageID`](https://pkg.go.dev/github.com/NicoNex/echotron/v3#NewInlineMessageID).
|
||||
- Optional parameters can be added by passing the correct struct to each method that might request optional parameters. If you don't want to pass any optional parameter, `nil` is more than enough. Refer to the [docs](https://pkg.go.dev/github.com/NicoNex/echotron/v3) to check for each method's optional parameters struct: it's the type of the `opts` parameter.
|
||||
- Some parameters are hardcoded to avoid putting random stuff which isn't recognized by the Telegram API. Some notable examples are [`ParseMode`](https://github.com/NicoNex/echotron/blob/master/options.go#L21), [`ChatAction`](https://github.com/NicoNex/echotron/blob/master/options.go#L54) and [`InlineQueryType`](https://github.com/NicoNex/echotron/blob/master/inline.go#L27). For a full list of custom hardcoded parameters, refer to the [docs](https://pkg.go.dev/github.com/NicoNex/echotron/v3) for each custom type: by clicking on the type's name, you'll get the source which contains the possible values for that type.
|
||||
|
||||
## Additional examples
|
||||
### Functional approach to state management
|
||||
```golang
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/NicoNex/echotron/v3"
|
||||
)
|
||||
|
||||
// Recursive type definition of the bot state function.
|
||||
type stateFn func(*echotron.Update) stateFn
|
||||
|
||||
type bot struct {
|
||||
chatID int64
|
||||
state stateFn
|
||||
name string
|
||||
echotron.API
|
||||
}
|
||||
|
||||
const token = "MY TELEGRAM TOKEN"
|
||||
|
||||
func newBot(chatID int64) echotron.Bot {
|
||||
bot := &bot{
|
||||
chatID: chatID,
|
||||
API: echotron.NewAPI(token),
|
||||
}
|
||||
// We set the default state to the bot.handleMessage method.
|
||||
bot.state = bot.handleMessage
|
||||
return bot
|
||||
}
|
||||
|
||||
func (b *bot) Update(update *echotron.Update) {
|
||||
// Here we execute the current state and set the next one.
|
||||
b.state = b.state(update)
|
||||
}
|
||||
|
||||
func (b *bot) handleMessage(update *echotron.Update) stateFn {
|
||||
if strings.HasPrefix(update.Message.Text, "/set_name") {
|
||||
b.SendMessage("Send me my new name!", b.chatID, nil)
|
||||
// Here we return b.handleName since next time we receive a message it
|
||||
// will be the new name.
|
||||
return b.handleName
|
||||
}
|
||||
return b.handleMessage
|
||||
}
|
||||
|
||||
func (b *bot) handleName(update *echotron.Update) stateFn {
|
||||
b.name = update.Message.Text
|
||||
b.SendMessage(fmt.Sprintf("My new name is %q", b.name), b.chatID, nil)
|
||||
// Here we return b.handleMessage since the next time we receive a message
|
||||
// it will be handled in the default way.
|
||||
return b.handleMessage
|
||||
}
|
||||
|
||||
func main() {
|
||||
dsp := echotron.NewDispatcher(token, newBot)
|
||||
log.Println(dsp.Poll())
|
||||
}
|
||||
```
|
||||
|
||||
### Self destruction for lower memory footprint
|
||||
```golang
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/NicoNex/echotron/v3"
|
||||
)
|
||||
|
||||
type bot struct {
|
||||
chatID int64
|
||||
echotron.API
|
||||
}
|
||||
|
||||
const token = "MY TELEGRAM TOKEN"
|
||||
|
||||
var dsp *echotron.Dispatcher
|
||||
|
||||
func newBot(chatID int64) echotron.Bot {
|
||||
bot := &bot{
|
||||
chatID,
|
||||
echotron.NewAPI(token),
|
||||
}
|
||||
go bot.selfDestruct(time.After(time.Hour))
|
||||
return bot
|
||||
}
|
||||
|
||||
func (b *bot) selfDestruct(timech <-chan time.Time) {
|
||||
<-timech
|
||||
b.SendMessage("goodbye", b.chatID, nil)
|
||||
dsp.DelSession(b.chatID)
|
||||
}
|
||||
|
||||
func (b *bot) Update(update *echotron.Update) {
|
||||
if update.Message.Text == "/start" {
|
||||
b.SendMessage("Hello world", b.chatID, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
dsp = echotron.NewDispatcher(token, newBot)
|
||||
log.Println(dsp.Poll())
|
||||
}
|
||||
```
|
||||
|
||||
### Webhook
|
||||
|
||||
```golang
|
||||
package main
|
||||
|
||||
import "github.com/NicoNex/echotron/v3"
|
||||
|
||||
type bot struct {
|
||||
chatID int64
|
||||
echotron.API
|
||||
}
|
||||
|
||||
const token = "MY TELEGRAM TOKEN"
|
||||
|
||||
func newBot(chatID int64) echotron.Bot {
|
||||
return &bot{
|
||||
chatID,
|
||||
echotron.NewAPI(token),
|
||||
}
|
||||
}
|
||||
|
||||
func (b *bot) Update(update *echotron.Update) {
|
||||
if update.Message.Text == "/start" {
|
||||
b.SendMessage("Hello world", b.chatID, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
dsp := echotron.NewDispatcher(token, newBot)
|
||||
dsp.ListenWebhook("https://example.com:443/my_bot_token")
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Webhook with a custom http.Server
|
||||
|
||||
This is an example for a custom http.Server which handles your own specified routes
|
||||
and also the webhook route which is specified by ListenWebhook.
|
||||
|
||||
```golang
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/NicoNex/echotron/v3"
|
||||
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
type bot struct {
|
||||
chatID int64
|
||||
echotron.API
|
||||
}
|
||||
|
||||
const token = "MY TELEGRAM TOKEN"
|
||||
|
||||
func newBot(chatID int64) echotron.Bot {
|
||||
return &bot{
|
||||
chatID,
|
||||
echotron.NewAPI(token),
|
||||
}
|
||||
}
|
||||
|
||||
func (b *bot) Update(update *echotron.Update) {
|
||||
if update.Message.Text == "/start" {
|
||||
b.SendMessage("Hello world", b.chatID, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
termChan := make(chan os.Signal, 1) // Channel for terminating the app via os.Interrupt signal
|
||||
signal.Notify(termChan, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) {
|
||||
// Handle user login
|
||||
})
|
||||
mux.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
|
||||
// Handle user logout
|
||||
})
|
||||
mux.HandleFunc("/about", func(w http.ResponseWriter, r *http.Request) {
|
||||
// Tell something about your awesome telegram bot
|
||||
})
|
||||
|
||||
// Set custom http.Server
|
||||
server := &http.Server{Addr: ":8080", Handler: mux}
|
||||
|
||||
go func() {
|
||||
<-termChan
|
||||
// Perform some cleanup..
|
||||
if err := server.Shutdown(context.Background()); err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Capture the interrupt signal for app termination handling
|
||||
dsp := echotron.NewDispatcher(token, newBot)
|
||||
dsp.SetHTTPServer(server)
|
||||
// Start your custom http.Server with a registered /my_bot_token handler.
|
||||
log.Println(dsp.ListenWebhook("https://example.com/my_bot_token"))
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2018 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import "fmt"
|
||||
|
||||
// APIError represents an error returned by the Telegram API.
|
||||
type APIError struct {
|
||||
desc string
|
||||
code int
|
||||
}
|
||||
|
||||
// ErrorCode returns the error code received from the Telegram API.
|
||||
func (a *APIError) ErrorCode() int {
|
||||
return a.code
|
||||
}
|
||||
|
||||
// Description returns the error description received from the Telegram API.
|
||||
func (a *APIError) Description() string {
|
||||
return a.desc
|
||||
}
|
||||
|
||||
// Error returns the error string.
|
||||
func (a *APIError) Error() string {
|
||||
return fmt.Sprintf("API error: %d %s", a.code, a.desc)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package echotron
|
||||
|
||||
import "testing"
|
||||
|
||||
var a APIError
|
||||
|
||||
func TestErrorCode(_ *testing.T) {
|
||||
a.ErrorCode()
|
||||
}
|
||||
|
||||
func TestDescription(_ *testing.T) {
|
||||
a.Description()
|
||||
}
|
||||
|
||||
func TestError(_ *testing.T) {
|
||||
_ = a.Error()
|
||||
}
|
||||
|
After Width: | Height: | Size: 580 KiB |
|
After Width: | Height: | Size: 214 KiB |
|
After Width: | Height: | Size: 222 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 6.2 KiB |
|
After Width: | Height: | Size: 17 KiB |
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2022 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
// ChatAdministratorRights represents the rights of an administrator in a chat.
|
||||
type ChatAdministratorRights struct {
|
||||
IsAnonymous bool `json:"is_anonymous"`
|
||||
CanManageChat bool `json:"can_manage_chat"`
|
||||
CanDeleteMessages bool `json:"can_delete_messages"`
|
||||
CanManageVideoChats bool `json:"can_manage_video_chats"`
|
||||
CanRestrictMembers bool `json:"can_restrict_members"`
|
||||
CanPromoteMembers bool `json:"can_promote_members"`
|
||||
CanChangeInfo bool `json:"can_change_info"`
|
||||
CanInviteUsers bool `json:"can_invite_users"`
|
||||
CanPostStories bool `json:"can_post_stories"`
|
||||
CanEditStories bool `json:"can_edit_stories"`
|
||||
CanDeleteStories bool `json:"can_delete_stories"`
|
||||
CanPostMessages bool `json:"can_post_messages,omitempty"`
|
||||
CanEditMessages bool `json:"can_edit_messages,omitempty"`
|
||||
CanPinMessages bool `json:"can_pin_messages,omitempty"`
|
||||
CanManageTopics bool `json:"can_manage_topics,omitempty"`
|
||||
}
|
||||
|
||||
// SetMyDefaultAdministratorRightsOptions contains the optional parameters used by
|
||||
// the SetMyDefaultAdministratorRights method.
|
||||
type SetMyDefaultAdministratorRightsOptions struct {
|
||||
Rights ChatAdministratorRights `query:"rights"`
|
||||
ForChannels bool `query:"for_channels"`
|
||||
}
|
||||
|
||||
// GetMyDefaultAdministratorRightsOptions contains the optional parameters used by
|
||||
// the GetMyDefaultAdministratorRights method.
|
||||
type GetMyDefaultAdministratorRightsOptions struct {
|
||||
ForChannels bool `query:"for_channels"`
|
||||
}
|
||||
|
||||
// SetMyDefaultAdministratorRights is used to change the default administrator rights
|
||||
// requested by the bot when it's added as an administrator to groups or channels.
|
||||
// These rights will be suggested to users, but they are are free to modify the list
|
||||
// before adding the bot.
|
||||
func (a API) SetMyDefaultAdministratorRights(opts *SetMyDefaultAdministratorRightsOptions) (res APIResponseBool, err error) {
|
||||
return res, client.get(a.base, "setMyDefaultAdministratorRights", urlValues(opts), &res)
|
||||
}
|
||||
|
||||
// GetMyDefaultAdministratorRights is used to get the current default administrator rights of the bot.
|
||||
func (a API) GetMyDefaultAdministratorRights(opts *GetMyDefaultAdministratorRightsOptions) (res APIResponseChatAdministratorRights, err error) {
|
||||
return res, client.get(a.base, "getMyDefaultAdministratorRights", urlValues(opts), &res)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
rights = ChatAdministratorRights{
|
||||
IsAnonymous: true,
|
||||
CanManageChat: true,
|
||||
CanDeleteMessages: true,
|
||||
CanManageVideoChats: true,
|
||||
CanRestrictMembers: true,
|
||||
CanPromoteMembers: true,
|
||||
CanChangeInfo: true,
|
||||
CanInviteUsers: true,
|
||||
CanPostStories: true,
|
||||
CanEditStories: true,
|
||||
CanDeleteStories: true,
|
||||
}
|
||||
)
|
||||
|
||||
func TestSetMyDefaultAdministratorRights(t *testing.T) {
|
||||
_, err := api.SetMyDefaultAdministratorRights(
|
||||
&SetMyDefaultAdministratorRightsOptions{
|
||||
Rights: rights,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMyDefaultAdministratorRights(t *testing.T) {
|
||||
res, err := api.GetMyDefaultAdministratorRights(nil)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(*res.Result, rights) {
|
||||
t.Logf("expected: %+v", rights)
|
||||
t.Logf("got: %+v", res.Result)
|
||||
t.Fatal("error: chat administrator rights mismatch")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2018 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type smap sync.Map
|
||||
|
||||
func (s *smap) load(id int64) (Bot, bool) {
|
||||
bot, ok := (*sync.Map)(s).Load(id)
|
||||
if ok {
|
||||
return bot.(Bot), ok
|
||||
}
|
||||
return nil, ok
|
||||
}
|
||||
|
||||
func (s *smap) store(id int64, bot Bot) {
|
||||
(*sync.Map)(s).Store(id, bot)
|
||||
}
|
||||
|
||||
func (s *smap) delete(id int64) {
|
||||
(*sync.Map)(s).Delete(id)
|
||||
}
|
||||
|
||||
// Bot is the interface that must be implemented by your definition of
|
||||
// the struct thus it represent each open session with a user on Telegram.
|
||||
type Bot interface {
|
||||
// Update will be called upon receiving any update from Telegram.
|
||||
Update(*Update)
|
||||
}
|
||||
|
||||
// NewBotFn is called every time echotron receives an update with a chat ID never
|
||||
// encountered before.
|
||||
type NewBotFn func(chatId int64) Bot
|
||||
|
||||
// The Dispatcher passes the updates from the Telegram Bot API to the Bot instance
|
||||
// associated with each chatID. When a new chat ID is found, the provided function
|
||||
// of type NewBotFn will be called.
|
||||
type Dispatcher struct {
|
||||
sessions smap
|
||||
newBot NewBotFn
|
||||
updates chan *Update
|
||||
httpServer *http.Server
|
||||
api API
|
||||
}
|
||||
|
||||
// NewDispatcher returns a new instance of the Dispatcher object.
|
||||
// Calls the Update function of the bot associated with each chat ID.
|
||||
// If a new chat ID is found, newBotFn will be called first.
|
||||
func NewDispatcher(token string, newBotFn NewBotFn) *Dispatcher {
|
||||
d := &Dispatcher{
|
||||
api: NewAPI(token),
|
||||
newBot: newBotFn,
|
||||
updates: make(chan *Update),
|
||||
}
|
||||
go d.listen()
|
||||
return d
|
||||
}
|
||||
|
||||
// DelSession deletes the Bot instance, seen as a session, from the
|
||||
// map with all of them.
|
||||
func (d *Dispatcher) DelSession(chatID int64) {
|
||||
d.sessions.delete(chatID)
|
||||
}
|
||||
|
||||
// AddSession allows to arbitrarily create a new Bot instance.
|
||||
func (d *Dispatcher) AddSession(chatID int64) {
|
||||
d.sessions.store(chatID, d.newBot(chatID))
|
||||
}
|
||||
|
||||
// Poll is a wrapper function for PollOptions.
|
||||
func (d *Dispatcher) Poll() error {
|
||||
return d.PollOptions(true, UpdateOptions{Timeout: 120})
|
||||
}
|
||||
|
||||
// PollOptions starts the polling loop so that the dispatcher calls the function Update
|
||||
// upon receiving any update from Telegram.
|
||||
func (d *Dispatcher) PollOptions(dropPendingUpdates bool, opts UpdateOptions) error {
|
||||
var (
|
||||
timeout = opts.Timeout
|
||||
isFirstRun = true
|
||||
)
|
||||
|
||||
// deletes webhook if present to run in long polling mode
|
||||
if _, err := d.api.DeleteWebhook(dropPendingUpdates); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
if isFirstRun {
|
||||
opts.Timeout = 0
|
||||
}
|
||||
|
||||
response, err := d.api.GetUpdates(&opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !dropPendingUpdates || !isFirstRun {
|
||||
for _, u := range response.Result {
|
||||
d.updates <- u
|
||||
}
|
||||
}
|
||||
|
||||
if l := len(response.Result); l > 0 {
|
||||
opts.Offset = response.Result[l-1].ID + 1
|
||||
}
|
||||
|
||||
if isFirstRun {
|
||||
isFirstRun = false
|
||||
opts.Timeout = timeout
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Dispatcher) instance(chatID int64) Bot {
|
||||
bot, ok := d.sessions.load(chatID)
|
||||
if !ok {
|
||||
bot = d.newBot(chatID)
|
||||
d.sessions.store(chatID, bot)
|
||||
}
|
||||
return bot
|
||||
}
|
||||
|
||||
func (d *Dispatcher) listen() {
|
||||
for update := range d.updates {
|
||||
bot := d.instance(update.ChatID())
|
||||
go bot.Update(update)
|
||||
}
|
||||
}
|
||||
|
||||
// ListenWebhook is a wrapper function for ListenWebhookOptions.
|
||||
func (d *Dispatcher) ListenWebhook(webhookURL string) error {
|
||||
return d.ListenWebhookOptions(webhookURL, false, nil)
|
||||
}
|
||||
|
||||
// ListenWebhookOptions sets a webhook and listens for incoming updates.
|
||||
// The webhookUrl should be provided in the following format: '<hostname>:<port>/<path>',
|
||||
// eg: 'https://example.com:443/bot_token'.
|
||||
// ListenWebhook will then proceed to communicate the webhook url '<hostname>/<path>' to Telegram
|
||||
// and run a webserver that listens to ':<port>' and handles the path.
|
||||
func (d *Dispatcher) ListenWebhookOptions(webhookURL string, dropPendingUpdates bool, opts *WebhookOptions) error {
|
||||
u, err := url.Parse(webhookURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
whURL := fmt.Sprintf("%s%s", u.Hostname(), u.EscapedPath())
|
||||
if _, err = d.api.SetWebhook(whURL, dropPendingUpdates, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if d.httpServer != nil {
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/", d.httpServer.Handler)
|
||||
mux.HandleFunc(u.EscapedPath(), d.HandleWebhook)
|
||||
d.httpServer.Handler = mux
|
||||
return d.httpServer.ListenAndServe()
|
||||
}
|
||||
http.HandleFunc(u.EscapedPath(), d.HandleWebhook)
|
||||
return http.ListenAndServe(fmt.Sprintf(":%s", u.Port()), nil)
|
||||
}
|
||||
|
||||
// SetHTTPServer allows to set a custom http.Server for ListenWebhook and ListenWebhookOptions.
|
||||
func (d *Dispatcher) SetHTTPServer(s *http.Server) {
|
||||
d.httpServer = s
|
||||
}
|
||||
|
||||
// HandleWebhook is the http.HandlerFunc for the webhook URL.
|
||||
// Useful if you've already a http server running and want to handle the request yourself.
|
||||
func (d *Dispatcher) HandleWebhook(w http.ResponseWriter, r *http.Request) {
|
||||
var update Update
|
||||
|
||||
jsn, err := readRequest(r)
|
||||
if err != nil {
|
||||
log.Println("echotron.Dispatcher", "HandleWebhook", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(jsn, &update); err != nil {
|
||||
log.Println("echotron.Dispatcher", "HandleWebhook", err)
|
||||
return
|
||||
}
|
||||
|
||||
d.updates <- &update
|
||||
}
|
||||
|
||||
func readRequest(r *http.Request) ([]byte, error) {
|
||||
switch r.Header.Get("Content-Encoding") {
|
||||
case "gzip":
|
||||
reader, err := gzip.NewReader(r.Body)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
defer reader.Close()
|
||||
return io.ReadAll(reader)
|
||||
|
||||
default:
|
||||
return io.ReadAll(r.Body)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type test struct{}
|
||||
|
||||
func (t test) Update(_ *Update) {}
|
||||
|
||||
var dsp *Dispatcher
|
||||
|
||||
func TestNewDispatcher(t *testing.T) {
|
||||
if dsp = NewDispatcher("token", func(_ int64) Bot { return test{} }); dsp == nil {
|
||||
t.Fatal("dispatcher is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddSession(t *testing.T) {
|
||||
dsp.AddSession(0)
|
||||
|
||||
if _, ok := dsp.sessions.load(0); !ok {
|
||||
t.Fatal("could not add session")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDelSession(t *testing.T) {
|
||||
dsp.DelSession(0)
|
||||
|
||||
if _, ok := dsp.sessions.load(0); ok {
|
||||
t.Fatal("could not delete session")
|
||||
}
|
||||
}
|
||||
|
||||
func TestListenWebhook(_ *testing.T) {
|
||||
dsp.ListenWebhook("http://example.com:8443/test")
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
func TestPoll(_ *testing.T) {
|
||||
dsp.Poll()
|
||||
|
||||
dsp.updates <- &Update{}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
ChatJoinRequest: &ChatJoinRequest{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
ChatBoost: &ChatBoostUpdated{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
RemovedChatBoost: &ChatBoostRemoved{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
Message: &Message{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
EditedMessage: &Message{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
ChannelPost: &Message{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
EditedChannelPost: &Message{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
BusinessConnection: &BusinessConnection{
|
||||
User: User{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
BusinessMessage: &Message{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
EditedBusinessMessage: &Message{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
DeletedBusinessMessages: &BusinessMessagesDeleted{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
MessageReaction: &MessageReactionUpdated{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
MessageReactionCount: &MessageReactionCountUpdated{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
InlineQuery: &InlineQuery{
|
||||
From: &User{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
ChosenInlineResult: &ChosenInlineResult{
|
||||
From: &User{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
CallbackQuery: &CallbackQuery{
|
||||
Message: &Message{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
ShippingQuery: &ShippingQuery{
|
||||
From: User{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
PreCheckoutQuery: &PreCheckoutQuery{
|
||||
From: User{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
PollAnswer: &PollAnswer{
|
||||
User: &User{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
MyChatMember: &ChatMemberUpdated{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
dsp.updates <- &Update{
|
||||
ChatMember: &ChatMemberUpdated{
|
||||
Chat: Chat{ID: 0},
|
||||
},
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2018 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import "net/url"
|
||||
|
||||
// Game represents a game.
|
||||
type Game struct {
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Photo []PhotoSize `json:"photo"`
|
||||
Text string `json:"text,omitempty"`
|
||||
TextEntities []MessageEntity `json:"text_entities,omitempty"`
|
||||
Animation Animation `json:"animation,omitempty"`
|
||||
}
|
||||
|
||||
// CallbackGame is a placeholder, currently holds no information.
|
||||
type CallbackGame struct{}
|
||||
|
||||
// GameHighScore represents one row of the high scores table for a game.
|
||||
type GameHighScore struct {
|
||||
User User `json:"user"`
|
||||
Position int `json:"position"`
|
||||
Score int `json:"score"`
|
||||
}
|
||||
|
||||
// GameScoreOptions contains the optional parameters used in SetGameScore method.
|
||||
type GameScoreOptions struct {
|
||||
Force bool `query:"force"`
|
||||
DisableEditMessage bool `query:"disable_edit_message"`
|
||||
}
|
||||
|
||||
// SendGame is used to send a Game.
|
||||
func (a API) SendGame(gameShortName string, chatID int64, opts *BaseOptions) (res APIResponseMessage, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("chat_id", itoa(chatID))
|
||||
vals.Set("game_short_name", gameShortName)
|
||||
return res, client.get(a.base, "sendGame", addValues(vals, opts), &res)
|
||||
}
|
||||
|
||||
// SetGameScore is used to set the score of the specified user in a game.
|
||||
func (a API) SetGameScore(userID int64, score int, msgID MessageIDOptions, opts *GameScoreOptions) (res APIResponseMessage, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("user_id", itoa(userID))
|
||||
vals.Set("score", itoa(int64(score)))
|
||||
return res, client.get(a.base, "setGameScore", addValues(addValues(vals, msgID), opts), &res)
|
||||
}
|
||||
|
||||
// GetGameHighScores is used to get data for high score tables.
|
||||
func (a API) GetGameHighScores(userID int64, opts MessageIDOptions) (res APIResponseGameHighScore, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("user_id", itoa(userID))
|
||||
return res, client.get(a.base, "getGameHighScores", addValues(vals, opts), &res)
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2018 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import "testing"
|
||||
|
||||
var (
|
||||
gameMsgTmp *Message
|
||||
highScores []*GameHighScore
|
||||
)
|
||||
|
||||
func TestSendGame(t *testing.T) {
|
||||
resp, err := api.SendGame(
|
||||
"echotron_coverage_game",
|
||||
chatID,
|
||||
nil,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
gameMsgTmp = resp.Result
|
||||
}
|
||||
|
||||
func TestGameHighScores(t *testing.T) {
|
||||
resp, err := api.GetGameHighScores(
|
||||
chatID,
|
||||
NewMessageID(chatID, gameMsgTmp.ID),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
highScores = resp.Result
|
||||
}
|
||||
|
||||
func TestSetGameScore(t *testing.T) {
|
||||
var score int
|
||||
|
||||
if len(highScores) > 0 {
|
||||
score = highScores[0].Score + 1
|
||||
}
|
||||
|
||||
_, err := api.SetGameScore(
|
||||
chatID,
|
||||
score,
|
||||
NewMessageID(chatID, gameMsgTmp.ID),
|
||||
&GameScoreOptions{
|
||||
Force: true,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
module github.com/NicoNex/echotron/v3
|
||||
|
||||
go 1.19
|
||||
|
||||
require golang.org/x/time v0.5.0
|
||||
@@ -0,0 +1,2 @@
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2018 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// content contains a file's name, its type and its data.
|
||||
type content struct {
|
||||
fname string
|
||||
ftype string
|
||||
fdata []byte
|
||||
}
|
||||
|
||||
func check(r APIResponse) error {
|
||||
if b := r.Base(); !b.Ok {
|
||||
return &APIError{code: b.ErrorCode, desc: b.Description}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func processMedia(media, thumbnail InputFile) (im mediaEnvelope, cnt []content, err error) {
|
||||
switch {
|
||||
case media.id != "":
|
||||
im = mediaEnvelope{
|
||||
media: media.id,
|
||||
thumbnail: "",
|
||||
}
|
||||
|
||||
case media.url != "":
|
||||
im = mediaEnvelope{
|
||||
media: media.url,
|
||||
thumbnail: "",
|
||||
}
|
||||
|
||||
case media.path != "" && len(media.content) == 0:
|
||||
if media.content, media.path, err = readFile(media); err != nil {
|
||||
return
|
||||
}
|
||||
fallthrough
|
||||
|
||||
case media.path != "" && len(media.content) > 0:
|
||||
cnt = append(cnt, content{media.path, media.path, media.content})
|
||||
im = mediaEnvelope{
|
||||
media: fmt.Sprintf("attach://%s", media.path),
|
||||
thumbnail: "",
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case thumbnail.path != "" && len(thumbnail.content) == 0:
|
||||
if thumbnail.content, thumbnail.path, err = readFile(thumbnail); err != nil {
|
||||
return
|
||||
}
|
||||
fallthrough
|
||||
|
||||
case thumbnail.path != "" && len(thumbnail.content) > 0:
|
||||
cnt = append(cnt, content{thumbnail.path, thumbnail.path, thumbnail.content})
|
||||
im.thumbnail = fmt.Sprintf("attach://%s", thumbnail.path)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func processSticker(sticker InputFile) (se stickerEnvelope, cnt []content, err error) {
|
||||
switch {
|
||||
case sticker.id != "":
|
||||
se.Sticker = sticker.id
|
||||
|
||||
case sticker.url != "":
|
||||
se.Sticker = sticker.url
|
||||
|
||||
case sticker.path != "" && len(sticker.content) == 0:
|
||||
if sticker.content, sticker.path, err = readFile(sticker); err != nil {
|
||||
return
|
||||
}
|
||||
fallthrough
|
||||
|
||||
case sticker.path != "" && len(sticker.content) > 0:
|
||||
cnt = append(cnt, content{sticker.path, sticker.path, sticker.content})
|
||||
se.Sticker = fmt.Sprintf("attach://%s", sticker.path)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func readFile(im InputFile) (content []byte, path string, err error) {
|
||||
content, err = os.ReadFile(im.path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
path = filepath.Base(im.path)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func toContent(ftype string, f InputFile) (content, error) {
|
||||
if f.path != "" && len(f.content) == 0 {
|
||||
var err error
|
||||
if f.content, f.path, err = readFile(f); err != nil {
|
||||
return content{}, err
|
||||
}
|
||||
}
|
||||
|
||||
return content{f.path, ftype, f.content}, nil
|
||||
}
|
||||
|
||||
func toInputMedia(media []GroupableInputMedia) (ret []InputMedia) {
|
||||
ret = make([]InputMedia, len(media))
|
||||
|
||||
for i, v := range media {
|
||||
ret[i] = v
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func joinURL(base, endpoint string, vals url.Values) (addr string, err error) {
|
||||
addr, err = url.JoinPath(base, endpoint)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if vals != nil {
|
||||
if queries := vals.Encode(); queries != "" {
|
||||
addr = fmt.Sprintf("%s?%s", addr, queries)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func itoa(i int64) string {
|
||||
return strconv.FormatInt(i, 10)
|
||||
}
|
||||
|
||||
func ftoa(f float64) string {
|
||||
return strconv.FormatFloat(f, 'f', -1, 64)
|
||||
}
|
||||
|
||||
func btoa(b bool) string {
|
||||
return strconv.FormatBool(b)
|
||||
}
|
||||
@@ -0,0 +1,601 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2018 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// InlineQueryType is a custom type for the various InlineQueryResult*'s Type field.
|
||||
type InlineQueryType string
|
||||
|
||||
// These are all the possible types for the various InlineQueryResult*'s Type field.
|
||||
const (
|
||||
InlineArticle InlineQueryType = "article"
|
||||
InlinePhoto = "photo"
|
||||
InlineGIF = "gif"
|
||||
InlineMPEG4GIF = "mpeg4_gif"
|
||||
InlineVideo = "video"
|
||||
InlineAudio = "audio"
|
||||
InlineVoice = "voice"
|
||||
InlineDocument = "document"
|
||||
InlineLocation = "location"
|
||||
InlineVenue = "venue"
|
||||
InlineContact = "contact"
|
||||
InlineGame = "game"
|
||||
InlineSticker = "sticker"
|
||||
)
|
||||
|
||||
// InlineQuery represents an incoming inline query.
|
||||
// When the user sends an empty query, your bot could return some default or trending results.
|
||||
type InlineQuery struct {
|
||||
From *User `json:"from"`
|
||||
Location *Location `json:"location,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Query string `json:"query"`
|
||||
Offset string `json:"offset"`
|
||||
ChatType string `json:"chat_type,omitempty"`
|
||||
}
|
||||
|
||||
// ChosenInlineResult represents a result of an inline query that was chosen by the user and sent to their chat partner.
|
||||
type ChosenInlineResult struct {
|
||||
ResultID string `json:"result_id"`
|
||||
From *User `json:"from"`
|
||||
Location *Location `json:"location,omitempty"`
|
||||
InlineMessageID string `json:"inline_message_id,omitempty"`
|
||||
Query string `json:"query"`
|
||||
}
|
||||
|
||||
// InlineQueryResult represents an interface that implements all the various InlineQueryResult* types.
|
||||
type InlineQueryResult interface {
|
||||
ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
// InlineQueryResultArticle represents a link to an article or web page.
|
||||
type InlineQueryResultArticle struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description,omitempty"`
|
||||
ThumbnailURL string `json:"thumbnail_url,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
ThumbnailWidth int `json:"thumbnail_width,omitempty"`
|
||||
ThumbnailHeight int `json:"thumbnail_height,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultArticle) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultPhoto represents a link to a photo.
|
||||
// By default, this photo will be sent by the user with optional caption.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the photo.
|
||||
type InlineQueryResultPhoto struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
ThumbnailURL string `json:"thumbnail_url"`
|
||||
PhotoURL string `json:"photo_url"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
PhotoHeight int `json:"photo_height,omitempty"`
|
||||
PhotoWidth int `json:"photo_width,omitempty"`
|
||||
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultPhoto) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultGif represents a link to an animated GIF file.
|
||||
// By default, this animated GIF file will be sent by the user with optional caption.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the animation.
|
||||
type InlineQueryResultGif struct {
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
GifURL string `json:"gif_url"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ThumbnailURL string `json:"thumbnail_url"`
|
||||
ID string `json:"id"`
|
||||
ThumbnailMimeType string `json:"thumbnail_mime_type,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
GifDuration int `json:"gif_duration,omitempty"`
|
||||
GifHeight int `json:"gif_height,omitempty"`
|
||||
GifWidth int `json:"gif_width,omitempty"`
|
||||
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultGif) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultMpeg4Gif represents a link to a video animation (H.264/MPEG-4 AVC video without sound).
|
||||
// By default, this animated MPEG-4 file will be sent by the user with optional caption.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the animation.
|
||||
type InlineQueryResultMpeg4Gif struct {
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Mpeg4URL string `json:"mpeg4_url"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ThumbnailURL string `json:"thumbnail_url"`
|
||||
ID string `json:"id"`
|
||||
ThumbnailMimeType string `json:"thumbnail_mime_type,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
Mpeg4Duration int `json:"mpeg4_duration,omitempty"`
|
||||
Mpeg4Height int `json:"mpeg4_height,omitempty"`
|
||||
Mpeg4Width int `json:"mpeg4_width,omitempty"`
|
||||
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultMpeg4Gif) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultVideo represents a link to a page containing an embedded video player or a video file.
|
||||
// By default, this video file will be sent by the user with an optional caption.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the video.
|
||||
type InlineQueryResultVideo struct {
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
MimeType string `json:"mime_type"`
|
||||
ThumbnailURL string `json:"thumbnail_url"`
|
||||
Title string `json:"title"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ID string `json:"id"`
|
||||
VideoURL string `json:"video_url"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
VideoHeight int `json:"video_height,omitempty"`
|
||||
VideoDuration int `json:"video_duration,omitempty"`
|
||||
VideoWidth int `json:"video_width,omitempty"`
|
||||
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultVideo) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultAudio represents a link to an MP3 audio file.
|
||||
// By default, this audio file will be sent by the user.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the audio.
|
||||
type InlineQueryResultAudio struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
ID string `json:"id"`
|
||||
AudioURL string `json:"audio_url"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
Performer string `json:"performer,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
AudioDuration int `json:"audio_duration,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultAudio) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultVoice represents a link to a voice recording in an .OGG container encoded with OPUS.
|
||||
// By default, this voice recording will be sent by the user.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the the voice message.
|
||||
type InlineQueryResultVoice struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
ID string `json:"id"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
VoiceURL string `json:"voice_url"`
|
||||
Title string `json:"title"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
VoiceDuration int `json:"voice_duration,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultVoice) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultDocument represents a link to a file.
|
||||
// By default, this file will be sent by the user with an optional caption.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the file.
|
||||
// Currently, only .PDF and .ZIP files can be sent using this method.
|
||||
type InlineQueryResultDocument struct {
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
MimeType string `json:"mime_type"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
ThumbnailURL string `json:"thumbnail_url,omitempty"`
|
||||
DocumentURL string `json:"document_url"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
ThumbnailWidth int `json:"thumbnail_width,omitempty"`
|
||||
ThumbnailHeight int `json:"thumbnail_height,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultDocument) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultLocation represents a location on a map.
|
||||
// By default, the location will be sent by the user.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the location.
|
||||
type InlineQueryResultLocation struct {
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
ID string `json:"id"`
|
||||
ThumbnailURL string `json:"thumbnail_url,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
LivePeriod int `json:"live_period,omitempty"`
|
||||
HorizontalAccuracy float64 `json:"horizontal_accuracy,omitempty"`
|
||||
ProximityAlertRadius int `json:"proximity_alert_radius,omitempty"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
Latitude float64 `json:"latitude"`
|
||||
ThumbnailWidth int `json:"thumbnail_width,omitempty"`
|
||||
ThumbnailHeight int `json:"thumbnail_height,omitempty"`
|
||||
Heading int `json:"heading,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultLocation) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultVenue represents a venue.
|
||||
// By default, the venue will be sent by the user.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the venue.
|
||||
type InlineQueryResultVenue struct {
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
GooglePlaceType string `json:"google_place_type,omitempty"`
|
||||
ThumbnailURL string `json:"thumbnail_url,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Address string `json:"address"`
|
||||
FoursquareID string `json:"foursquare_id,omitempty"`
|
||||
ID string `json:"id"`
|
||||
GooglePlaceID string `json:"google_place_id,omitempty"`
|
||||
FoursquareType string `json:"foursquare_type,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
Latitude float64 `json:"latitude"`
|
||||
ThumbnailWidth int `json:"thumbnail_width,omitempty"`
|
||||
ThumbnailHeight int `json:"thumbnail_height,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultVenue) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultContact represents a contact with a phone number.
|
||||
// By default, this contact will be sent by the user.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the contact.
|
||||
type InlineQueryResultContact struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
ID string `json:"id"`
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
FirstName string `json:"first_name"`
|
||||
VCard string `json:"vcard,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
ThumbnailURL string `json:"thumbnail_url,omitempty"`
|
||||
LastName string `json:"last_name,omitempty"`
|
||||
ThumbnailWidth int `json:"thumbnail_width,omitempty"`
|
||||
ThumbnailHeight int `json:"thumbnail_height,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultContact) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultGame represents a Game.
|
||||
type InlineQueryResultGame struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
ID string `json:"id"`
|
||||
GameShortName string `json:"game_short_name"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultGame) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultCachedPhoto represents a link to a photo stored on the Telegram servers.
|
||||
// By default, this photo will be sent by the user with an optional caption.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the photo.
|
||||
type InlineQueryResultCachedPhoto struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
ID string `json:"id"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
PhotoFileID string `json:"photo_file_id"`
|
||||
Title string `json:"title,omitempty"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultCachedPhoto) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultCachedGif represents a link to an animated GIF file stored on the Telegram servers.
|
||||
// By default, this animated GIF file will be sent by the user with an optional caption.
|
||||
// Alternatively, you can use InputMessageContent to send a message with specified content instead of the animation.
|
||||
type InlineQueryResultCachedGif struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
ID string `json:"id"`
|
||||
GifFileID string `json:"gif_file_id"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultCachedGif) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultCachedMpeg4Gif represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers.
|
||||
// By default, this animated MPEG-4 file will be sent by the user with an optional caption.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the animation.
|
||||
type InlineQueryResultCachedMpeg4Gif struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Mpeg4FileID string `json:"mpeg4_file_id"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultCachedMpeg4Gif) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultCachedSticker represents a link to a sticker stored on the Telegram servers.
|
||||
// By default, this sticker will be sent by the user.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the sticker.
|
||||
type InlineQueryResultCachedSticker struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
ID string `json:"id"`
|
||||
StickerFileID string `json:"sticker_file_id"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultCachedSticker) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultCachedDocument represents a link to a file stored on the Telegram servers.
|
||||
// By default, this file will be sent by the user with an optional caption.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the file.
|
||||
type InlineQueryResultCachedDocument struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
ID string `json:"id"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
Title string `json:"title"`
|
||||
DocumentFileID string `json:"document_file_id"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultCachedDocument) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultCachedVideo represents a link to a video file stored on the Telegram servers.
|
||||
// By default, this video file will be sent by the user with an optional caption.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the video.
|
||||
type InlineQueryResultCachedVideo struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
ID string `json:"id"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
VideoFileID string `json:"video_file_id"`
|
||||
Title string `json:"title"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultCachedVideo) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultCachedVoice represents a link to a voice message stored on the Telegram servers.
|
||||
// By default, this voice message will be sent by the user.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the voice message.
|
||||
type InlineQueryResultCachedVoice struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
Title string `json:"title"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
ID string `json:"id"`
|
||||
VoiceFileID string `json:"voice_file_id"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultCachedVoice) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InlineQueryResultCachedAudio represents a link to an MP3 audio file stored on the Telegram servers.
|
||||
// By default, this audio file will be sent by the user.
|
||||
// Alternatively, you can use InputMessageContent to send a message with the specified content instead of the audio.
|
||||
type InlineQueryResultCachedAudio struct {
|
||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
|
||||
AudioFileID string `json:"audio_file_id"`
|
||||
Caption string `json:"caption,omitempty"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
Type InlineQueryType `json:"type"`
|
||||
ID string `json:"id"`
|
||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.
|
||||
func (i InlineQueryResultCachedAudio) ImplementsInlineQueryResult() {}
|
||||
|
||||
// InputMessageContent represents an interface that implements all the various Input*MessageContent types.
|
||||
type InputMessageContent interface {
|
||||
ImplementsInputMessageContent()
|
||||
}
|
||||
|
||||
// InputTextMessageContent represents the content of a text message to be sent as the result of an inline query.
|
||||
type InputTextMessageContent struct {
|
||||
LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"`
|
||||
MessageText string `json:"message_text"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
Entities []*MessageEntity `json:"entities,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInputMessageContent is used to implement the InputMessageContent interface.
|
||||
func (i InputTextMessageContent) ImplementsInputMessageContent() {}
|
||||
|
||||
// InputLocationMessageContent represents the content of a location message to be sent as the result of an inline query.
|
||||
type InputLocationMessageContent struct {
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
HorizontalAccuracy float64 `json:"horizontal_accuracy,omitempty"`
|
||||
LivePeriod int `json:"live_period,omitempty"`
|
||||
Heading int `json:"heading,omitempty"`
|
||||
ProximityAlertRadius int `json:"proximity_alert_radius,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInputMessageContent is used to implement the InputMessageContent interface.
|
||||
func (i InputLocationMessageContent) ImplementsInputMessageContent() {}
|
||||
|
||||
// InputVenueMessageContent represents the content of a venue message to be sent as the result of an inline query.
|
||||
type InputVenueMessageContent struct {
|
||||
GooglePlaceID string `json:"google_place_id,omitempty"`
|
||||
GooglePlaceType string `json:"google_place_type,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Address string `json:"address"`
|
||||
FoursquareID string `json:"foursquare_id,omitempty"`
|
||||
FoursquareType string `json:"foursquare_type,omitempty"`
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
}
|
||||
|
||||
// ImplementsInputMessageContent is used to implement the InputMessageContent interface.
|
||||
func (i InputVenueMessageContent) ImplementsInputMessageContent() {}
|
||||
|
||||
// InputContactMessageContent represents the content of a contact message to be sent as the result of an inline query.
|
||||
type InputContactMessageContent struct {
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name,omitempty"`
|
||||
VCard string `json:"vcard,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInputMessageContent is used to implement the InputMessageContent interface.
|
||||
func (i InputContactMessageContent) ImplementsInputMessageContent() {}
|
||||
|
||||
// InputInvoiceMessageContent represents the content of an invoice message to be sent as the result of an inline query.
|
||||
type InputInvoiceMessageContent struct {
|
||||
SuggestedTipAmounts *[]int `json:"suggested_tip_amounts,omitempty"`
|
||||
PhotoURL string `json:"photo_url,omitempty"`
|
||||
Description string `json:"description"`
|
||||
Payload string `json:"string"`
|
||||
ProviderToken string `json:"provider_token,omitempty"`
|
||||
Currency string `json:"currency"`
|
||||
Title string `json:"title"`
|
||||
ProviderData string `json:"provider_data,omitempty"`
|
||||
Prices []LabeledPrice `json:"prices"`
|
||||
PhotoSize int `json:"photo_size,omitempty"`
|
||||
MaxTipAmount int `json:"max_tip_amount,omitempty"`
|
||||
PhotoWidth int `json:"photo_width,omitempty"`
|
||||
PhotoHeight int `json:"photo_height,omitempty"`
|
||||
NeedName bool `json:"need_name,omitempty"`
|
||||
NeedPhoneNumber bool `json:"need_phone_number,omitempty"`
|
||||
NeedEmail bool `json:"need_email,omitempty"`
|
||||
NeedShippingAddress bool `json:"need_shipping_address,omitempty"`
|
||||
SendPhoneNumberToProvider bool `json:"send_phone_number_to_provider,omitempty"`
|
||||
SendEmailToProvider bool `json:"send_email_to_provider,omitempty"`
|
||||
IsFlexible bool `json:"is_flexible,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsInputMessageContent is used to implement the InputMessageContent interface.
|
||||
func (i InputInvoiceMessageContent) ImplementsInputMessageContent() {}
|
||||
|
||||
// InlineQueryResultsButton represents a button to be shown above inline query results.
|
||||
// You MUST use exactly one of the fields.
|
||||
type InlineQueryResultsButton struct {
|
||||
WebApp WebAppInfo `json:"web_app,omitempty"`
|
||||
StartParameter string `json:"start_parameter,omitempty"`
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
// PreparedInlineMessage describes an inline message to be sent by a user of a Mini App.
|
||||
type PreparedInlineMessage struct {
|
||||
ID string `json:"id"`
|
||||
ExpirationDate int `json:"expiration_date"`
|
||||
}
|
||||
|
||||
// InlineQueryOptions is a custom type which contains the various options required by the AnswerInlineQuery method.
|
||||
type InlineQueryOptions struct {
|
||||
Button InlineQueryResultsButton `query:"button"`
|
||||
NextOffset string `query:"next_offset"`
|
||||
CacheTime int `query:"cache_time"`
|
||||
IsPersonal bool `query:"is_personal"`
|
||||
}
|
||||
|
||||
// PreparedInlineMessageOptions is a custom type which contains the various options required by the SavePreparedInlineMessage method.
|
||||
type PreparedInlineMessageOptions struct {
|
||||
AllowUserChats bool `query:"allow_user_chats"`
|
||||
AllowBotChats bool `query:"allow_bot_chats"`
|
||||
AllowGroupChats bool `query:"allow_group_chats"`
|
||||
AllowChannelChats bool `query:"allow_channel_chats"`
|
||||
}
|
||||
|
||||
// AnswerInlineQuery is used to send answers to an inline query.
|
||||
func (a API) AnswerInlineQuery(inlineQueryID string, results []InlineQueryResult, opts *InlineQueryOptions) (res APIResponseBase, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
jsn, _ := json.Marshal(results)
|
||||
vals.Set("inline_query_id", inlineQueryID)
|
||||
vals.Set("results", string(jsn))
|
||||
return res, client.get(a.base, "answerInlineQuery", addValues(vals, opts), &res)
|
||||
}
|
||||
|
||||
// SavePreparedInlineMessage stores a message that can be sent by a user of a Mini App.
|
||||
func (a API) SavePreparedInlineMessage(userID int64, result InlineQueryResult, opts *PreparedInlineMessageOptions) (res APIResponsePreparedInlineMessage, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
jsn, _ := json.Marshal(result)
|
||||
vals.Set("user_id", itoa(userID))
|
||||
vals.Set("result", string(jsn))
|
||||
return res, client.get(a.base, "savePreparedInlineMessage", addValues(vals, opts), &res)
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package echotron
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestInlineQueryResultArticle(_ *testing.T) {
|
||||
i := InlineQueryResultArticle{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultPhoto(_ *testing.T) {
|
||||
i := InlineQueryResultPhoto{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultGif(_ *testing.T) {
|
||||
i := InlineQueryResultGif{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultMpeg4Gif(_ *testing.T) {
|
||||
i := InlineQueryResultMpeg4Gif{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultVideo(_ *testing.T) {
|
||||
i := InlineQueryResultVideo{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultAudio(_ *testing.T) {
|
||||
i := InlineQueryResultAudio{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultVoice(_ *testing.T) {
|
||||
i := InlineQueryResultVoice{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultDocument(_ *testing.T) {
|
||||
i := InlineQueryResultDocument{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultLocation(_ *testing.T) {
|
||||
i := InlineQueryResultLocation{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultVenue(_ *testing.T) {
|
||||
i := InlineQueryResultVenue{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultContact(_ *testing.T) {
|
||||
i := InlineQueryResultContact{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultGame(_ *testing.T) {
|
||||
i := InlineQueryResultGame{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultCachedPhoto(_ *testing.T) {
|
||||
i := InlineQueryResultCachedPhoto{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultCachedGif(_ *testing.T) {
|
||||
i := InlineQueryResultCachedGif{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultCachedMpeg4Gif(_ *testing.T) {
|
||||
i := InlineQueryResultCachedMpeg4Gif{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultCachedSticker(_ *testing.T) {
|
||||
i := InlineQueryResultCachedSticker{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultCachedDocument(_ *testing.T) {
|
||||
i := InlineQueryResultCachedDocument{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultCachedVideo(_ *testing.T) {
|
||||
i := InlineQueryResultCachedVideo{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultCachedVoice(_ *testing.T) {
|
||||
i := InlineQueryResultCachedVoice{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInlineQueryResultCachedAudio(_ *testing.T) {
|
||||
i := InlineQueryResultCachedAudio{}
|
||||
i.ImplementsInlineQueryResult()
|
||||
}
|
||||
|
||||
func TestInputTextMessageContent(_ *testing.T) {
|
||||
i := InputTextMessageContent{}
|
||||
i.ImplementsInputMessageContent()
|
||||
}
|
||||
|
||||
func TestInputLocationMessageContent(_ *testing.T) {
|
||||
i := InputLocationMessageContent{}
|
||||
i.ImplementsInputMessageContent()
|
||||
}
|
||||
|
||||
func TestInputVenueMessageContent(_ *testing.T) {
|
||||
i := InputVenueMessageContent{}
|
||||
i.ImplementsInputMessageContent()
|
||||
}
|
||||
|
||||
func TestInputContactMessageContent(_ *testing.T) {
|
||||
i := InputContactMessageContent{}
|
||||
i.ImplementsInputMessageContent()
|
||||
}
|
||||
|
||||
func TestInputInvoiceMessageContent(_ *testing.T) {
|
||||
i := InputInvoiceMessageContent{}
|
||||
i.ImplementsInputMessageContent()
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2022 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
// MenuButtonType is a custom type for the various MenuButton*'s Type field.
|
||||
type MenuButtonType string
|
||||
|
||||
// These are all the possible types for the various MenuButton*'s Type field.
|
||||
const (
|
||||
MenuButtonTypeCommands MenuButtonType = "commands"
|
||||
MenuButtonTypeWebApp = "web_app"
|
||||
MenuButtonTypeDefault = "default"
|
||||
)
|
||||
|
||||
// MenuButton is a unique type for MenuButtonCommands, MenuButtonWebApp and MenuButtonDefault
|
||||
type MenuButton struct {
|
||||
WebApp *WebAppInfo `json:"web_app,omitempty"`
|
||||
Type MenuButtonType `json:"type"`
|
||||
Text string `json:"text,omitempty"`
|
||||
}
|
||||
|
||||
// SetChatMenuButtonOptions contains the optional parameters used by the SetChatMenuButton method.
|
||||
type SetChatMenuButtonOptions struct {
|
||||
MenuButton MenuButton `query:"menu_button"`
|
||||
ChatID int64 `query:"chat_id"`
|
||||
}
|
||||
|
||||
// GetChatMenuButtonOptions contains the optional parameters used by the GetChatMenuButton method.
|
||||
type GetChatMenuButtonOptions struct {
|
||||
ChatID int64 `query:"chat_id"`
|
||||
}
|
||||
|
||||
// SetChatMenuButton is used to change the bot's menu button in a private chat, or the default menu button.
|
||||
func (a API) SetChatMenuButton(opts *SetChatMenuButtonOptions) (res APIResponseBool, err error) {
|
||||
return res, client.get(a.base, "setChatMenuButton", urlValues(opts), &res)
|
||||
}
|
||||
|
||||
// GetChatMenuButton is used to get the current value of the bot's menu button in a private chat, or the default menu button.
|
||||
func (a API) GetChatMenuButton(opts *GetChatMenuButtonOptions) (res APIResponseMenuButton, err error) {
|
||||
return res, client.get(a.base, "getChatMenuButton", urlValues(opts), &res)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
menuBtn = MenuButton{
|
||||
Type: MenuButtonTypeCommands,
|
||||
}
|
||||
)
|
||||
|
||||
func TestSetChatMenuButton(t *testing.T) {
|
||||
_, err := api.SetChatMenuButton(
|
||||
&SetChatMenuButtonOptions{
|
||||
MenuButton: menuBtn,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetChatMenuButton(t *testing.T) {
|
||||
res, err := api.GetChatMenuButton(nil)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(*res.Result, menuBtn) {
|
||||
t.Logf("expected menu button: %+v", menuBtn)
|
||||
t.Logf("got menu button: %+v", res.Result)
|
||||
t.Fatal("error: menu buttons mismatch")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,437 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2018 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
type lclient struct {
|
||||
*http.Client
|
||||
*sync.RWMutex
|
||||
cl map[string]*rate.Limiter // chat based limiter
|
||||
gl *rate.Limiter // global limiter
|
||||
climiter func() *rate.Limiter
|
||||
}
|
||||
|
||||
var client = &lclient{
|
||||
Client: new(http.Client),
|
||||
RWMutex: new(sync.RWMutex),
|
||||
cl: make(map[string]*rate.Limiter),
|
||||
gl: rate.NewLimiter(rate.Every(time.Second/30), 30),
|
||||
climiter: func() *rate.Limiter {
|
||||
return rate.NewLimiter(rate.Every(time.Minute/20), 20)
|
||||
},
|
||||
}
|
||||
|
||||
// SetGlobalRequestLimit sets the global rate limit for requests to the Telegram API.
|
||||
// An interval of 0 disables the rate limiter, allowing unlimited requests.
|
||||
// By default the interval of this limiter is set to time.Second/30 and the
|
||||
// burstSize is set to 30.
|
||||
func SetGlobalRequestLimit(interval time.Duration, burstSize int) {
|
||||
client.Lock()
|
||||
client.gl = rate.NewLimiter(rate.Every(interval), burstSize)
|
||||
client.Unlock()
|
||||
}
|
||||
|
||||
// SetChatRequestLimit sets the per-chat rate limit for requests to the Telegram API.
|
||||
// An interval of 0 disables the rate limiter, allowing unlimited requests.
|
||||
// By default the interval of this limiter is set to time.Minute/20 and the
|
||||
// burstSize is set to 20.
|
||||
func SetChatRequestLimit(interval time.Duration, burstSize int) {
|
||||
client.Lock()
|
||||
client.cl = make(map[string]*rate.Limiter)
|
||||
client.climiter = func() *rate.Limiter {
|
||||
return rate.NewLimiter(rate.Every(interval), burstSize)
|
||||
}
|
||||
client.Unlock()
|
||||
}
|
||||
|
||||
func (c lclient) wait(chatID string) error {
|
||||
c.RLock()
|
||||
defer c.RUnlock()
|
||||
|
||||
ctx := context.Background()
|
||||
// If the chatID is empty, it's a general API call like GetUpdates, GetMe
|
||||
// and similar, so skip the per-chat request limit wait.
|
||||
if chatID != "" {
|
||||
// If no limiter exists for a chat, create one.
|
||||
l, ok := c.cl[chatID]
|
||||
if !ok {
|
||||
l = c.climiter()
|
||||
c.cl[chatID] = l
|
||||
}
|
||||
|
||||
// Make sure to respect the single chat limit of requests.
|
||||
if err := l.Wait(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure to respect the global limit of requests.
|
||||
return c.gl.Wait(ctx)
|
||||
}
|
||||
|
||||
func (c lclient) doGet(reqURL string) ([]byte, error) {
|
||||
resp, err := c.Get(reqURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (c lclient) doPost(reqURL string, files ...content) ([]byte, error) {
|
||||
var (
|
||||
buf = new(bytes.Buffer)
|
||||
w = multipart.NewWriter(buf)
|
||||
)
|
||||
|
||||
for _, f := range files {
|
||||
part, err := w.CreateFormFile(f.ftype, filepath.Base(f.fname))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
part.Write(f.fdata)
|
||||
}
|
||||
w.Close()
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, reqURL, buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Add("Content-Type", w.FormDataContentType())
|
||||
|
||||
res, err := c.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
return io.ReadAll(res.Body)
|
||||
}
|
||||
|
||||
func (c lclient) doPostForm(reqURL string, keyVals map[string]string) ([]byte, error) {
|
||||
var form = make(url.Values)
|
||||
|
||||
for k, v := range keyVals {
|
||||
form.Add(k, v)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, reqURL, strings.NewReader(form.Encode()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.PostForm = form
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
res, err := c.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
return io.ReadAll(res.Body)
|
||||
}
|
||||
|
||||
func (c lclient) sendFile(file, thumbnail InputFile, url, fileType string) (res []byte, err error) {
|
||||
var cnt []content
|
||||
|
||||
if file.id != "" {
|
||||
url = fmt.Sprintf("%s&%s=%s", url, fileType, file.id)
|
||||
} else if file.url != "" {
|
||||
url = fmt.Sprintf("%s&%s=%s", url, fileType, file.url)
|
||||
} else if c, e := toContent(fileType, file); e == nil {
|
||||
cnt = append(cnt, c)
|
||||
} else {
|
||||
err = e
|
||||
}
|
||||
|
||||
if c, e := toContent("thumbnail", thumbnail); e == nil {
|
||||
cnt = append(cnt, c)
|
||||
} else {
|
||||
err = e
|
||||
}
|
||||
|
||||
if len(cnt) > 0 {
|
||||
res, err = c.doPost(url, cnt...)
|
||||
} else {
|
||||
res, err = c.doGet(url)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c lclient) get(base, endpoint string, vals url.Values, v APIResponse) error {
|
||||
url, err := url.JoinPath(base, endpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vals != nil {
|
||||
if queries := vals.Encode(); queries != "" {
|
||||
url = fmt.Sprintf("%s?%s", url, queries)
|
||||
}
|
||||
}
|
||||
|
||||
if err := c.wait(vals.Get("chat_id")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cnt, err := c.doGet(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(cnt, v); err != nil {
|
||||
return err
|
||||
}
|
||||
return check(v)
|
||||
}
|
||||
|
||||
func (c lclient) postFile(base, endpoint, fileType string, file, thumbnail InputFile, vals url.Values, v APIResponse) error {
|
||||
url, err := joinURL(base, endpoint, vals)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.wait(vals.Get("chat_id")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cnt, err := c.sendFile(file, thumbnail, url, fileType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(cnt, v); err != nil {
|
||||
return err
|
||||
}
|
||||
return check(v)
|
||||
}
|
||||
|
||||
func (c lclient) postMedia(base, endpoint string, editSingle bool, vals url.Values, v APIResponse, files ...InputMedia) error {
|
||||
url, err := joinURL(base, endpoint, vals)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.wait(vals.Get("chat_id")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cnt, err := c.sendMediaFiles(url, editSingle, files...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(cnt, v); err != nil {
|
||||
return err
|
||||
}
|
||||
return check(v)
|
||||
}
|
||||
|
||||
func (c lclient) postStickers(base, endpoint string, vals url.Values, v APIResponse, stickers ...InputSticker) error {
|
||||
url, err := joinURL(base, endpoint, vals)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.wait(vals.Get("chat_id")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cnt, err := c.sendStickers(url, stickers...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := json.Unmarshal(cnt, v); err != nil {
|
||||
return err
|
||||
}
|
||||
return check(v)
|
||||
}
|
||||
|
||||
func (c lclient) postProfilePhoto(base, endpoint string, vals url.Values, v APIResponse, profilePhoto InputProfilePhoto) error {
|
||||
url, err := joinURL(base, endpoint, vals)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.wait(""); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cnt, err := c.sendProfilePhoto(url, profilePhoto)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := json.Unmarshal(cnt, v); err != nil {
|
||||
return err
|
||||
}
|
||||
return check(v)
|
||||
}
|
||||
|
||||
func (c lclient) sendMediaFiles(url string, editSingle bool, files ...InputMedia) (res []byte, err error) {
|
||||
var (
|
||||
med []mediaEnvelope
|
||||
cnt []content
|
||||
jsn []byte
|
||||
)
|
||||
|
||||
for _, file := range files {
|
||||
var im mediaEnvelope
|
||||
var cntArr []content
|
||||
|
||||
media := file.media()
|
||||
thumbnail := file.thumbnail()
|
||||
|
||||
im, cntArr, err = processMedia(media, thumbnail)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
im.InputMedia = file
|
||||
|
||||
med = append(med, im)
|
||||
cnt = append(cnt, cntArr...)
|
||||
}
|
||||
|
||||
if editSingle {
|
||||
jsn, err = json.Marshal(med[0])
|
||||
} else {
|
||||
jsn, err = json.Marshal(med)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
url = fmt.Sprintf("%s&media=%s", url, jsn)
|
||||
|
||||
if len(cnt) > 0 {
|
||||
return c.doPost(url, cnt...)
|
||||
}
|
||||
return c.doGet(url)
|
||||
}
|
||||
|
||||
func (c lclient) sendStickers(url string, stickers ...InputSticker) (res []byte, err error) {
|
||||
var (
|
||||
sti []stickerEnvelope
|
||||
cnt []content
|
||||
jsn []byte
|
||||
)
|
||||
|
||||
for _, s := range stickers {
|
||||
var se stickerEnvelope
|
||||
var cntArr []content
|
||||
|
||||
se, cntArr, err = processSticker(s.Sticker)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
se.InputSticker = s
|
||||
|
||||
sti = append(sti, se)
|
||||
cnt = append(cnt, cntArr...)
|
||||
}
|
||||
|
||||
if len(sti) == 1 {
|
||||
jsn, _ = json.Marshal(sti[0])
|
||||
url = fmt.Sprintf("%s&sticker=%s", url, jsn)
|
||||
} else {
|
||||
jsn, _ = json.Marshal(sti)
|
||||
url = fmt.Sprintf("%s&stickers=%s", url, jsn)
|
||||
}
|
||||
|
||||
if len(cnt) > 0 {
|
||||
return c.doPost(url, cnt...)
|
||||
}
|
||||
return c.doGet(url)
|
||||
}
|
||||
|
||||
func (c lclient) sendProfilePhoto(url string, profilePhoto InputProfilePhoto) (res []byte, err error) {
|
||||
var (
|
||||
pp profilePhotoEnvelope
|
||||
cnt []content
|
||||
jsn []byte
|
||||
)
|
||||
|
||||
file := profilePhoto.file()
|
||||
|
||||
switch file := file; {
|
||||
case file.id != "":
|
||||
pp.ProfilePhoto = file.id
|
||||
pp.Animation = file.id
|
||||
|
||||
case file.url != "":
|
||||
pp.ProfilePhoto = file.url
|
||||
pp.Animation = file.url
|
||||
|
||||
case file.path != "" && len(file.content) == 0:
|
||||
if file.content, file.path, err = readFile(file); err != nil {
|
||||
return
|
||||
}
|
||||
fallthrough
|
||||
|
||||
case file.path != "" && len(file.content) > 0:
|
||||
cnt = append(cnt, content{file.path, file.path, file.content})
|
||||
pp.ProfilePhoto = fmt.Sprintf("attach://%s", file.path)
|
||||
pp.Animation = fmt.Sprintf("attach://%s", file.path)
|
||||
}
|
||||
|
||||
switch profilePhoto.(type) {
|
||||
case InputProfilePhotoStatic:
|
||||
pp.Animation = ""
|
||||
case InputProfilePhotoAnimated:
|
||||
pp.ProfilePhoto = ""
|
||||
}
|
||||
|
||||
pp.InputProfilePhoto = profilePhoto
|
||||
jsn, err = json.Marshal(pp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sep := "?"
|
||||
if strings.Contains(url, "?") {
|
||||
sep = "&"
|
||||
}
|
||||
url = fmt.Sprintf("%s%sprofile_photo=%s", url, sep, jsn)
|
||||
|
||||
if len(cnt) > 0 {
|
||||
return c.doPost(url, cnt...)
|
||||
}
|
||||
return c.doGet(url)
|
||||
}
|
||||
@@ -0,0 +1,861 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2018 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
// ParseMode is a custom type for the various frequent options used by some methods of the API.
|
||||
type ParseMode string
|
||||
|
||||
// These are all the possible options that can be used by some methods.
|
||||
const (
|
||||
Markdown ParseMode = "Markdown"
|
||||
MarkdownV2 = "MarkdownV2"
|
||||
HTML = "HTML"
|
||||
)
|
||||
|
||||
// PollType is a custom type for the various types of poll that can be sent.
|
||||
type PollType string
|
||||
|
||||
// These are all the possible poll types.
|
||||
const (
|
||||
Quiz PollType = "quiz"
|
||||
Regular = "regular"
|
||||
Any = ""
|
||||
)
|
||||
|
||||
// DiceEmoji is a custom type for the various emojis that can be sent through the SendDice method.
|
||||
type DiceEmoji string
|
||||
|
||||
// These are all the possible emojis that can be sent through the SendDice method.
|
||||
const (
|
||||
Die DiceEmoji = "🎲"
|
||||
Darts = "🎯"
|
||||
Basket = "🏀"
|
||||
Goal = "⚽️"
|
||||
Bowling = "🎳"
|
||||
Slot = "🎰"
|
||||
)
|
||||
|
||||
// ChatAction is a custom type for the various actions that can be sent through the SendChatAction method.
|
||||
type ChatAction string
|
||||
|
||||
// These are all the possible actions that can be sent through the SendChatAction method.
|
||||
const (
|
||||
Typing ChatAction = "typing"
|
||||
UploadPhoto = "upload_photo"
|
||||
RecordVideo = "record_video"
|
||||
UploadVideo = "upload_video"
|
||||
RecordAudio = "record_audio"
|
||||
UploadAudio = "upload_audio"
|
||||
UploadDocument = "upload_document"
|
||||
FindLocation = "find_location"
|
||||
RecordVideoNote = "record_video_note"
|
||||
UploadVideoNote = "upload_video_note"
|
||||
ChooseSticker = "choose_sticker"
|
||||
)
|
||||
|
||||
// MessageEntityType is a custom type for the various MessageEntity types used in various methods.
|
||||
type MessageEntityType string
|
||||
|
||||
// These are all the possible types for MessageEntityType.
|
||||
const (
|
||||
MentionEntity MessageEntityType = "mention"
|
||||
HashtagEntity = "hashtag"
|
||||
CashtagEntity = "cashtag"
|
||||
BotCommandEntity = "bot_command"
|
||||
UrlEntity = "url"
|
||||
EmailEntity = "email"
|
||||
PhoneNumberEntity = "phone_number"
|
||||
BoldEntity = "bold"
|
||||
ItalicEntity = "italic"
|
||||
UnderlineEntity = "underline"
|
||||
StrikethroughEntity = "strikethrough"
|
||||
SpoilerEntity = "spoiler"
|
||||
BlockQuoteEntity = "blockquote"
|
||||
ExpandableBlockQuoteEntity = "expandable_blockquote"
|
||||
CodeEntity = "code"
|
||||
PreEntity = "pre"
|
||||
TextLinkEntity = "text_link"
|
||||
TextMentionEntity = "text_mention"
|
||||
CustomEmojiEntity = "custom_emoji"
|
||||
)
|
||||
|
||||
// UpdateType is a custom type for the various update types that a bot can be subscribed to.
|
||||
type UpdateType string
|
||||
|
||||
// These are all the possible types that a bot can be subscribed to.
|
||||
const (
|
||||
MessageUpdate UpdateType = "message"
|
||||
EditedMessageUpdate = "edited_message"
|
||||
ChannelPostUpdate = "channel_post"
|
||||
EditedChannelPostUpdate = "edited_channel_post"
|
||||
InlineQueryUpdate = "inline_query"
|
||||
ChosenInlineResultUpdate = "chosen_inline_result"
|
||||
CallbackQueryUpdate = "callback_query"
|
||||
ShippingQueryUpdate = "shipping_query"
|
||||
PreCheckoutQueryUpdate = "pre_checkout_query"
|
||||
PollUpdate = "poll"
|
||||
PollAnswerUpdate = "poll_answer"
|
||||
MyChatMemberUpdate = "my_chat_member"
|
||||
ChatMemberUpdate = "chat_member"
|
||||
)
|
||||
|
||||
// ReplyMarkup is an interface for the various keyboard types.
|
||||
type ReplyMarkup interface {
|
||||
ImplementsReplyMarkup()
|
||||
}
|
||||
|
||||
// KeyboardButton represents a button in a keyboard.
|
||||
type KeyboardButton struct {
|
||||
RequestPoll *KeyboardButtonPollType `json:"request_poll,omitempty"`
|
||||
WebApp *WebAppInfo `json:"web_app,omitempty"`
|
||||
RequestUsers *KeyboardButtonRequestUsers `json:"request_users,omitempty"`
|
||||
RequestChat *KeyboardButtonRequestChat `json:"request_chat,omitempty"`
|
||||
IconCustomEmojiID string `json:"icon_custom_emoji_id,omitempty"`
|
||||
Style ButtonStyle `json:"style,omitempty"`
|
||||
Text string `json:"text"`
|
||||
RequestContact bool `json:"request_contact,omitempty"`
|
||||
RequestLocation bool `json:"request_location,omitempty"`
|
||||
}
|
||||
|
||||
// ButtonStyle represents supported button style values.
|
||||
type ButtonStyle string
|
||||
|
||||
// These are all the possible values for ButtonStyle.
|
||||
const (
|
||||
PrimaryButtonStyle ButtonStyle = "primary"
|
||||
DangerButtonStyle = "danger"
|
||||
SuccessButtonStyle = "success"
|
||||
)
|
||||
|
||||
// KeyboardButtonPollType represents type of a poll, which is allowed to be created and sent when the corresponding button is pressed.
|
||||
type KeyboardButtonPollType struct {
|
||||
Type PollType `json:"type"`
|
||||
}
|
||||
|
||||
// KeyboardButtonRequestUsers defines the criteria used to request suitable users.
|
||||
// The identifiers of the selected users will be shared with the bot when the corresponding button is pressed.
|
||||
type KeyboardButtonRequestUsers struct {
|
||||
RequestID int `json:"request_id"`
|
||||
MaxQuantity int `json:"max_quantity,omitempty"`
|
||||
UserIsBot bool `json:"user_is_bot,omitempty"`
|
||||
UserIsPremium bool `json:"user_is_premium,omitempty"`
|
||||
RequestName bool `json:"request_name,omitempty"`
|
||||
RequestUsername bool `json:"request_username,omitempty"`
|
||||
RequestPhoto bool `json:"request_photo,omitempty"`
|
||||
}
|
||||
|
||||
// KeyboardButtonRequestChat defines the criteria used to request a suitable chat.
|
||||
// The identifier of the selected chat will be shared with the bot when the corresponding button is pressed.
|
||||
type KeyboardButtonRequestChat struct {
|
||||
UserAdministratorRights *ChatAdministratorRights `json:"user_administrator_rights,omitempty"`
|
||||
BotAdministratorRights *ChatAdministratorRights `json:"bot_administrator_rights,omitempty"`
|
||||
RequestID int `json:"request_id"`
|
||||
ChatIsChannel bool `json:"chat_is_channel,omitempty"`
|
||||
ChatIsForum bool `json:"chat_is_forum,omitempty"`
|
||||
ChatHasUsername bool `json:"chat_has_username,omitempty"`
|
||||
ChatIsCreated bool `json:"chat_is_created,omitempty"`
|
||||
BotIsMember bool `json:"bot_is_member,omitempty"`
|
||||
RequestName bool `json:"request_name,omitempty"`
|
||||
RequestUsername bool `json:"request_username,omitempty"`
|
||||
RequestPhoto bool `json:"request_photo,omitempty"`
|
||||
}
|
||||
|
||||
// ReplyKeyboardMarkup represents a custom keyboard with reply options.
|
||||
type ReplyKeyboardMarkup struct {
|
||||
InputFieldPlaceholder string `json:"input_field_placeholder,omitempty"`
|
||||
Keyboard [][]KeyboardButton `json:"keyboard"`
|
||||
IsPersistent bool `json:"is_persistent,omitempty"`
|
||||
ResizeKeyboard bool `json:"resize_keyboard,omitempty"`
|
||||
OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"`
|
||||
Selective bool `json:"selective,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsReplyMarkup is a dummy method which exists to implement the interface ReplyMarkup.
|
||||
func (i ReplyKeyboardMarkup) ImplementsReplyMarkup() {}
|
||||
|
||||
// ReplyKeyboardRemove is used to remove the current custom keyboard and display the default letter-keyboard.
|
||||
// By default, custom keyboards are displayed until a new keyboard is sent by a bot.
|
||||
// An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup).
|
||||
// RemoveKeyboard MUST BE true.
|
||||
type ReplyKeyboardRemove struct {
|
||||
RemoveKeyboard bool `json:"remove_keyboard"`
|
||||
Selective bool `json:"selective"`
|
||||
}
|
||||
|
||||
// ImplementsReplyMarkup is a dummy method which exists to implement the interface ReplyMarkup.
|
||||
func (r ReplyKeyboardRemove) ImplementsReplyMarkup() {}
|
||||
|
||||
// InlineKeyboardButton represents a button in an inline keyboard.
|
||||
type InlineKeyboardButton struct {
|
||||
CopyText *CopyTextButton `json:"copy_text,omitempty"`
|
||||
CallbackGame *CallbackGame `json:"callback_game,omitempty"`
|
||||
WebApp *WebAppInfo `json:"web_app,omitempty"`
|
||||
LoginURL *LoginURL `json:"login_url,omitempty"`
|
||||
SwitchInlineQueryChosenChat *SwitchInlineQueryChosenChat `json:"switch_inline_query_chosen_chat,omitempty"`
|
||||
IconCustomEmojiID string `json:"icon_custom_emoji_id,omitempty"`
|
||||
Style ButtonStyle `json:"style,omitempty"`
|
||||
Text string `json:"text"`
|
||||
CallbackData string `json:"callback_data,omitempty"`
|
||||
SwitchInlineQuery string `json:"switch_inline_query,omitempty"`
|
||||
SwitchInlineQueryCurrentChat string `json:"switch_inline_query_current_chat,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
Pay bool `json:"pay,omitempty"`
|
||||
}
|
||||
|
||||
// CopyTextButton represents an inline keyboard button that copies specified text to the clipboard.
|
||||
type CopyTextButton struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
// InlineKeyboardMarkup represents an inline keyboard.
|
||||
type InlineKeyboardMarkup struct {
|
||||
InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard" query:"inline_keyboard"`
|
||||
}
|
||||
|
||||
// ImplementsReplyMarkup is a dummy method which exists to implement the interface ReplyMarkup.
|
||||
func (i InlineKeyboardMarkup) ImplementsReplyMarkup() {}
|
||||
|
||||
// ForceReply is used to display a reply interface to the user (act as if the user has selected the bot's message and tapped 'Reply').
|
||||
// This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode.
|
||||
type ForceReply struct {
|
||||
InputFieldPlaceholder string `json:"input_field_placeholder,omitempty"`
|
||||
ForceReply bool `json:"force_reply"`
|
||||
Selective bool `json:"selective"`
|
||||
}
|
||||
|
||||
// ImplementsReplyMarkup is a dummy method which exists to implement the interface ReplyMarkup.
|
||||
func (f ForceReply) ImplementsReplyMarkup() {}
|
||||
|
||||
// UpdateOptions contains the optional parameters used by the GetUpdates method.
|
||||
type UpdateOptions struct {
|
||||
AllowedUpdates []UpdateType `query:"allowed_updates"`
|
||||
Offset int `query:"offset"`
|
||||
Limit int `query:"limit"`
|
||||
Timeout int `query:"timeout"`
|
||||
}
|
||||
|
||||
// WebhookOptions contains the optional parameters used by the SetWebhook method.
|
||||
type WebhookOptions struct {
|
||||
IPAddress string `query:"ip_address"`
|
||||
SecretToken string `query:"secret_token"`
|
||||
Certificate InputFile
|
||||
AllowedUpdates []UpdateType `query:"allowed_updates"`
|
||||
MaxConnections int `query:"max_connections"`
|
||||
}
|
||||
|
||||
// BaseOptions contains the optional parameters used frequently in some Telegram API methods.
|
||||
type BaseOptions struct {
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// MessageOptions contains the optional parameters used by some Telegram API methods.
|
||||
type MessageOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ParseMode ParseMode `query:"parse_mode"`
|
||||
LinkPreviewOptions LinkPreviewOptions `query:"link_preview_options"`
|
||||
Entities []MessageEntity `query:"entities"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int64 `query:"message_thread_id"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// PinMessageOptions contains the optional parameters used by the PinChatMember method.
|
||||
type PinMessageOptions struct {
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
}
|
||||
|
||||
// UnpinMessageOptions contains the optional parameters used by the UnpinChatMember method.
|
||||
type UnpinMessageOptions struct {
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
MessageID int `query:"message_id"`
|
||||
}
|
||||
|
||||
// ForwardOptions contains the optional parameters used by the ForwardMessage method.
|
||||
type ForwardOptions struct {
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
VideoStartTimestamp int `query:"video_start_timestamp"`
|
||||
}
|
||||
|
||||
// CopyOptions contains the optional parameters used by the CopyMessage method.
|
||||
type CopyOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
ParseMode ParseMode `query:"parse_mode"`
|
||||
Caption string `query:"caption"`
|
||||
CaptionEntities []MessageEntity `query:"caption_entities"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
ShowCaptionAboveMedia bool `query:"show_caption_above_media"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// CopyMessagesOptions contains the optional parameters used by the CopyMessages methods.
|
||||
type CopyMessagesOptions struct {
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
RemoveCaption bool `query:"remove_caption"`
|
||||
VideoStartTimestamp int `query:"video_start_timestamp"`
|
||||
}
|
||||
|
||||
// StickerOptions contains the optional parameters used by the SendSticker method.
|
||||
type StickerOptions struct {
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
Emoji string `query:"emoji"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// InputFile is a struct which contains data about a file to be sent.
|
||||
type InputFile struct {
|
||||
id string
|
||||
path string
|
||||
url string
|
||||
content []byte
|
||||
}
|
||||
|
||||
// NewInputFileID is a wrapper for InputFile which only fills the id field.
|
||||
func NewInputFileID(ID string) InputFile {
|
||||
return InputFile{id: ID}
|
||||
}
|
||||
|
||||
// NewInputFilePath is a wrapper for InputFile which only fills the path field.
|
||||
func NewInputFilePath(filePath string) InputFile {
|
||||
return InputFile{path: filePath}
|
||||
}
|
||||
|
||||
// NewInputFileURL is a wrapper for InputFile which only fills the url field.
|
||||
func NewInputFileURL(url string) InputFile {
|
||||
return InputFile{url: url}
|
||||
}
|
||||
|
||||
// NewInputFileBytes is a wrapper for InputFile which only fills the path and content fields.
|
||||
func NewInputFileBytes(fileName string, content []byte) InputFile {
|
||||
return InputFile{path: fileName, content: content}
|
||||
}
|
||||
|
||||
// PhotoOptions contains the optional parameters used by the SendPhoto method.
|
||||
type PhotoOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ParseMode ParseMode `query:"parse_mode"`
|
||||
Caption string `query:"caption"`
|
||||
CaptionEntities []MessageEntity `query:"caption_entities"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
HasSpoiler bool `query:"has_spoiler"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
ShowCaptionAboveMedia bool `query:"show_caption_above_media"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// AudioOptions contains the optional parameters used by the SendAudio method.
|
||||
type AudioOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
Title string `query:"title"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ParseMode ParseMode `query:"parse_mode"`
|
||||
Caption string `query:"caption"`
|
||||
Performer string `query:"performer"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
Thumbnail InputFile
|
||||
CaptionEntities []MessageEntity `query:"caption_entities"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
Duration int `query:"duration"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// DocumentOptions contains the optional parameters used by the SendDocument method.
|
||||
type DocumentOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ParseMode ParseMode `query:"parse_mode"`
|
||||
Caption string `query:"caption"`
|
||||
Thumbnail InputFile
|
||||
CaptionEntities []MessageEntity `query:"caption_entities"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
DisableContentTypeDetection bool `query:"disable_content_type_detection"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// VideoOptions contains the optional parameters used by the SendVideo method.
|
||||
// TODO: handle the cover correctly.
|
||||
type VideoOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
Caption string `query:"caption"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ParseMode ParseMode `query:"parse_mode"`
|
||||
Thumbnail InputFile
|
||||
CaptionEntities []MessageEntity `query:"caption_entities"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
Duration int `query:"duration"`
|
||||
Width int `query:"width"`
|
||||
Height int `query:"height"`
|
||||
HasSpoiler bool `query:"has_spoiler"`
|
||||
SupportsStreaming bool `query:"supports_streaming"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
ShowCaptionAboveMedia bool `query:"show_caption_above_media"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
Cover InputFile
|
||||
StartTimestamp int `query:"start_timestamp"`
|
||||
}
|
||||
|
||||
// AnimationOptions contains the optional parameters used by the SendAnimation method.
|
||||
type AnimationOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ParseMode ParseMode `query:"parse_mode"`
|
||||
Caption string `query:"caption"`
|
||||
Thumbnail InputFile
|
||||
CaptionEntities []MessageEntity `query:"caption_entities"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
Duration int `query:"duration"`
|
||||
Width int `query:"width"`
|
||||
Height int `query:"height"`
|
||||
HasSpoiler bool `query:"has_spoiler"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
ShowCaptionAboveMedia bool `query:"show_caption_above_media"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// VoiceOptions contains the optional parameters used by the SendVoice method.
|
||||
type VoiceOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ParseMode ParseMode `query:"parse_mode"`
|
||||
Caption string `query:"caption"`
|
||||
CaptionEntities []MessageEntity `query:"caption_entities"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
Duration int `query:"duration"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// VideoNoteOptions contains the optional parameters used by the SendVideoNote method.
|
||||
type VideoNoteOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
Thumbnail InputFile
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
Duration int `query:"duration"`
|
||||
Length int `query:"length"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// PaidMediaOptions contains the optional parameters used by the SendPaidMedia method.
|
||||
type PaidMediaOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
Caption string `query:"caption"`
|
||||
Payload string `query:"payload"`
|
||||
ParseMode ParseMode `query:"parse_mode"`
|
||||
CaptionEntities []MessageEntity `query:"caption_entities"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
ShowCaptionAboveMedia bool `query:"show_caption_above_media"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// MediaGroupOptions contains the optional parameters used by the SendMediaGroup method.
|
||||
type MediaGroupOptions struct {
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// This is a custom constant to set an infinite live period value in LocationOptions and EditLocationOptions.
|
||||
const InfiniteLivePeriod = 0x7FFFFFFF
|
||||
|
||||
// LocationOptions contains the optional parameters used by the SendLocation method.
|
||||
type LocationOptions struct {
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
HorizontalAccuracy float64 `query:"horizontal_accuracy"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
LivePeriod int `query:"live_period"`
|
||||
ProximityAlertRadius int `query:"proximity_alert_radius"`
|
||||
Heading int `query:"heading"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// EditLocationOptions contains the optional parameters used by the EditMessageLiveLocation method.
|
||||
type EditLocationOptions struct {
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
ReplyMarkup InlineKeyboardMarkup `query:"reply_markup"`
|
||||
HorizontalAccuracy float64 `query:"horizontal_accuracy"`
|
||||
Heading int `query:"heading"`
|
||||
LivePeriod int `query:"live_period"`
|
||||
ProximityAlertRadius int `query:"proximity_alert_radius"`
|
||||
}
|
||||
|
||||
// StopLocationOptions contains the optional parameters used by the StopMessageLiveLocation method.
|
||||
type StopLocationOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
}
|
||||
|
||||
// VenueOptions contains the optional parameters used by the SendVenue method.
|
||||
type VenueOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
FoursquareID string `query:"foursquare_id"`
|
||||
FoursquareType string `query:"foursquare_type"`
|
||||
GooglePlaceType string `query:"google_place_type"`
|
||||
GooglePlaceID string `query:"google_place_id"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// ContactOptions contains the optional parameters used by the SendContact method.
|
||||
type ContactOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
VCard string `query:"vcard"`
|
||||
LastName string `query:"last_name"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// PollOptions contains the optional parameters used by the SendPoll method.
|
||||
type PollOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
Explanation string `query:"explanation"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ExplanationParseMode ParseMode `query:"explanation_parse_mode"`
|
||||
QuestionParseMode ParseMode `query:"question_parse_mode"`
|
||||
Type PollType `query:"type"`
|
||||
ExplanationEntities []MessageEntity `query:"explanation_entities"`
|
||||
QuestionEntities []MessageEntity `query:"question_entities"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
CorrectOptionID int `query:"correct_option_id"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
CloseDate int `query:"close_date"`
|
||||
OpenPeriod int `query:"open_period"`
|
||||
IsClosed bool `query:"is_closed"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
AllowsMultipleAnswers bool `query:"allows_multiple_answers"`
|
||||
IsAnonymous bool `query:"is_anonymous"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// StopPollOptions contains the optional parameters used by the StopPoll method.
|
||||
type StopPollOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
}
|
||||
|
||||
// BanOptions contains the optional parameters used by the BanChatMember method.
|
||||
type BanOptions struct {
|
||||
UntilDate int `query:"until_date"`
|
||||
RevokeMessages bool `query:"revoke_messages"`
|
||||
}
|
||||
|
||||
// UnbanOptions contains the optional parameters used by the UnbanChatMember method.
|
||||
type UnbanOptions struct {
|
||||
OnlyIfBanned bool `query:"only_if_banned"`
|
||||
}
|
||||
|
||||
// RestrictOptions contains the optional parameters used by the RestrictChatMember method.
|
||||
type RestrictOptions struct {
|
||||
UseIndependentChatPermissions bool `query:"use_independent_chat_permissions"`
|
||||
UntilDate int `query:"until_date"`
|
||||
}
|
||||
|
||||
// PromoteOptions contains the optional parameters used by the PromoteChatMember method.
|
||||
type PromoteOptions struct {
|
||||
IsAnonymous bool `query:"is_anonymous,omitempty"`
|
||||
CanManageChat bool `query:"can_manage_chat,omitempty"`
|
||||
CanPostMessages bool `query:"can_post_messages,omitempty"`
|
||||
CanEditMessages bool `query:"can_edit_messages,omitempty"`
|
||||
CanDeleteMessages bool `query:"can_delete_messages,omitempty"`
|
||||
CanManageVideoChats bool `query:"can_manage_video_chats,omitempty"`
|
||||
CanRestrictMembers bool `query:"can_restrict_members,omitempty"`
|
||||
CanPromoteMembers bool `query:"can_promote_members,omitempty"`
|
||||
CanChangeInfo bool `query:"can_change_info,omitempty"`
|
||||
CanInviteUsers bool `query:"can_invite_users,omitempty"`
|
||||
CanPinMessages bool `query:"can_pin_messages,omitempty"`
|
||||
CanPostStories bool `json:"can_post_stories,omitempty"`
|
||||
CanEditStories bool `json:"can_edit_stories,omitempty"`
|
||||
CanDeleteStories bool `json:"can_delete_stories,omitempty"`
|
||||
CanManageTopics bool `query:"can_manage_topics,omitempty"`
|
||||
}
|
||||
|
||||
// UserProfileOptions contains the optional parameters used by the GetUserProfilePhotos method.
|
||||
type UserProfileOptions struct {
|
||||
Offset int `query:"offset"`
|
||||
Limit int `query:"limit"`
|
||||
}
|
||||
|
||||
// UserProfileAudioOptions contains the optional parameters used by the GetUserProfileAudios method.
|
||||
type UserProfileAudioOptions struct {
|
||||
Offset int `query:"offset"`
|
||||
Limit int `query:"limit"`
|
||||
}
|
||||
|
||||
// UserEmojiStatusOptions contains the optional parameters used by the SetUserEmojiStatus method.
|
||||
type UserEmojiStatusOptions struct {
|
||||
EmojiStatusCustomEmojiID string `query:"emoji_status_custom_emoji_id"`
|
||||
EmojiStatusExpirationDate string `query:"emoji_status_expiration_date"`
|
||||
}
|
||||
|
||||
// ChatPermissionsOptions contains the optional parameters used by the SetChatPermissions method.
|
||||
type ChatPermissionsOptions struct {
|
||||
UseIndependentChatPermissions bool `query:"use_independent_chat_permissions"`
|
||||
}
|
||||
|
||||
// InviteLinkOptions contains the optional parameters used by the CreateChatInviteLink and EditChatInviteLink methods.
|
||||
type InviteLinkOptions struct {
|
||||
Name string `query:"name"`
|
||||
ExpireDate int64 `query:"expire_date"`
|
||||
MemberLimit int `query:"member_limit"`
|
||||
CreatesJoinRequest bool `query:"creates_join_request"`
|
||||
}
|
||||
|
||||
// ChatSubscriptionInviteOptions contains the optional parameters used by the CreateChatSubscriptionInviteLink and EditChatSubscriptionInviteLink methods.
|
||||
type ChatSubscriptionInviteOptions struct {
|
||||
Name string `query:"name"`
|
||||
}
|
||||
|
||||
// CallbackQueryOptions contains the optional parameters used by the AnswerCallbackQuery method.
|
||||
type CallbackQueryOptions struct {
|
||||
Text string `query:"text"`
|
||||
URL string `query:"url"`
|
||||
CacheTime int `query:"cache_time"`
|
||||
ShowAlert bool `query:"show_alert"`
|
||||
}
|
||||
|
||||
// MessageIDOptions is a struct which contains data about a message to edit.
|
||||
type MessageIDOptions struct {
|
||||
inlineMessageID string `query:"inline_message_id"`
|
||||
chatID int64 `query:"chat_id"`
|
||||
messageID int `query:"message_id"`
|
||||
}
|
||||
|
||||
// NewMessageID is a wrapper for MessageIDOptions which only fills the chatID and messageID fields.
|
||||
func NewMessageID(chatID int64, messageID int) MessageIDOptions {
|
||||
return MessageIDOptions{chatID: chatID, messageID: messageID}
|
||||
}
|
||||
|
||||
// NewInlineMessageID is a wrapper for MessageIDOptions which only fills the inlineMessageID fields.
|
||||
func NewInlineMessageID(ID string) MessageIDOptions {
|
||||
return MessageIDOptions{inlineMessageID: ID}
|
||||
}
|
||||
|
||||
// MessageTextOptions contains the optional parameters used by the EditMessageText method.
|
||||
type MessageTextOptions struct {
|
||||
ParseMode ParseMode `query:"parse_mode"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
Entities []MessageEntity `query:"entities"`
|
||||
ReplyMarkup InlineKeyboardMarkup `query:"reply_markup"`
|
||||
LinkPreviewOptions LinkPreviewOptions `query:"link_preview_options"`
|
||||
}
|
||||
|
||||
// MessageCaptionOptions contains the optional parameters used by the EditMessageCaption method.
|
||||
type MessageCaptionOptions struct {
|
||||
Caption string `query:"caption"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
ParseMode ParseMode `query:"parse_mode"`
|
||||
CaptionEntities []MessageEntity `query:"caption_entities"`
|
||||
ReplyMarkup InlineKeyboardMarkup `query:"reply_markup"`
|
||||
ShowCaptionAboveMedia bool `query:"show_caption_above_media"`
|
||||
}
|
||||
|
||||
// MessageMediaOptions contains the optional parameters used by the EditMessageMedia method.
|
||||
type MessageMediaOptions struct {
|
||||
ReplyMarkup ReplyMarkup `query:"reply_markup"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
}
|
||||
|
||||
// MessageReplyMarkupOptions contains the optional parameters used by the EditMessageReplyMarkup method.
|
||||
type MessageReplyMarkupOptions struct {
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
ReplyMarkup InlineKeyboardMarkup `query:"reply_markup"`
|
||||
}
|
||||
|
||||
// CommandOptions contains the optional parameters used by the SetMyCommands, DeleteMyCommands and GetMyCommands methods.
|
||||
type CommandOptions struct {
|
||||
LanguageCode string `query:"language_code"`
|
||||
Scope BotCommandScope `query:"scope"`
|
||||
}
|
||||
|
||||
// InvoiceOptions contains the optional parameters used by the SendInvoice API method.
|
||||
type InvoiceOptions struct {
|
||||
StartParameter string `query:"start_parameter"`
|
||||
ProviderData string `query:"provider_data"`
|
||||
PhotoURL string `query:"photo_url"`
|
||||
ProviderToken string `query:"provider_token"`
|
||||
MessageEffectID string `query:"message_effect_id"`
|
||||
ReplyMarkup InlineKeyboardMarkup `query:"reply_markup"`
|
||||
SuggestedTipAmount []int `query:"suggested_tip_amounts"`
|
||||
ReplyParameters ReplyParameters `query:"reply_parameters"`
|
||||
MaxTipAmount int `query:"max_tip_amount"`
|
||||
PhotoSize int `query:"photo_size"`
|
||||
PhotoWidth int `query:"photo_width"`
|
||||
PhotoHeight int `query:"photo_height"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
SendPhoneNumberToProvider bool `query:"send_phone_number_to_provider"`
|
||||
NeedShippingAddress bool `query:"need_shipping_address"`
|
||||
NeedPhoneNumber bool `query:"need_phone_number"`
|
||||
SendEmailToProvider bool `query:"send_email_to_provider"`
|
||||
IsFlexible bool `query:"is_flexible"`
|
||||
DisableNotification bool `query:"disable_notification"`
|
||||
ProtectContent bool `query:"protect_content"`
|
||||
NeedName bool `query:"need_name"`
|
||||
NeedEmail bool `query:"need_email"`
|
||||
AllowPaidBroadcast bool `query:"allow_paid_broadcast"`
|
||||
}
|
||||
|
||||
// CreateInvoiceLinkOptions contains the optional parameters used by the CreateInvoiceLink API method.
|
||||
// Currently, SubscriptionPeriod should always be set to 2592000 (30 days) if specified.
|
||||
type CreateInvoiceLinkOptions struct {
|
||||
ProviderData string `query:"provider_data"`
|
||||
PhotoURL string `query:"photo_url"`
|
||||
ProviderToken string `query:"provider_token"`
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
SuggestedTipAmounts []int `query:"suggested_tip_amounts"`
|
||||
PhotoSize int `query:"photo_size"`
|
||||
PhotoWidth int `query:"photo_width"`
|
||||
PhotoHeight int `query:"photo_height"`
|
||||
MaxTipAmount int `query:"max_tip_amount"`
|
||||
SubscriptionPeriod int `query:"subscription_period"`
|
||||
NeedPhoneNumber bool `query:"need_phone_number"`
|
||||
NeepShippingAddress bool `query:"need_shipping_address"`
|
||||
SendPhoneNumberToProvider bool `query:"send_phone_number_to_provider"`
|
||||
SendEmailToProvider bool `query:"send_email_to_provider"`
|
||||
IsFlexible bool `query:"is_flexible"`
|
||||
NeedName bool `query:"need_name"`
|
||||
NeedEmail bool `query:"need_email"`
|
||||
}
|
||||
|
||||
// ShippingOption represents one shipping option.
|
||||
type ShippingOption struct {
|
||||
ID string `query:"id"`
|
||||
Title string `query:"title"`
|
||||
Prices []LabeledPrice `query:"prices"`
|
||||
}
|
||||
|
||||
// ShippingQueryOptions contains the optional parameters used by the AnswerShippingQuery API method.
|
||||
type ShippingQueryOptions struct {
|
||||
ErrorMessage string `query:"error_message"`
|
||||
ShippingOptions []ShippingOption `query:"shipping_options"`
|
||||
}
|
||||
|
||||
// PreCheckoutOptions contains the optional parameters used by the AnswerPreCheckoutQuery API method.
|
||||
type PreCheckoutOptions struct {
|
||||
ErrorMessage string `query:"error_message"`
|
||||
}
|
||||
|
||||
// CreateTopicOptions contains the optional parameters used by the CreateForumTopic API method.
|
||||
type CreateTopicOptions struct {
|
||||
IconCustomEmojiID string `query:"icon_custom_emoji_id"`
|
||||
IconColor IconColor `query:"icon_color"`
|
||||
}
|
||||
|
||||
// EditTopicOptions contains the optional parameters used by the EditForumTopic API method.
|
||||
type EditTopicOptions struct {
|
||||
Name string `query:"name"`
|
||||
IconCustomEmojiID string `query:"icon_custom_emoji_id"`
|
||||
}
|
||||
|
||||
// ChatActionOptions contains the optional parameters used by the SendChatAction API method.
|
||||
type ChatActionOptions struct {
|
||||
BusinessConnectionID string `query:"business_connection_id"`
|
||||
MessageThreadID int `query:"message_thread_id"`
|
||||
}
|
||||
|
||||
// MessageReactionOptions contains the optional parameters used by the SetMessageReaction API method.
|
||||
type MessageReactionOptions struct {
|
||||
Reaction []ReactionType `query:"reaction"`
|
||||
IsBig bool `query:"is_big"`
|
||||
}
|
||||
|
||||
// GiftOptions contains the optional parameters used by the SendGift API method.
|
||||
type GiftOptions struct {
|
||||
Text string `query:"text"`
|
||||
TextParseMode string `query:"text_parse_mode"`
|
||||
TextEntities []MessageEntity `query:"text_entities"`
|
||||
ChatID int64 `query:"chat_id"`
|
||||
PayForUpgrade bool `query:"pay_for_upgrade"`
|
||||
}
|
||||
|
||||
// VerifyOptions contains the optional parameters used by the VerifyUser and VerifyChat API methods.
|
||||
type VerifyOptions struct {
|
||||
CustomDescription string `query:"custom_description"`
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
msgIDOpts = MessageIDOptions{
|
||||
chatID: 1,
|
||||
messageID: 2,
|
||||
}
|
||||
|
||||
inlineMsgIDOpts = MessageIDOptions{
|
||||
inlineMessageID: "inline",
|
||||
}
|
||||
)
|
||||
|
||||
func TestNewMessageID(t *testing.T) {
|
||||
new := NewMessageID(1, 2)
|
||||
|
||||
if !reflect.DeepEqual(new, msgIDOpts) {
|
||||
t.Logf("expected MessageIDOptions: %+v", msgIDOpts)
|
||||
t.Logf("got MessageIDOptions: %+v", new)
|
||||
t.Fatal("error: MessageIDOptions mismatch")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewInlineMessageID(t *testing.T) {
|
||||
new := NewInlineMessageID("inline")
|
||||
|
||||
if !reflect.DeepEqual(new, inlineMsgIDOpts) {
|
||||
t.Logf("expected MessageIDOptions: %+v", inlineMsgIDOpts)
|
||||
t.Logf("got MessageIDOptions: %+v", new)
|
||||
t.Fatal("error: MessageIDOptions mismatch")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplyKeyboardMarkupImplementsReplyMarkup(_ *testing.T) {
|
||||
i := ReplyKeyboardMarkup{}
|
||||
i.ImplementsReplyMarkup()
|
||||
}
|
||||
|
||||
func TestReplyKeyboardRemoveImplementsReplyMarkup(_ *testing.T) {
|
||||
i := ReplyKeyboardRemove{}
|
||||
i.ImplementsReplyMarkup()
|
||||
}
|
||||
|
||||
func TestInlineKeyboardMarkupImplementsReplyMarkup(_ *testing.T) {
|
||||
i := InlineKeyboardMarkup{}
|
||||
i.ImplementsReplyMarkup()
|
||||
}
|
||||
|
||||
func TestForceReplyImplementsReplyMarkup(_ *testing.T) {
|
||||
i := ForceReply{}
|
||||
i.ImplementsReplyMarkup()
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// PassportData contains information about Telegram Passport data shared with the bot by the user.
|
||||
type PassportData struct {
|
||||
Credentials EncryptedCredentials `json:"encrypted_credentials"`
|
||||
Data []EncryptedPassportElement `json:"encrypted_passport_element"`
|
||||
}
|
||||
|
||||
// PassportFile represents a file uploaded to Telegram Passport.
|
||||
// Currently all Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB.
|
||||
type PassportFile struct {
|
||||
FileID string `json:"file_id"`
|
||||
FileUniqueID string `json:"file_unique_id"`
|
||||
FileSize int64 `json:"file_size"`
|
||||
FileDate int64 `json:"file_date"`
|
||||
}
|
||||
|
||||
// EncryptedPassportElementType is a custom type for the various possible options used as Type in EncryptedPassportElement.
|
||||
type EncryptedPassportElementType string
|
||||
|
||||
// These are all the possible options that can be used as Type in EncryptedPassportElement.
|
||||
const (
|
||||
TypePersonalDetails EncryptedPassportElementType = "personal_details"
|
||||
TypePassport = "passport"
|
||||
TypeDriverLicense = "driver_license"
|
||||
TypeIdentityCard = "identity_card"
|
||||
TypeInternalPassport = "internal_passport"
|
||||
TypeAddress = "address"
|
||||
TypeUtilityBill = "utility_bill"
|
||||
TypeBankStatement = "bank_statement"
|
||||
TypeRentalAgreement = "rental_agreement"
|
||||
TypePassportRegistration = "passport_registration"
|
||||
TypeTemporaryRegistration = "temporary_registration"
|
||||
TypePhoneNumber = "phone_number"
|
||||
TypeEmail = "email"
|
||||
)
|
||||
|
||||
// EncryptedPassportElement contains information about documents or other Telegram Passport elements shared with the bot by the user.
|
||||
type EncryptedPassportElement struct {
|
||||
Type EncryptedPassportElementType `json:"type"`
|
||||
Data string `json:"data,omitempty"`
|
||||
PhoneNumber string `json:"phone_number,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
Files *[]PassportFile `json:"files,omitempty"`
|
||||
FrontSide *PassportFile `json:"front_side,omitempty"`
|
||||
ReverseSide *PassportFile `json:"reverse_side,omitempty"`
|
||||
Selfie *PassportFile `json:"selfie,omitempty"`
|
||||
Translation *[]PassportFile `json:"translation,omitempty"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
// EncryptedCredentials contains data required for decrypting and authenticating EncryptedPassportElement.
|
||||
// See the Telegram Passport Documentation for a complete description of the data decryption and authentication processes.
|
||||
// https://core.telegram.org/passport#receiving-information
|
||||
type EncryptedCredentials struct {
|
||||
Data string `json:"data"`
|
||||
Hash string `json:"hash"`
|
||||
Secret string `json:"secret"`
|
||||
}
|
||||
|
||||
// PassportElementErrorSource is a custom type for the various possible options used as Source in PassportElementSource.
|
||||
type PassportElementErrorSource string
|
||||
|
||||
// These are all the possible options that can be used as Source in PassportElementSource.
|
||||
const (
|
||||
SourceData PassportElementErrorSource = "data"
|
||||
SourceFrontSide = "front_side"
|
||||
SourceReverseSide = "reverse_side"
|
||||
SourceSelfie = "selfie"
|
||||
SourceFile = "file"
|
||||
SourceFiles = "files"
|
||||
SourceTranslationFile = "translation_file"
|
||||
SourceTranslationFiles = "translation_files"
|
||||
SourceUnspecified = "unspecified"
|
||||
)
|
||||
|
||||
// PassportElementError is an interface for the various PassportElementError types.
|
||||
type PassportElementError interface {
|
||||
ImplementsPassportElementError()
|
||||
}
|
||||
|
||||
// PassportElementErrorDataField represents an issue in one of the data fields that was provided by the user.
|
||||
// The error is considered resolved when the field's value changes.
|
||||
// Source MUST BE SourceData.
|
||||
// Type MUST BE one of TypePersonalDetails, TypePassport, TypeDriverLicense, TypeIdentityCard, TypeInternalPassport and TypeAddress.
|
||||
type PassportElementErrorDataField struct {
|
||||
Source PassportElementErrorSource `json:"source"`
|
||||
Type EncryptedPassportElementType `json:"type"`
|
||||
FieldName string `json:"field_name"`
|
||||
DataHash string `json:"data_hash"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
|
||||
func (p PassportElementErrorDataField) ImplementsPassportElementError() {}
|
||||
|
||||
// PassportElementErrorFrontSide represents an issue with the front side of a document.
|
||||
// The error is considered resolved when the file with the front side of the document changes.
|
||||
// Source MUST BE SourceFrontSide.
|
||||
// Type MUST BE one of TypeDriverLicense and TypeIdentityCard.
|
||||
type PassportElementErrorFrontSide struct {
|
||||
Source PassportElementErrorSource `json:"source"`
|
||||
Type EncryptedPassportElementType `json:"type"`
|
||||
FileHash string `json:"file_hash"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
|
||||
func (p PassportElementErrorFrontSide) ImplementsPassportElementError() {}
|
||||
|
||||
// PassportElementErrorReverseSide represents an issue with the reverse side of a document.
|
||||
// The error is considered resolved when the file with the reverse side of the document changes.
|
||||
// Source MUST BE SourceReverseSide.
|
||||
// Type MUST BE one of TypeDriverLicense and TypeIdentityCard.
|
||||
type PassportElementErrorReverseSide struct {
|
||||
Source PassportElementErrorSource `json:"source"`
|
||||
Type EncryptedPassportElementType `json:"type"`
|
||||
FileHash string `json:"file_hash"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
|
||||
func (p PassportElementErrorReverseSide) ImplementsPassportElementError() {}
|
||||
|
||||
// PassportElementErrorSelfie represents an issue with the selfie with a document.
|
||||
// The error is considered resolved when the file with the selfie changes.
|
||||
// Source MUST BE SourceSelfie.
|
||||
// Type MUST BE one of TypePassport, TypeDriverLicense, TypeIdentityCard and TypeIdentityPassport.
|
||||
type PassportElementErrorSelfie struct {
|
||||
Source PassportElementErrorSource `json:"source"`
|
||||
Type EncryptedPassportElementType `json:"type"`
|
||||
FileHash string `json:"file_hash"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
|
||||
func (p PassportElementErrorSelfie) ImplementsPassportElementError() {}
|
||||
|
||||
// PassportElementErrorFile represents an issue with the document scan.
|
||||
// The error is considered resolved when the file with the document scan changes.
|
||||
// Source MUST BE SourceFile.
|
||||
// Type MUST BE one of TypePassport, TypeDriverLicense, TypeIdentityCard and TypeIdentityPassport.
|
||||
type PassportElementErrorFile struct {
|
||||
Source PassportElementErrorSource `json:"source"`
|
||||
Type EncryptedPassportElementType `json:"type"`
|
||||
FileHash string `json:"file_hash"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
|
||||
func (p PassportElementErrorFile) ImplementsPassportElementError() {}
|
||||
|
||||
// PassportElementErrorFiles represents an issue with a list of scans.
|
||||
// The error is considered resolved when the list of files containing the scans changes.
|
||||
// Source MUST BE SourceFiles.
|
||||
// Type MUST BE one of TypeUtilityBill, TypeBankStatement, TypeRentalAgreement, TypePassportRegistration and TypeTemporaryRegistration.
|
||||
type PassportElementErrorFiles struct {
|
||||
Source PassportElementErrorSource `json:"source"`
|
||||
Type EncryptedPassportElementType `json:"type"`
|
||||
Message string `json:"message"`
|
||||
FileHashes []string `json:"file_hashes"`
|
||||
}
|
||||
|
||||
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
|
||||
func (p PassportElementErrorFiles) ImplementsPassportElementError() {}
|
||||
|
||||
// PassportElementErrorTranslationFile represents an issue with one of the files that constitute the translation of the document.
|
||||
// The error is considered resolved when the file changes.
|
||||
// Source MUST BE SourceTranslationFile.
|
||||
// Type MUST BE one of TypePassport, TypeDriverLicense, TypeIdentityCard, TypeInternalPassport, TypeUtilityBill, TypeBankStatement,
|
||||
// TypeRentalAgreement, TypePassportRegistration and TypeTemporaryRegistration.
|
||||
type PassportElementErrorTranslationFile struct {
|
||||
Source PassportElementErrorSource `json:"source"`
|
||||
Type EncryptedPassportElementType `json:"type"`
|
||||
FileHash string `json:"file_hash"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
|
||||
func (p PassportElementErrorTranslationFile) ImplementsPassportElementError() {}
|
||||
|
||||
// PassportElementErrorTranslationFiles represents an issue with the translated version of a document.
|
||||
// The error is considered resolved when a file with the document translation changes.
|
||||
// Source MUST BE SourceTranslationFiles.
|
||||
// Type MUST BE one of TypePassport, TypeDriverLicense, TypeIdentityCard, TypeInternalPassport, TypeUtilityBill, TypeBankStatement,
|
||||
// TypeRentalAgreement, TypePassportRegistration and TypeTemporaryRegistration.
|
||||
type PassportElementErrorTranslationFiles struct {
|
||||
Source PassportElementErrorSource `json:"source"`
|
||||
Type EncryptedPassportElementType `json:"type"`
|
||||
Message string `json:"message"`
|
||||
FileHashes []string `json:"file_hashes"`
|
||||
}
|
||||
|
||||
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
|
||||
func (p PassportElementErrorTranslationFiles) ImplementsPassportElementError() {}
|
||||
|
||||
// PassportElementErrorUnspecified represents an issue in an unspecified place.
|
||||
// The error is considered resolved when new data is added.
|
||||
type PassportElementErrorUnspecified struct {
|
||||
Source PassportElementErrorSource `json:"source"`
|
||||
Type EncryptedPassportElementType `json:"type"`
|
||||
ElementHash string `json:"element_hash"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// ImplementsPassportElementError us a dummy method which exists to implement the interface PassportElementError.
|
||||
func (p PassportElementErrorUnspecified) ImplementsPassportElementError() {}
|
||||
|
||||
// SetPassportDataErrors Informs a user that some of the Telegram Passport elements they provided contains errors.
|
||||
// The user will not be able to re-submit their Passport to you until the errors are fixed.
|
||||
// The contents of the field for which you returned the error must change.
|
||||
func (a API) SetPassportDataErrors(userID int64, errors []PassportElementError) (res APIResponseBool, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
errorsArr, err := json.Marshal(errors)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
vals.Set("user_id", itoa(userID))
|
||||
vals.Set("errors", string(errorsArr))
|
||||
return res, client.get(a.base, "setPassportDataErrors", vals, &res)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package echotron
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPassportElementErrorDataField(_ *testing.T) {
|
||||
p := PassportElementErrorDataField{}
|
||||
p.ImplementsPassportElementError()
|
||||
}
|
||||
|
||||
func TestPassportElementErrorFrontSide(_ *testing.T) {
|
||||
p := PassportElementErrorFrontSide{}
|
||||
p.ImplementsPassportElementError()
|
||||
}
|
||||
|
||||
func TestPassportElementErrorReverseSide(_ *testing.T) {
|
||||
p := PassportElementErrorReverseSide{}
|
||||
p.ImplementsPassportElementError()
|
||||
}
|
||||
|
||||
func TestPassportElementErrorSelfie(_ *testing.T) {
|
||||
p := PassportElementErrorSelfie{}
|
||||
p.ImplementsPassportElementError()
|
||||
}
|
||||
|
||||
func TestPassportElementErrorFile(_ *testing.T) {
|
||||
p := PassportElementErrorFile{}
|
||||
p.ImplementsPassportElementError()
|
||||
}
|
||||
|
||||
func TestPassportElementErrorFiles(_ *testing.T) {
|
||||
p := PassportElementErrorFiles{}
|
||||
p.ImplementsPassportElementError()
|
||||
}
|
||||
|
||||
func TestPassportElementErrorTranslationFile(_ *testing.T) {
|
||||
p := PassportElementErrorTranslationFile{}
|
||||
p.ImplementsPassportElementError()
|
||||
}
|
||||
|
||||
func TestPassportElementErrorTranslationFiles(_ *testing.T) {
|
||||
p := PassportElementErrorTranslationFiles{}
|
||||
p.ImplementsPassportElementError()
|
||||
}
|
||||
|
||||
func TestPassportElementErrorUnspecified(_ *testing.T) {
|
||||
p := PassportElementErrorUnspecified{}
|
||||
p.ImplementsPassportElementError()
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2018 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// LabeledPrice represents a portion of the price for goods or services.
|
||||
type LabeledPrice struct {
|
||||
Label string `json:"label"`
|
||||
// Price of the product in the smallest units of the currency (integer, not float/double).
|
||||
// For example, for a price of US$ 1.45 pass amount = 145.
|
||||
// See the exp parameter in currencies.json, it shows the number of digits
|
||||
// past the decimal point for each currency (2 for the majority of currencies).
|
||||
Amount int `json:"amount"`
|
||||
}
|
||||
|
||||
// Invoice contains basic information about an invoice.
|
||||
type Invoice struct {
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
StartParameter string `json:"start_parameter"`
|
||||
// Three-letter ISO 4217 currency code.
|
||||
Currency string `json:"currency"`
|
||||
// Total amount in the smallest units of the currency (integer, not float/double).
|
||||
// For example, for a price of US$ 1.45 pass amount = 145.
|
||||
// See the exp parameter in currencies.json, it shows the number of digits
|
||||
// past the decimal point for each currency (2 for the majority of currencies).
|
||||
TotalAmount int `json:"total_amount"`
|
||||
}
|
||||
|
||||
// ShippingAddress represents a shipping address.
|
||||
type ShippingAddress struct {
|
||||
// ISO 3166-1 alpha-2 country code.
|
||||
CountryCode string `json:"country_code"`
|
||||
State string `json:"state"`
|
||||
City string `json:"city"`
|
||||
StreetLine1 string `json:"street_line1"`
|
||||
StreetLine2 string `json:"street_line2"`
|
||||
PostCode string `json:"post_code"`
|
||||
}
|
||||
|
||||
// OrderInfo represents information about an order.
|
||||
type OrderInfo struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
PhoneNumber string `json:"phone_number,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
ShippingAddress ShippingAddress `json:"shipping_address,omitempty"`
|
||||
}
|
||||
|
||||
// SuccessfulPayment contains basic information about a successful payment.
|
||||
type SuccessfulPayment struct {
|
||||
OrderInfo OrderInfo `json:"order_info"`
|
||||
Currency string `json:"currency"`
|
||||
InvoicePayload string `json:"invoice_payload"`
|
||||
ShippingOptionID string `json:"shipping_option_id"`
|
||||
TelegramPaymentChargeID string `json:"telegram_payment_charge_id"`
|
||||
ProviderPaymentChargeID string `json:"provider_payment_charge_id"`
|
||||
TotalAmount int `json:"total_amount"`
|
||||
SubscriptionExpirationDate int `json:"subscription_expiration_date,omitempty"`
|
||||
IsRecurring bool `json:"is_recurring,omitempty"`
|
||||
IsFirstRecurring bool `json:"is_first_recurring,omitempty"`
|
||||
}
|
||||
|
||||
// RefundedPayment contains basic information about a refunded payment.
|
||||
type RefundedPayment struct {
|
||||
Currency string `json:"currency"`
|
||||
InvoicePayload string `json:"invoice_payload"`
|
||||
TelegramPaymentChargeID string `json:"telegram_payment_charge_id"`
|
||||
ProviderPaymentChargeID string `json:"provider_payment_charge_id,omitempty"`
|
||||
TotalAmount int `json:"total_amount"`
|
||||
}
|
||||
|
||||
// ShippingQuery contains information about an incoming shipping query.
|
||||
type ShippingQuery struct {
|
||||
ShippingAddress ShippingAddress `json:"shipping_address"`
|
||||
ID string `json:"id"`
|
||||
InvoicePayload string `json:"invoice_payload"`
|
||||
From User `json:"from"`
|
||||
}
|
||||
|
||||
// PreCheckoutQuery contains information about an incoming pre-checkout query.
|
||||
type PreCheckoutQuery struct {
|
||||
OrderInfo OrderInfo `json:"order_info,omitempty"`
|
||||
Currency string `json:"currency"`
|
||||
InvoicePayload string `json:"invoice_payload"`
|
||||
ShippingOptionID string `json:"shipping_option_id,omitempty"`
|
||||
ID string `json:"id"`
|
||||
From User `json:"from"`
|
||||
TotalAmount int `json:"total_amount"`
|
||||
}
|
||||
|
||||
// PaidMediaPurchased contains information about a paid media purchase.
|
||||
type PaidMediaPurchased struct {
|
||||
PaidMediaPayload string `json:"paid_media_payload"`
|
||||
From User `json:"from"`
|
||||
}
|
||||
|
||||
// RevenueWithdrawalState describes the state of a revenue withdrawal operation.
|
||||
type RevenueWithdrawalState interface {
|
||||
ImplementsRevenueWithdrawalState()
|
||||
}
|
||||
|
||||
// RevenueWithdrawalStatePending describes the state of a withdrawal in progress.
|
||||
type RevenueWithdrawalStatePending struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// ImplementsRevenueWithdrawalState is used to implement the RevenueWithdrawalState interface.
|
||||
func (r RevenueWithdrawalStatePending) ImplementsRevenueWithdrawalState() {}
|
||||
|
||||
// RevenueWithdrawalStateSucceeded describes the state of a succeeded withdrawal.
|
||||
type RevenueWithdrawalStateSucceeded struct {
|
||||
Type string `json:"type"`
|
||||
URL string `json:"url"`
|
||||
Date int `json:"date"`
|
||||
}
|
||||
|
||||
// ImplementsRevenueWithdrawalState is used to implement the RevenueWithdrawalState interface.
|
||||
func (r RevenueWithdrawalStateSucceeded) ImplementsRevenueWithdrawalState() {}
|
||||
|
||||
// RevenueWithdrawalStateFailed describes the state of a failed withdrawal, in which the transaction was refunded.
|
||||
type RevenueWithdrawalStateFailed struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// ImplementsRevenueWithdrawalState is used to implement the RevenueWithdrawalState interface.
|
||||
func (r RevenueWithdrawalStateFailed) ImplementsRevenueWithdrawalState() {}
|
||||
|
||||
// AffiliateInfo
|
||||
type AffiliateInfo struct {
|
||||
AffiliateUser *User `json:"affiliate_user,omitempty"`
|
||||
AffiliateChat *Chat `json:"affiliate_chat,omitempty"`
|
||||
CommissionPerMille int `json:"commission_per_mille"`
|
||||
Amount int `json:"amount"`
|
||||
NanostarAmount int `json:"nanostar_amount,omitempty"`
|
||||
}
|
||||
|
||||
// TransactionPartner describes the source of a transaction, or its recipient for outgoing transactions.
|
||||
type TransactionPartner interface {
|
||||
ImplementsTransactionPartner()
|
||||
}
|
||||
|
||||
// TransactionPartnerAffiliateProgram describes the affiliate program that issued the affiliate commission received via this transaction.
|
||||
// Type MUST be "affiliate_program".
|
||||
type TransactionPartnerAffiliateProgram struct {
|
||||
SponsorUser *User `json:"sponsor_user,omitempty"`
|
||||
Type string `json:"type"`
|
||||
CommissionPerMille int `json:"commission_per_mille,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsTransactionPartner is used to implement the TransactionPartner interface.
|
||||
func (t TransactionPartnerAffiliateProgram) ImplementsTransactionPartner() {}
|
||||
|
||||
// TransactionPartnerFragment describes a withdrawal transaction with Fragment.
|
||||
// Type MUST be "fragment".
|
||||
type TransactionPartnerFragment struct {
|
||||
WithdrawalState RevenueWithdrawalState `json:"withdrawal_state"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// ImplementsTransactionPartner is used to implement the TransactionPartner interface.
|
||||
func (t TransactionPartnerFragment) ImplementsTransactionPartner() {}
|
||||
|
||||
// TransactionPartnerUser describes a transaction with a user.
|
||||
// Type MUST be "user".
|
||||
type TransactionPartnerUser struct {
|
||||
PaidMedia *[]PaidMedia `json:"paid_media,omitempty"`
|
||||
Type string `json:"type"`
|
||||
InvoicePayload string `json:"invoice_payload,omitempty"`
|
||||
PaidMediaPayload string `json:"paid_media_payload,omitempty"`
|
||||
User User `json:"user"`
|
||||
Affiliate *AffiliateInfo `json:"affiliate,omitempty"`
|
||||
Gift Gift `json:"gift,omitempty"`
|
||||
SubscriptionPeriod int `json:"subscription_period,omitempty"`
|
||||
}
|
||||
|
||||
// TransactionPartnerChat describes a transaction with a chat.
|
||||
type TransactionPartnerChat struct {
|
||||
Type string `json:"type"`
|
||||
Chat Chat `json:"chat"`
|
||||
Gift Gift `json:"gift,omitempty"`
|
||||
}
|
||||
|
||||
// ImplementsTransactionPartner is used to implement the TransactionPartner interface.
|
||||
func (t TransactionPartnerUser) ImplementsTransactionPartner() {}
|
||||
|
||||
// TransactionPartnerTelegramAds describes a withdrawal transaction to the Telegram Ads platform.
|
||||
// Type MUST be "telegram_ads".
|
||||
type TransactionPartnerTelegramAds struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// ImplementsTransactionPartner is used to implement the TransactionPartner interface.
|
||||
func (t TransactionPartnerTelegramAds) ImplementsTransactionPartner() {}
|
||||
|
||||
// TransactionPartnerTelegramApi describes a transaction with payment for paid broadcasting.
|
||||
// Type MUST be "telegram_api".
|
||||
type TransactionPartnerTelegramApi struct {
|
||||
Type string `json:"type"`
|
||||
RequestCount int `json:"request_count"`
|
||||
}
|
||||
|
||||
// ImplementsTransactionPartner is used to implement the TransactionPartner interface.
|
||||
func (t TransactionPartnerTelegramApi) ImplementsTransactionPartner() {}
|
||||
|
||||
// TransactionPartnerOther describes a transaction with an unknown source or recipient.
|
||||
// Type MUST be "other".
|
||||
type TransactionPartnerOther struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// ImplementsTransactionPartner is used to implement the TransactionPartner interface.
|
||||
func (t TransactionPartnerOther) ImplementsTransactionPartner() {}
|
||||
|
||||
// StarTransaction describes a Telegram Star transaction.
|
||||
type StarTransaction struct {
|
||||
Source TransactionPartner `json:"source"`
|
||||
Receiver TransactionPartner `json:"receiver"`
|
||||
ID string `json:"id"`
|
||||
Amount int `json:"amount"`
|
||||
NanostarAmount int `json:"nanostar_amount,omitempty"`
|
||||
Date int `json:"date"`
|
||||
}
|
||||
|
||||
// StarTransactions contains a list of Telegram Star transactions.
|
||||
type StarTransactions struct {
|
||||
Transaction []StarTransaction `json:"transaction"`
|
||||
}
|
||||
|
||||
// StarTransactionsOptions contains the optional parameters used by the GetStarTransactions method.
|
||||
type StarTransactionsOptions struct {
|
||||
Offset int `query:"offset"`
|
||||
Limit int `query:"limit"`
|
||||
}
|
||||
|
||||
// SendInvoice is used to send invoices.
|
||||
func (a API) SendInvoice(chatID int64, title, description, payload, currency string, prices []LabeledPrice, opts *InvoiceOptions) (res APIResponseMessage, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
p, err := json.Marshal(prices)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
vals.Set("chat_id", itoa(chatID))
|
||||
vals.Set("title", title)
|
||||
vals.Set("description", description)
|
||||
vals.Set("payload", payload)
|
||||
vals.Set("currency", currency)
|
||||
vals.Set("prices", string(p))
|
||||
return res, client.get(a.base, "sendInvoice", addValues(vals, opts), &res)
|
||||
}
|
||||
|
||||
// CreateInvoiceLink creates a link for an invoice.
|
||||
func (a API) CreateInvoiceLink(title, description, payload, currency string, prices []LabeledPrice, opts *CreateInvoiceLinkOptions) (res APIResponseBase, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
p, err := json.Marshal(prices)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
vals.Set("title", title)
|
||||
vals.Set("description", description)
|
||||
vals.Set("payload", payload)
|
||||
vals.Set("currency", currency)
|
||||
vals.Set("prices", string(p))
|
||||
return res, client.get(a.base, "createInvoiceLink", addValues(vals, opts), &res)
|
||||
}
|
||||
|
||||
// AnswerShippingQuery is used to reply to shipping queries.
|
||||
// If you sent an invoice requesting a shipping address and the parameter is_flexible was specified,
|
||||
// the Bot API will send an Update with a shipping_query field to the bot.
|
||||
func (a API) AnswerShippingQuery(shippingQueryID string, ok bool, opts *ShippingQueryOptions) (res APIResponseBase, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("shipping_query_id", shippingQueryID)
|
||||
vals.Set("ok", btoa(ok))
|
||||
return res, client.get(a.base, "answerShippingQuery", addValues(vals, opts), &res)
|
||||
}
|
||||
|
||||
// AnswerPreCheckoutQuery is used to respond to such pre-checkout queries.
|
||||
// Once the user has confirmed their payment and shipping details,
|
||||
// the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query.
|
||||
// NOTE: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
|
||||
func (a API) AnswerPreCheckoutQuery(preCheckoutQueryID string, ok bool, opts *PreCheckoutOptions) (res APIResponseBase, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("pre_checkout_query_id", preCheckoutQueryID)
|
||||
vals.Set("ok", btoa(ok))
|
||||
return res, client.get(a.base, "answerPreCheckoutQuery", addValues(vals, opts), &res)
|
||||
}
|
||||
|
||||
// GetStarTransactions returns the bot's Telegram Star transactions in chronological order.
|
||||
func (a API) GetStarTransactions(opts *StarTransactionsOptions) (res APIResponseStarTransactions, err error) {
|
||||
return res, client.get(a.base, "getStarTransactions", urlValues(opts), &res)
|
||||
}
|
||||
|
||||
// RefundStarPayment refunds a successful payment in Telegram Stars.
|
||||
func (a API) RefundStarPayment(userID int64, telegramPaymentChargeID string) (res APIResponseBool, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("user_id", itoa(userID))
|
||||
vals.Set("telegram_payment_charge_id", telegramPaymentChargeID)
|
||||
return res, client.get(a.base, "refundStarPayment", vals, &res)
|
||||
}
|
||||
|
||||
// EditUserStarSubscription allows the bot to cancel or re-enable extension of a subscription paid in Telegram Stars.
|
||||
func (a API) EditUserStarSubscription(userID int64, telegramPaymentChargeID string, isCanceled bool) (res APIResponseBool, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("user_id", itoa(userID))
|
||||
vals.Set("telegram_payment_charge_id", telegramPaymentChargeID)
|
||||
vals.Set("is_canceled", btoa(isCanceled))
|
||||
return res, client.get(a.base, "editUserStarSubscription", vals, &res)
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package echotron
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRevenueWithdrawalStatePending(t *testing.T) {
|
||||
r := RevenueWithdrawalStatePending{}
|
||||
r.ImplementsRevenueWithdrawalState()
|
||||
}
|
||||
|
||||
func TestRevenueWithdrawalStateSucceeded(t *testing.T) {
|
||||
r := RevenueWithdrawalStateSucceeded{}
|
||||
r.ImplementsRevenueWithdrawalState()
|
||||
}
|
||||
|
||||
func TestRevenueWithdrawalStateFailed(t *testing.T) {
|
||||
r := RevenueWithdrawalStateFailed{}
|
||||
r.ImplementsRevenueWithdrawalState()
|
||||
}
|
||||
|
||||
func TestTransactionPartnerFragment(t *testing.T) {
|
||||
r := TransactionPartnerFragment{}
|
||||
r.ImplementsTransactionPartner()
|
||||
}
|
||||
|
||||
func TestTransactionPartnerUser(t *testing.T) {
|
||||
r := TransactionPartnerUser{}
|
||||
r.ImplementsTransactionPartner()
|
||||
}
|
||||
func TestTransactionPartnerTelegramAds(t *testing.T) {
|
||||
r := TransactionPartnerTelegramAds{}
|
||||
r.ImplementsTransactionPartner()
|
||||
}
|
||||
func TestTransactionPartnerOther(t *testing.T) {
|
||||
r := TransactionPartnerOther{}
|
||||
r.ImplementsTransactionPartner()
|
||||
}
|
||||
|
||||
func TestSendInvoice(t *testing.T) {
|
||||
_, err := api.SendInvoice(
|
||||
chatID,
|
||||
"TestSendInvoice",
|
||||
"TestSendInvoiceDesc",
|
||||
"echotron_test",
|
||||
"XTR",
|
||||
[]LabeledPrice{
|
||||
{
|
||||
Label: "Test",
|
||||
Amount: 1,
|
||||
},
|
||||
},
|
||||
nil,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateInvoiceLink(t *testing.T) {
|
||||
_, err := api.CreateInvoiceLink(
|
||||
"TestCreateInvoiceLink",
|
||||
"TestCreateInvoiceLinkDesc",
|
||||
"echotron_test",
|
||||
"XTR",
|
||||
[]LabeledPrice{
|
||||
{
|
||||
Label: "Test",
|
||||
Amount: 1,
|
||||
},
|
||||
},
|
||||
nil,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetStarTransactions(t *testing.T) {
|
||||
_, err := api.GetStarTransactions(
|
||||
nil,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2018 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func toString(v reflect.Value) string {
|
||||
switch v.Kind() {
|
||||
case reflect.String:
|
||||
return v.String()
|
||||
|
||||
case reflect.Float64:
|
||||
return strconv.FormatFloat(v.Float(), 'f', -1, 64)
|
||||
|
||||
case reflect.Int, reflect.Int64:
|
||||
return strconv.FormatInt(v.Int(), 10)
|
||||
|
||||
case reflect.Bool:
|
||||
return strconv.FormatBool(v.Bool())
|
||||
|
||||
case reflect.Struct, reflect.Interface, reflect.Slice, reflect.Array:
|
||||
b, _ := json.Marshal(v.Interface())
|
||||
return string(b)
|
||||
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func scan(i any, v url.Values) url.Values {
|
||||
e := reflect.ValueOf(i)
|
||||
|
||||
if e.Kind() == reflect.Pointer {
|
||||
e = e.Elem()
|
||||
}
|
||||
|
||||
if e.Kind() == reflect.Invalid {
|
||||
return v
|
||||
}
|
||||
|
||||
for i := 0; i < e.NumField(); i++ {
|
||||
fTag := e.Type().Field(i).Tag
|
||||
|
||||
if name := fTag.Get("query"); name != "" && !e.Field(i).IsZero() {
|
||||
v.Set(name, toString(e.Field(i)))
|
||||
}
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func urlValues(i any) url.Values {
|
||||
if i == nil {
|
||||
return nil
|
||||
}
|
||||
return scan(i, url.Values{})
|
||||
}
|
||||
|
||||
func addValues(vals url.Values, i any) url.Values {
|
||||
if i == nil {
|
||||
return vals
|
||||
}
|
||||
if vals == nil {
|
||||
vals = make(url.Values)
|
||||
}
|
||||
return scan(i, vals)
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type scanTest struct {
|
||||
i any
|
||||
predefined url.Values
|
||||
expected url.Values
|
||||
}
|
||||
|
||||
func TestScan(t *testing.T) {
|
||||
tests := []scanTest{
|
||||
{
|
||||
i: CommandOptions{
|
||||
LanguageCode: "it",
|
||||
Scope: BotCommandScope{Type: BCSTChat, ChatID: 33288},
|
||||
},
|
||||
predefined: url.Values{"foo": {"bar"}},
|
||||
expected: url.Values{
|
||||
"foo": {"bar"},
|
||||
"language_code": {"it"},
|
||||
"scope": {`{"type":"chat","chat_id":33288,"user_id":0}`},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
result := scan(tt.i, tt.predefined)
|
||||
if !reflect.DeepEqual(tt.expected, result) {
|
||||
t.Fatalf("test #%d: result differs from expected value\n", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestToStringDefault(t *testing.T) {
|
||||
ret := toString(reflect.ValueOf(nil))
|
||||
|
||||
if ret != "" {
|
||||
t.Fatalf("expected empty string, got %+v", ret)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUrlValues(t *testing.T) {
|
||||
ret := urlValues(nil)
|
||||
|
||||
if ret != nil {
|
||||
t.Fatalf("expected nil, got %+v", ret)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddValues(t *testing.T) {
|
||||
vals := url.Values{}
|
||||
ret := addValues(vals, nil)
|
||||
|
||||
if !reflect.DeepEqual(vals, ret) {
|
||||
t.Fatalf("expected nil, got %+v", ret)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddValuesNil(t *testing.T) {
|
||||
opts := MessageOptions{ParseMode: MarkdownV2}
|
||||
vals := urlValues(opts)
|
||||
ret := addValues(nil, opts)
|
||||
|
||||
if !reflect.DeepEqual(vals, ret) {
|
||||
t.Fatalf("expected %+v, got %+v", vals, ret)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2023 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
// PollingUpdates is a wrapper function for PollingUpdatesOptions.
|
||||
func PollingUpdates(token string) <-chan *Update {
|
||||
return PollingUpdatesOptions(token, true, UpdateOptions{Timeout: 120})
|
||||
}
|
||||
|
||||
// PollingUpdatesOptions returns a read-only channel of incoming updates from the Telegram API.
|
||||
func PollingUpdatesOptions(token string, dropPendingUpdates bool, opts UpdateOptions) <-chan *Update {
|
||||
var updates = make(chan *Update)
|
||||
|
||||
go func() {
|
||||
defer close(updates)
|
||||
|
||||
var (
|
||||
api = NewAPI(token)
|
||||
timeout = opts.Timeout
|
||||
isFirstRun = true
|
||||
)
|
||||
|
||||
// deletes webhook if present to run in long polling mode
|
||||
if _, err := api.DeleteWebhook(dropPendingUpdates); err != nil {
|
||||
log.Println("echotron.PollingUpdates", err)
|
||||
}
|
||||
|
||||
for {
|
||||
if isFirstRun {
|
||||
opts.Timeout = 0
|
||||
}
|
||||
|
||||
response, err := api.GetUpdates(&opts)
|
||||
if err != nil {
|
||||
log.Println("echotron.PollingUpdates", err)
|
||||
time.Sleep(5 * time.Second)
|
||||
continue
|
||||
}
|
||||
|
||||
if !dropPendingUpdates || !isFirstRun {
|
||||
for _, u := range response.Result {
|
||||
updates <- u
|
||||
}
|
||||
}
|
||||
|
||||
if l := len(response.Result); l > 0 {
|
||||
opts.Offset = response.Result[l-1].ID + 1
|
||||
}
|
||||
|
||||
if isFirstRun {
|
||||
isFirstRun = false
|
||||
opts.Timeout = timeout
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return updates
|
||||
}
|
||||
|
||||
// WebhookUpdates is a wrapper function for WebhookUpdatesOptions.
|
||||
func WebhookUpdates(url, token string) <-chan *Update {
|
||||
return WebhookUpdatesOptions(url, token, false, nil)
|
||||
}
|
||||
|
||||
// WebhookUpdatesOptions returns a read-only channel of incoming updates from the Telegram API.
|
||||
// The webhookUrl should be provided in the following format: '<hostname>:<port>/<path>',
|
||||
// eg: 'https://example.com:443/bot_token'.
|
||||
// WebhookUpdatesOptions will then proceed to communicate the webhook url '<hostname>/<path>'
|
||||
// to Telegram and run a webserver that listens to ':<port>' and handles the path.
|
||||
func WebhookUpdatesOptions(whURL, token string, dropPendingUpdates bool, opts *WebhookOptions) <-chan *Update {
|
||||
u, err := url.Parse(whURL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
wURL := u.Hostname() + u.EscapedPath()
|
||||
api := NewAPI(token)
|
||||
if _, err := api.SetWebhook(wURL, dropPendingUpdates, opts); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var updates = make(chan *Update)
|
||||
http.HandleFunc(u.EscapedPath(), func(w http.ResponseWriter, r *http.Request) {
|
||||
var update Update
|
||||
|
||||
jsn, err := readRequest(r)
|
||||
if err != nil {
|
||||
log.Println("echotron.WebhookUpdates", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(jsn, &update); err != nil {
|
||||
log.Println("echotron.WebhookUpdates", err)
|
||||
return
|
||||
}
|
||||
|
||||
updates <- &update
|
||||
})
|
||||
|
||||
go func() {
|
||||
defer close(updates)
|
||||
port := fmt.Sprintf(":%s", u.Port())
|
||||
for {
|
||||
if err := http.ListenAndServe(port, nil); err != nil {
|
||||
log.Println("echotron.WebhookUpdates", err)
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return updates
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package echotron
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPollingUpdates(t *testing.T) {
|
||||
PollingUpdates(api.token)
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2018 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Sticker represents a sticker.
|
||||
type Sticker struct {
|
||||
Thumbnail *PhotoSize `json:"thumbnail,omitempty"`
|
||||
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
|
||||
Type StickerSetType `json:"type"`
|
||||
FileUniqueID string `json:"file_unique_id"`
|
||||
SetName string `json:"set_name,omitempty"`
|
||||
FileID string `json:"file_id"`
|
||||
Emoji string `json:"emoji,omitempty"`
|
||||
CustomEmojiID string `json:"custom_emoji_id,omitempty"`
|
||||
PremiumAnimation File `json:"premium_animation,omitempty"`
|
||||
FileSize int `json:"file_size,omitempty"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
IsVideo bool `json:"is_video"`
|
||||
IsAnimated bool `json:"is_animated"`
|
||||
NeedsRepainting bool `json:"needs_repainting,omitempty"`
|
||||
}
|
||||
|
||||
// StickerSet represents a sticker set.
|
||||
type StickerSet struct {
|
||||
Thumbnail *PhotoSize `json:"thumbnail,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Name string `json:"name"`
|
||||
StickerType StickerSetType `json:"sticker_type"`
|
||||
Stickers []Sticker `json:"stickers"`
|
||||
}
|
||||
|
||||
// StickerSetType represents the type of a sticker or of the entire set
|
||||
type StickerSetType string
|
||||
|
||||
const (
|
||||
RegularStickerSet StickerSetType = "regular"
|
||||
MaskStickerSet = "mask"
|
||||
CustomEmojiStickerSet = "custom_emoji"
|
||||
)
|
||||
|
||||
// StickerFormat is a custom type for the various sticker formats.
|
||||
type StickerFormat string
|
||||
|
||||
// These are all the possible sticker formats.
|
||||
const (
|
||||
StaticFormat StickerFormat = "static"
|
||||
AnimatedFormat = "animated"
|
||||
VideoFormat = "video"
|
||||
)
|
||||
|
||||
// MaskPosition describes the position on faces where a mask should be placed by default.
|
||||
type MaskPosition struct {
|
||||
Point MaskPoint `json:"point"`
|
||||
XShift float32 `json:"x_shift"`
|
||||
YShift float32 `json:"y_shift"`
|
||||
Scale float32 `json:"scale"`
|
||||
}
|
||||
|
||||
// MaskPoint is a custom type for the various part of face where a mask should be placed.
|
||||
type MaskPoint string
|
||||
|
||||
// These are all the possible parts of the face for a mask.
|
||||
const (
|
||||
ForeheadPoint MaskPoint = "forehead"
|
||||
EyesPoint = "eyes"
|
||||
MouthPoint = "mouth"
|
||||
ChinPoint = "chin"
|
||||
)
|
||||
|
||||
// NewStickerSetOptions contains the optional parameters used in the CreateNewStickerSet method.
|
||||
type NewStickerSetOptions struct {
|
||||
StickerType StickerSetType `query:"sticker_type"`
|
||||
NeedsRepainting bool `query:"needs_repainting"`
|
||||
}
|
||||
|
||||
// InputSticker is a struct which describes a sticker to be added to a sticker set.
|
||||
type InputSticker struct {
|
||||
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
|
||||
Keywords *[]string `json:"keywords,omitempty"`
|
||||
Format StickerFormat `json:"format"`
|
||||
Sticker InputFile `json:"-"`
|
||||
EmojiList []string `json:"emoji_list"`
|
||||
}
|
||||
|
||||
// stickerEnvelope is a generic struct for all the various structs under the InputSticker interface.
|
||||
type stickerEnvelope struct {
|
||||
Sticker string `json:"sticker"`
|
||||
InputSticker
|
||||
}
|
||||
|
||||
// SendSticker is used to send static .WEBP or animated .TGS stickers.
|
||||
func (a API) SendSticker(stickerID string, chatID int64, opts *StickerOptions) (res APIResponseMessage, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("sticker", stickerID)
|
||||
vals.Set("chat_id", itoa(chatID))
|
||||
return res, client.get(a.base, "sendSticker", addValues(vals, opts), &res)
|
||||
}
|
||||
|
||||
// GetStickerSet is used to get a sticker set.
|
||||
func (a API) GetStickerSet(name string) (res APIResponseStickerSet, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("name", name)
|
||||
return res, client.get(a.base, "getStickerSet", vals, &res)
|
||||
}
|
||||
|
||||
// GetCustomEmojiStickers is used to get information about custom emoji stickers by their identifiers.
|
||||
func (a API) GetCustomEmojiStickers(customEmojiIDs ...string) (res APIResponseStickers, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
jsn, _ := json.Marshal(customEmojiIDs)
|
||||
vals.Set("custom_emoji_ids", string(jsn))
|
||||
return res, client.get(a.base, "getCustomEmojiStickers", vals, &res)
|
||||
}
|
||||
|
||||
// UploadStickerFile is used to upload a .PNG file with a sticker for later use in
|
||||
// CreateNewStickerSet and AddStickerToSet methods (can be used multiple times).
|
||||
func (a API) UploadStickerFile(userID int64, sticker InputFile, format StickerFormat) (res APIResponseFile, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("user_id", itoa(userID))
|
||||
vals.Set("sticker_format", string(format))
|
||||
return res, client.postFile(a.base, "uploadStickerFile", "sticker", sticker, InputFile{}, vals, &res)
|
||||
}
|
||||
|
||||
// CreateNewStickerSet is used to create a new sticker set owned by a user.
|
||||
func (a API) CreateNewStickerSet(userID int64, name, title string, stickers []InputSticker, opts *NewStickerSetOptions) (res APIResponseBool, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("user_id", itoa(userID))
|
||||
vals.Set("name", name)
|
||||
vals.Set("title", title)
|
||||
return res, client.postStickers(a.base, "createNewStickerSet", addValues(vals, opts), &res, stickers...)
|
||||
}
|
||||
|
||||
// AddStickerToSet is used to add a new sticker to a set created by the bot.
|
||||
func (a API) AddStickerToSet(userID int64, name string, sticker InputSticker) (res APIResponseBool, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("user_id", itoa(userID))
|
||||
vals.Set("name", name)
|
||||
return res, client.postStickers(a.base, "addStickerToSet", vals, &res, sticker)
|
||||
}
|
||||
|
||||
// SetStickerPositionInSet is used to move a sticker in a set created by the bot to a specific position.
|
||||
func (a API) SetStickerPositionInSet(sticker string, position int) (res APIResponseBase, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("sticker", sticker)
|
||||
vals.Set("position", itoa(int64(position)))
|
||||
return res, client.get(a.base, "setStickerPositionInSet", vals, &res)
|
||||
}
|
||||
|
||||
// DeleteStickerFromSet is used to delete a sticker from a set created by the bot.
|
||||
func (a API) DeleteStickerFromSet(sticker string) (res APIResponseBase, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("sticker", sticker)
|
||||
return res, client.get(a.base, "deleteStickerFromSet", vals, &res)
|
||||
}
|
||||
|
||||
// ReplaceStickerInSet is used to replace an existing sticker in a sticker set with a new one.
|
||||
// The method is equivalent to calling DeleteStickerFromSet, then AddStickerToSet, then SetStickerPositionInSet.
|
||||
func (a API) ReplaceStickerInSet(userID int64, name string, old_sticker string, sticker InputSticker) (res APIResponseBool, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("user_id", itoa(userID))
|
||||
vals.Set("name", name)
|
||||
vals.Set("old_sticker", old_sticker)
|
||||
return res, client.postStickers(a.base, "replaceStickerInSet", vals, &res, sticker)
|
||||
}
|
||||
|
||||
// SetStickerEmojiList is used to change the list of emoji assigned to a regular or custom emoji sticker.
|
||||
// The sticker must belong to a sticker set created by the bot.
|
||||
func (a API) SetStickerEmojiList(sticker string, emojis []string) (res APIResponseBool, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
jsn, _ := json.Marshal(emojis)
|
||||
|
||||
vals.Set("sticker", sticker)
|
||||
vals.Set("emoji_list", string(jsn))
|
||||
return res, client.get(a.base, "setStickerEmojiList", vals, &res)
|
||||
}
|
||||
|
||||
// SetStickerKeywords is used to change search keywords assigned to a regular or custom emoji sticker.
|
||||
// The sticker must belong to a sticker set created by the bot.
|
||||
func (a API) SetStickerKeywords(sticker string, keywords []string) (res APIResponseBool, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
jsn, _ := json.Marshal(keywords)
|
||||
|
||||
vals.Set("sticker", sticker)
|
||||
vals.Set("keywords", string(jsn))
|
||||
return res, client.get(a.base, "setStickerKeywords", vals, &res)
|
||||
}
|
||||
|
||||
// SetStickerMaskPosition is used to change the mask position of a mask sticker.
|
||||
// The sticker must belong to a sticker set that was created by the bot.
|
||||
func (a API) SetStickerMaskPosition(sticker string, mask MaskPosition) (res APIResponseBool, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
jsn, _ := json.Marshal(mask)
|
||||
|
||||
vals.Set("sticker", sticker)
|
||||
vals.Set("mask_position", string(jsn))
|
||||
return res, client.get(a.base, "setStickerMaskPosition", vals, &res)
|
||||
}
|
||||
|
||||
// SetStickerSetTitle is used to set the title of a created sticker set.
|
||||
func (a API) SetStickerSetTitle(name, title string) (res APIResponseBool, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("name", name)
|
||||
vals.Set("title", title)
|
||||
return res, client.get(a.base, "setStickerSetTitle", vals, &res)
|
||||
}
|
||||
|
||||
// SetStickerSetThumbnail is used to set the thumbnail of a sticker set.
|
||||
func (a API) SetStickerSetThumbnail(name string, userID int64, thumbnail InputFile, format StickerFormat) (res APIResponseBase, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("name", name)
|
||||
vals.Set("user_id", itoa(userID))
|
||||
vals.Set("format", string(format))
|
||||
return res, client.postFile(a.base, "setStickerSetThumbnail", "thumbnail", thumbnail, InputFile{}, vals, &res)
|
||||
}
|
||||
|
||||
// SetCustomEmojiStickerSetThumbnail is used to set the thumbnail of a custom emoji sticker set.
|
||||
func (a API) SetCustomEmojiStickerSetThumbnail(name, emojiID string) (res APIResponseBool, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("name", name)
|
||||
vals.Set("custom_emoji_id", emojiID)
|
||||
return res, client.get(a.base, "setCustomEmojiStickerSetThumbnail", vals, &res)
|
||||
}
|
||||
|
||||
// DeleteStickerSet is used to delete a sticker set that was created by the bot.
|
||||
func (a API) DeleteStickerSet(name string) (res APIResponseBool, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
vals.Set("name", name)
|
||||
return res, client.get(a.base, "DeleteStickerSet", vals, &res)
|
||||
}
|
||||
|
||||
// GetForumTopicIconStickers is used to get custom emoji stickers, which can be used as a forum topic icon by any user.
|
||||
func (a API) GetForumTopicIconStickers() (res APIResponseStickers, err error) {
|
||||
return res, client.get(a.base, "getForumTopicIconStickers", nil, &res)
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2018 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
stickerFile *File
|
||||
stickerSet *StickerSet
|
||||
stickerSetName = fmt.Sprintf("set%d_by_echotron_coverage_bot", time.Now().Unix())
|
||||
)
|
||||
|
||||
func TestUploadStickerFile(t *testing.T) {
|
||||
resp, err := api.UploadStickerFile(
|
||||
chatID,
|
||||
NewInputFilePath("assets/tests/echotron_test.png"),
|
||||
StaticFormat,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
stickerFile = resp.Result
|
||||
}
|
||||
|
||||
func TestCreateNewStickerSet(t *testing.T) {
|
||||
_, err := api.CreateNewStickerSet(
|
||||
chatID,
|
||||
stickerSetName,
|
||||
"Echotron Coverage Pack",
|
||||
[]InputSticker{
|
||||
{
|
||||
Sticker: NewInputFileID(stickerFile.FileID),
|
||||
EmojiList: []string{"🤖"},
|
||||
Format: StaticFormat,
|
||||
},
|
||||
{
|
||||
Sticker: NewInputFilePath("assets/tests/echotron_test.png"),
|
||||
EmojiList: []string{"🤖"},
|
||||
Format: StaticFormat,
|
||||
},
|
||||
{
|
||||
Sticker: NewInputFileURL(photoURL),
|
||||
EmojiList: []string{"🤖"},
|
||||
Format: StaticFormat,
|
||||
},
|
||||
},
|
||||
nil,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddStickerToSet(t *testing.T) {
|
||||
_, err := api.AddStickerToSet(
|
||||
chatID,
|
||||
stickerSetName,
|
||||
InputSticker{
|
||||
Sticker: NewInputFilePath("assets/tests/echotron_sticker.png"),
|
||||
EmojiList: []string{"🤖"},
|
||||
Format: StaticFormat,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCustomEmojiStickers(t *testing.T) {
|
||||
_, err := api.GetCustomEmojiStickers(
|
||||
"5407041870620531251",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetStickerSet(t *testing.T) {
|
||||
resp, err := api.GetStickerSet(
|
||||
stickerSetName,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
stickerSet = resp.Result
|
||||
}
|
||||
|
||||
func TestSetStickerPositionInSet(t *testing.T) {
|
||||
_, err := api.SetStickerPositionInSet(
|
||||
stickerSet.Stickers[1].FileID,
|
||||
0,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetStickerEmojiList(t *testing.T) {
|
||||
_, err := api.SetStickerEmojiList(
|
||||
stickerSet.Stickers[0].FileID,
|
||||
[]string{"🤖", "👾"},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetStickerKeywords(t *testing.T) {
|
||||
_, err := api.SetStickerKeywords(
|
||||
stickerSet.Stickers[0].FileID,
|
||||
[]string{"echotron"},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetStickerSetTitle(t *testing.T) {
|
||||
_, err := api.SetStickerSetTitle(
|
||||
stickerSetName,
|
||||
fmt.Sprintf("new_%s", stickerSetName),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplaceStickerInSet(t *testing.T) {
|
||||
_, err := api.ReplaceStickerInSet(
|
||||
chatID,
|
||||
stickerSetName,
|
||||
stickerSet.Stickers[0].FileID,
|
||||
InputSticker{
|
||||
Sticker: NewInputFileURL(photoURL),
|
||||
EmojiList: []string{"🤖"},
|
||||
Format: StaticFormat,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteStickerFromSet(t *testing.T) {
|
||||
_, err := api.DeleteStickerFromSet(
|
||||
stickerSet.Stickers[1].FileID,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendSticker(t *testing.T) {
|
||||
_, err := api.SendSticker(
|
||||
stickerSet.Stickers[0].FileID,
|
||||
chatID,
|
||||
nil,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetStickerSetThumbnail(t *testing.T) {
|
||||
_, err := api.SetStickerSetThumbnail(
|
||||
stickerSetName,
|
||||
chatID,
|
||||
NewInputFilePath("assets/tests/echotron_thumb.png"),
|
||||
StaticFormat,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteStickerSet(t *testing.T) {
|
||||
_, err := api.DeleteStickerSet(stickerSetName)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetForumTopicIconStickers(t *testing.T) {
|
||||
res, err := api.GetForumTopicIconStickers()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(res.Result) == 0 {
|
||||
t.Fatal("error: Telegram returned no forum topic icon stickers")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
package echotron
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestAPIResponseBase(_ *testing.T) {
|
||||
a := APIResponseBase{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseUpdate(_ *testing.T) {
|
||||
a := APIResponseUpdate{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseUser(_ *testing.T) {
|
||||
a := APIResponseUser{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseMessage(_ *testing.T) {
|
||||
a := APIResponseMessage{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseMessageArray(_ *testing.T) {
|
||||
a := APIResponseMessageArray{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseMessageID(_ *testing.T) {
|
||||
a := APIResponseMessageID{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseCommands(_ *testing.T) {
|
||||
a := APIResponseCommands{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseBool(_ *testing.T) {
|
||||
a := APIResponseBool{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseString(_ *testing.T) {
|
||||
a := APIResponseString{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseChat(_ *testing.T) {
|
||||
a := APIResponseChat{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseInviteLink(_ *testing.T) {
|
||||
a := APIResponseInviteLink{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseStickerSet(_ *testing.T) {
|
||||
a := APIResponseStickerSet{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseUserProfile(_ *testing.T) {
|
||||
a := APIResponseUserProfile{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseUserProfileAudios(_ *testing.T) {
|
||||
a := APIResponseUserProfileAudios{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseFile(_ *testing.T) {
|
||||
a := APIResponseFile{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseAdministrators(_ *testing.T) {
|
||||
a := APIResponseAdministrators{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseChatMember(_ *testing.T) {
|
||||
a := APIResponseChatMember{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseInteger(_ *testing.T) {
|
||||
a := APIResponseInteger{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponsePoll(_ *testing.T) {
|
||||
a := APIResponsePoll{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseGameHighScore(_ *testing.T) {
|
||||
a := APIResponseGameHighScore{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseWebhook(_ *testing.T) {
|
||||
a := APIResponseWebhook{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseSentWebAppMessage(_ *testing.T) {
|
||||
a := APIResponseSentWebAppMessage{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseMenuButton(_ *testing.T) {
|
||||
a := APIResponseMenuButton{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseChatAdministratorRights(_ *testing.T) {
|
||||
a := APIResponseChatAdministratorRights{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseBotDescription(_ *testing.T) {
|
||||
a := APIResponseBotDescription{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseBotShortDescription(_ *testing.T) {
|
||||
a := APIResponseBotShortDescription{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseBusinessConnection(_ *testing.T) {
|
||||
a := APIResponseBusinessConnection{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseStarTransactions(_ *testing.T) {
|
||||
a := APIResponseStarTransactions{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponsePreparedInlineMessage(_ *testing.T) {
|
||||
a := APIResponsePreparedInlineMessage{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestAPIResponseGifts(_ *testing.T) {
|
||||
a := APIResponseGifts{}
|
||||
a.Base()
|
||||
}
|
||||
|
||||
func TestInputMediaPhoto(_ *testing.T) {
|
||||
i := InputMediaPhoto{}
|
||||
i.media()
|
||||
i.thumbnail()
|
||||
i.groupable()
|
||||
}
|
||||
|
||||
func TestInputMediaVideo(_ *testing.T) {
|
||||
i := InputMediaVideo{}
|
||||
i.media()
|
||||
i.thumbnail()
|
||||
i.groupable()
|
||||
}
|
||||
|
||||
func TestInputMediaAnimation(_ *testing.T) {
|
||||
i := InputMediaAnimation{}
|
||||
i.media()
|
||||
i.thumbnail()
|
||||
}
|
||||
|
||||
func TestInputMediaAudio(_ *testing.T) {
|
||||
i := InputMediaAudio{}
|
||||
i.media()
|
||||
i.thumbnail()
|
||||
i.groupable()
|
||||
}
|
||||
|
||||
func TestInputMediaDocument(_ *testing.T) {
|
||||
i := InputMediaDocument{}
|
||||
i.media()
|
||||
i.thumbnail()
|
||||
i.groupable()
|
||||
}
|
||||
|
||||
func TestInputPaidMediaPhoto(_ *testing.T) {
|
||||
i := InputPaidMediaPhoto{}
|
||||
i.media()
|
||||
i.groupable()
|
||||
i.thumbnail()
|
||||
}
|
||||
|
||||
func TestInputPaidMediaVideo(_ *testing.T) {
|
||||
i := InputPaidMediaVideo{}
|
||||
i.media()
|
||||
i.groupable()
|
||||
i.thumbnail()
|
||||
}
|
||||
|
||||
func TestInputProfilePhotoStatic(_ *testing.T) {
|
||||
i := InputProfilePhotoStatic{}
|
||||
i.file()
|
||||
i.inputProfilePhoto()
|
||||
}
|
||||
|
||||
func TestInputProfilePhotoAnimated(_ *testing.T) {
|
||||
i := InputProfilePhotoAnimated{}
|
||||
i.file()
|
||||
i.inputProfilePhoto()
|
||||
}
|
||||
|
||||
func TestBackgroundFillSolid(_ *testing.T) {
|
||||
b := BackgroundFillSolid{}
|
||||
b.ImplementsBackgroundFill()
|
||||
}
|
||||
|
||||
func TestBackgroundFillGradient(_ *testing.T) {
|
||||
b := BackgroundFillGradient{}
|
||||
b.ImplementsBackgroundFill()
|
||||
}
|
||||
|
||||
func TestBackgroundFillFreeformGradient(_ *testing.T) {
|
||||
b := BackgroundFillFreeformGradient{}
|
||||
b.ImplementsBackgroundFill()
|
||||
}
|
||||
|
||||
func TestBackgroundTypeFill(_ *testing.T) {
|
||||
b := BackgroundTypeFill{}
|
||||
b.ImplementsBackgroundType()
|
||||
}
|
||||
|
||||
func TestBackgroundTypeWallpaper(_ *testing.T) {
|
||||
b := BackgroundTypeWallpaper{}
|
||||
b.ImplementsBackgroundType()
|
||||
}
|
||||
|
||||
func TestBackgroundTypePattern(_ *testing.T) {
|
||||
b := BackgroundTypePattern{}
|
||||
b.ImplementsBackgroundType()
|
||||
}
|
||||
|
||||
func TestBackgroundTypeChatTheme(_ *testing.T) {
|
||||
b := BackgroundTypeChatTheme{}
|
||||
b.ImplementsBackgroundType()
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Echotron
|
||||
* Copyright (C) 2022 The Echotron Contributors
|
||||
*
|
||||
* Echotron is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Echotron is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package echotron
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// WebAppInfo contains information about a Web App.
|
||||
type WebAppInfo struct {
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// SentWebAppMessage contains information about an inline message sent
|
||||
// by a Web App on behalf of a user.
|
||||
type SentWebAppMessage struct {
|
||||
InlineMessageID string `json:"inline_message_id,omitempty"`
|
||||
}
|
||||
|
||||
// WebAppData contains data sent from a Web App to the bot.
|
||||
type WebAppData struct {
|
||||
Data string `json:"data"`
|
||||
ButtonText string `json:"button_text"`
|
||||
}
|
||||
|
||||
// AnswerWebAppQuery is used to set the result of an interaction with a Web App
|
||||
// and send a corresponding message on behalf of the user to the chat from which
|
||||
// the query originated.
|
||||
func (a API) AnswerWebAppQuery(webAppQueryID string, result InlineQueryResult) (res APIResponseSentWebAppMessage, err error) {
|
||||
var vals = make(url.Values)
|
||||
|
||||
resultJson, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
vals.Set("web_app_query_id", webAppQueryID)
|
||||
vals.Set("result", string(resultJson))
|
||||
return res, client.get(a.base, "answerWebAppQuery", vals, &res)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class JWTConfig(BaseModel):
|
||||
SECRET_KEY: str
|
||||
ALGORITHM: str = 'HS256'
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7 # 7 days
|
||||
|
||||
|
||||
class JWTBase:
|
||||
def __init__(self, config: JWTConfig) -> None:
|
||||
self.config = config
|
||||
@@ -0,0 +1,3 @@
|
||||
__all__ = ['LoggerConfig', 'init']
|
||||
|
||||
from .logger import LoggerConfig, init
|
||||
@@ -0,0 +1,84 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class ColoredConsoleFormatter(logging.Formatter):
|
||||
TIME_COLOR = '\033[38;2;89;89;89m'
|
||||
RESET = '\033[0m'
|
||||
BOLD = '\033[1m'
|
||||
DARK_CYAN = '\033[36m'
|
||||
DARK_YELLOW = '\033[33m'
|
||||
RED = '\033[91m'
|
||||
|
||||
LEVEL_COLORS = {
|
||||
logging.DEBUG: '\033[36m',
|
||||
logging.INFO: '\033[32m',
|
||||
logging.WARNING: '\033[33m',
|
||||
logging.ERROR: RED,
|
||||
logging.CRITICAL: '\033[35m',
|
||||
}
|
||||
|
||||
LEVEL_NAMES = {
|
||||
logging.DEBUG: 'DBG',
|
||||
logging.INFO: 'INF',
|
||||
logging.WARNING: 'WRN',
|
||||
logging.ERROR: 'ERR',
|
||||
logging.CRITICAL: 'CRT',
|
||||
}
|
||||
|
||||
def format(self, record: logging.LogRecord) -> str:
|
||||
timestamp = f'{self.TIME_COLOR}{datetime.fromtimestamp(record.created).strftime("%H:%M:%S")}{self.RESET}'
|
||||
|
||||
level_name = self.LEVEL_NAMES.get(record.levelno, record.levelname[:3])
|
||||
level_color = self.LEVEL_COLORS.get(record.levelno, '')
|
||||
level = f'{level_color}{level_name}{self.RESET}'
|
||||
|
||||
message_color = self.RED if record.levelno >= logging.ERROR else ''
|
||||
message = f'{message_color}{self.BOLD}{record.getMessage()}{self.RESET}'
|
||||
|
||||
# Add extra fields
|
||||
extra_parts = []
|
||||
for key, value in record.__dict__.items():
|
||||
if key not in [
|
||||
'name',
|
||||
'msg',
|
||||
'args',
|
||||
'created',
|
||||
'filename',
|
||||
'funcName',
|
||||
'levelname',
|
||||
'levelno',
|
||||
'lineno',
|
||||
'module',
|
||||
'msecs',
|
||||
'message',
|
||||
'pathname',
|
||||
'process',
|
||||
'processName',
|
||||
'relativeCreated',
|
||||
'thread',
|
||||
'threadName',
|
||||
'exc_info',
|
||||
'exc_text',
|
||||
'stack_info',
|
||||
'app_name',
|
||||
'app_version',
|
||||
'taskName',
|
||||
'color_message',
|
||||
]:
|
||||
value_color = self.RED if key == 'error' else self.DARK_YELLOW
|
||||
extra_parts.append(f'{self.DARK_CYAN}{key}{self.RESET}={value_color}{value}{self.RESET}')
|
||||
|
||||
if extra_parts:
|
||||
message += f' {" ".join(extra_parts)}'
|
||||
|
||||
if record.levelno >= logging.WARNING:
|
||||
location = f'{self.TIME_COLOR}{record.module}:{record.lineno}{self.RESET}'
|
||||
result = f'{timestamp} {level} {location} {message}'
|
||||
else:
|
||||
result = f'{timestamp} {level} {message}'
|
||||
|
||||
if record.exc_info:
|
||||
result += '\n' + self.formatException(record.exc_info)
|
||||
|
||||
return result
|
||||
@@ -0,0 +1,55 @@
|
||||
import json
|
||||
import logging
|
||||
from datetime import UTC, datetime
|
||||
|
||||
|
||||
class JSONFormatter(logging.Formatter):
|
||||
def format(self, record: logging.LogRecord) -> str:
|
||||
log_data = {
|
||||
'timestamp': datetime.fromtimestamp(record.created, UTC).isoformat(),
|
||||
'level': record.levelname,
|
||||
'message': record.getMessage(),
|
||||
'module': record.module,
|
||||
'package': record.name,
|
||||
'app_name': getattr(record, 'app_name', 'unknown'),
|
||||
'app_version': getattr(record, 'app_version', 'unknown'),
|
||||
}
|
||||
|
||||
if record.levelno >= logging.ERROR:
|
||||
log_data['location'] = f'{record.pathname}:{record.lineno}'
|
||||
|
||||
if record.exc_info:
|
||||
exc_type = record.exc_info[0]
|
||||
log_data['error_type'] = exc_type.__name__ if exc_type else 'Unknown'
|
||||
log_data['error_message'] = str(record.exc_info[1])
|
||||
log_data['traceback'] = self.formatException(record.exc_info)
|
||||
|
||||
for key, value in record.__dict__.items():
|
||||
if key not in {
|
||||
'name',
|
||||
'msg',
|
||||
'args',
|
||||
'created',
|
||||
'filename',
|
||||
'funcName',
|
||||
'levelname',
|
||||
'levelno',
|
||||
'lineno',
|
||||
'module',
|
||||
'msecs',
|
||||
'message',
|
||||
'pathname',
|
||||
'process',
|
||||
'processName',
|
||||
'relativeCreated',
|
||||
'thread',
|
||||
'threadName',
|
||||
'exc_info',
|
||||
'exc_text',
|
||||
'stack_info',
|
||||
'app_name',
|
||||
'app_version',
|
||||
}:
|
||||
log_data[key] = value
|
||||
|
||||
return json.dumps(log_data, ensure_ascii=False)
|
||||
@@ -0,0 +1,65 @@
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pydantic
|
||||
|
||||
from .console_formatter import ColoredConsoleFormatter
|
||||
from .json_formatter import JSONFormatter
|
||||
|
||||
|
||||
class LoggerConfig(pydantic.BaseModel):
|
||||
APP_NAME: str
|
||||
APP_VERSION: str
|
||||
LEVEL: int = logging.INFO
|
||||
PRETTY_CONSOLE: bool = False
|
||||
|
||||
@pydantic.field_validator('APP_VERSION')
|
||||
@classmethod
|
||||
def normalize_app_version(cls, v: str) -> str:
|
||||
parts = v.removeprefix('v').split('.')
|
||||
if len(parts) < 2 or any(not part.isdigit() for part in parts):
|
||||
raise ValueError('APP_VERSION must look like 1.2.0')
|
||||
commit_count = _get_git_commit_count()
|
||||
if not commit_count:
|
||||
return f'v{".".join(parts)}'
|
||||
parts[-1] = commit_count
|
||||
return f'v{".".join(parts)}'
|
||||
|
||||
|
||||
def _get_git_commit_count() -> str | None:
|
||||
commit_count = os.getenv('GIT_COMMIT_COUNT')
|
||||
if commit_count is None:
|
||||
return None
|
||||
normalized = commit_count.strip()
|
||||
return normalized or None
|
||||
|
||||
|
||||
def init(config: LoggerConfig) -> None:
|
||||
root_logger = logging.getLogger()
|
||||
root_logger.setLevel(config.LEVEL)
|
||||
root_logger.handlers.clear()
|
||||
|
||||
handler = logging.StreamHandler(sys.stdout)
|
||||
handler.setLevel(config.LEVEL)
|
||||
|
||||
formatter = ColoredConsoleFormatter() if config.PRETTY_CONSOLE else JSONFormatter()
|
||||
handler.setFormatter(formatter)
|
||||
root_logger.addHandler(handler)
|
||||
|
||||
for logger_name in ['uvicorn', 'uvicorn.access', 'uvicorn.error']:
|
||||
uvicorn_logger = logging.getLogger(logger_name)
|
||||
uvicorn_logger.handlers = [handler]
|
||||
uvicorn_logger.propagate = False
|
||||
|
||||
old_factory = logging.getLogRecordFactory()
|
||||
|
||||
def record_factory(*args: object, **kwargs: object) -> logging.LogRecord:
|
||||
record = old_factory(*args, **kwargs)
|
||||
record.app_name = config.APP_NAME
|
||||
record.app_version = config.APP_VERSION
|
||||
return record
|
||||
|
||||
logging.setLogRecordFactory(record_factory)
|
||||
|
||||
logging.info('Logger initialized', extra={'app': config.APP_NAME, 'version': config.APP_VERSION})
|
||||
@@ -0,0 +1,14 @@
|
||||
import logging
|
||||
|
||||
import pydantic
|
||||
from aiogram import Bot
|
||||
|
||||
|
||||
class TelegramConfig(pydantic.BaseModel):
|
||||
TOKEN: str
|
||||
|
||||
|
||||
class TelegramBase:
|
||||
def __init__(self, config: TelegramConfig) -> None:
|
||||
self.bot: Bot = Bot(token=config.TOKEN)
|
||||
logging.info('Telegram bot initialized')
|
||||
@@ -0,0 +1,65 @@
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
import pydantic
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class WorkerConfig(pydantic.BaseModel):
|
||||
INTERVAL_SECONDS: int = 60
|
||||
|
||||
|
||||
class WorkerBase:
|
||||
def __init__(self, config: WorkerConfig) -> None:
|
||||
self.config = config
|
||||
self._task: asyncio.Task[None] | None = None
|
||||
self._stop_event = asyncio.Event()
|
||||
|
||||
log.info('Worker initialized (interval=%ds)', config.INTERVAL_SECONDS)
|
||||
|
||||
async def _cycle_func(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
async def start(self) -> None:
|
||||
if self._task is not None:
|
||||
log.warning('Worker already running')
|
||||
return
|
||||
|
||||
self._stop_event.clear()
|
||||
self._task = asyncio.create_task(self._run())
|
||||
log.info('Worker started')
|
||||
|
||||
async def stop(self) -> None:
|
||||
if self._task is None:
|
||||
log.warning('Worker not running')
|
||||
return
|
||||
|
||||
self._stop_event.set()
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(self._task, timeout=5.0)
|
||||
except TimeoutError:
|
||||
log.warning('Worker did not stop in time, cancelling')
|
||||
self._task.cancel()
|
||||
try:
|
||||
await self._task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
except asyncio.CancelledError:
|
||||
log.info('Worker task cancelled')
|
||||
|
||||
self._task = None
|
||||
log.info('Worker stopped')
|
||||
|
||||
async def _run(self) -> None:
|
||||
while not self._stop_event.is_set():
|
||||
try:
|
||||
await self._cycle_func()
|
||||
except Exception:
|
||||
log.exception('Error in worker cycle')
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(self._stop_event.wait(), timeout=self.config.INTERVAL_SECONDS)
|
||||
except TimeoutError:
|
||||
pass # Время вышло, продолжаем
|
||||
@@ -0,0 +1,59 @@
|
||||
import datetime
|
||||
import uuid
|
||||
|
||||
import jwt
|
||||
import pydantic
|
||||
|
||||
from shared.jwt_base import JWTBase
|
||||
from src.usecase import JWTEncoder
|
||||
|
||||
|
||||
class JWTPayload(pydantic.BaseModel):
|
||||
user_id: uuid.UUID
|
||||
telegram_id: int
|
||||
username: str | None
|
||||
|
||||
|
||||
class JWT(JWTBase, JWTEncoder):
|
||||
def encode_access_token(
|
||||
self,
|
||||
user_id: uuid.UUID,
|
||||
telegram_id: int,
|
||||
username: str | None = None,
|
||||
) -> str:
|
||||
expire = datetime.datetime.now(datetime.UTC) + datetime.timedelta(
|
||||
minutes=self.config.ACCESS_TOKEN_EXPIRE_MINUTES
|
||||
)
|
||||
|
||||
payload = {
|
||||
'sub': str(user_id),
|
||||
'telegram_id': telegram_id,
|
||||
'username': username,
|
||||
'exp': expire,
|
||||
'type': 'access',
|
||||
}
|
||||
|
||||
encoded: str = jwt.encode(payload, self.config.SECRET_KEY, algorithm=self.config.ALGORITHM)
|
||||
return encoded
|
||||
|
||||
def decode_access_token(self, token: str) -> JWTPayload:
|
||||
try:
|
||||
payload = jwt.decode(token, self.config.SECRET_KEY, algorithms=[self.config.ALGORITHM])
|
||||
|
||||
if payload.get('type') != 'access':
|
||||
raise ValueError('Invalid token type')
|
||||
|
||||
user_id = payload.get('sub')
|
||||
if not user_id:
|
||||
raise ValueError('Token missing subject')
|
||||
|
||||
return JWTPayload(
|
||||
user_id=uuid.UUID(user_id),
|
||||
telegram_id=payload['telegram_id'],
|
||||
username=payload.get('username'),
|
||||
)
|
||||
|
||||
except jwt.ExpiredSignatureError as e:
|
||||
raise ValueError('Token has expired') from e
|
||||
except jwt.InvalidTokenError as e:
|
||||
raise ValueError('Invalid token') from e
|
||||
@@ -0,0 +1,83 @@
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
from pydantic import BaseModel
|
||||
|
||||
from src.usecase import Parser
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FetchChannelResponse(BaseModel):
|
||||
telegram_id: int
|
||||
username: str | None
|
||||
title: str | None
|
||||
access_hash: int | None
|
||||
pts: int | None
|
||||
|
||||
|
||||
class ParserClient(Parser):
|
||||
def __init__(self, base_url: str, timeout: float = 5.0):
|
||||
self.base_url = base_url.rstrip('/')
|
||||
self.timeout = timeout
|
||||
|
||||
async def fetch_telegram_channel(self, username: str) -> FetchChannelResponse | None:
|
||||
username = username.lstrip('@')
|
||||
|
||||
url = f'{self.base_url}/fetch-telegram-channel'
|
||||
params = {'username': username}
|
||||
|
||||
async with httpx.AsyncClient(timeout=self.timeout) as client:
|
||||
try:
|
||||
response = await client.get(url, params=params)
|
||||
|
||||
if response.status_code == 404:
|
||||
log.info('Channel @%s not found in Telegram', username)
|
||||
return None
|
||||
|
||||
response.raise_for_status()
|
||||
data: dict[str, Any] = response.json()
|
||||
return FetchChannelResponse.model_validate(data)
|
||||
|
||||
except httpx.HTTPStatusError as e:
|
||||
if e.response.status_code == 404:
|
||||
return None
|
||||
log.error('Parser HTTP error for @%s: %s', username, e)
|
||||
raise
|
||||
except httpx.TimeoutException:
|
||||
log.error('Parser timeout for @%s', username)
|
||||
raise
|
||||
except Exception as e:
|
||||
log.error('Parser unexpected error for @%s: %s', username, e)
|
||||
raise
|
||||
|
||||
async def resolve_telegram_channel_by_invite(self, invite_link: str) -> FetchChannelResponse | None:
|
||||
invite_link = invite_link.strip()
|
||||
|
||||
url = f'{self.base_url}/resolve-channel-by-invite'
|
||||
payload = {'invite_link': invite_link}
|
||||
|
||||
async with httpx.AsyncClient(timeout=self.timeout) as client:
|
||||
try:
|
||||
response = await client.post(url, json=payload)
|
||||
|
||||
if response.status_code == 404:
|
||||
log.info('Channel not found by invite link')
|
||||
return None
|
||||
|
||||
response.raise_for_status()
|
||||
data: dict[str, Any] = response.json()
|
||||
return FetchChannelResponse.model_validate(data)
|
||||
|
||||
except httpx.HTTPStatusError as e:
|
||||
if e.response.status_code == 404:
|
||||
return None
|
||||
log.error('Parser HTTP error for invite link: %s', e)
|
||||
raise
|
||||
except httpx.TimeoutException:
|
||||
log.error('Parser timeout for invite link')
|
||||
raise
|
||||
except Exception as e:
|
||||
log.error('Parser unexpected error for invite link: %s', e)
|
||||
raise
|
||||