6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
72 lines
2.0 KiB
Python
72 lines
2.0 KiB
Python
"""Platform adapter interfaces for messaging gateways."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from abc import ABC, abstractmethod
|
|
from collections.abc import AsyncIterator
|
|
from dataclasses import dataclass, field
|
|
from typing import Any
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ParsedInboundEvent:
|
|
platform: str
|
|
event_kind: str
|
|
external_peer_id: str | None
|
|
external_peer_kind: str
|
|
external_message_id: str | None
|
|
external_user_id: str | None
|
|
text: str | None
|
|
raw_payload: dict[str, Any]
|
|
display_name: str | None = None
|
|
username: str | None = None
|
|
metadata: dict[str, Any] = field(default_factory=dict)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class PlatformSendResult:
|
|
external_message_id: str
|
|
raw_response: dict[str, Any] = field(default_factory=dict)
|
|
|
|
|
|
class BasePlatformAdapter(ABC):
|
|
platform: str
|
|
|
|
@abstractmethod
|
|
def parse_inbound(self, raw_payload: dict[str, Any]) -> ParsedInboundEvent:
|
|
"""Parse a provider webhook/update into the gateway's normalized shape."""
|
|
|
|
@abstractmethod
|
|
async def send_message(
|
|
self,
|
|
*,
|
|
external_peer_id: str,
|
|
text: str,
|
|
parse_mode: str | None = None,
|
|
reply_to_message_id: str | None = None,
|
|
) -> PlatformSendResult:
|
|
"""Send a new platform message."""
|
|
|
|
@abstractmethod
|
|
async def edit_message(
|
|
self,
|
|
*,
|
|
external_peer_id: str,
|
|
external_message_id: str,
|
|
text: str,
|
|
parse_mode: str | None = None,
|
|
) -> PlatformSendResult:
|
|
"""Edit an existing platform message."""
|
|
|
|
@abstractmethod
|
|
async def validate_credentials(self) -> dict[str, Any]:
|
|
"""Validate configured credentials and return account metadata."""
|
|
|
|
async def fetch_updates(
|
|
self, *, offset: int | None
|
|
) -> AsyncIterator[dict[str, Any]]:
|
|
"""Yield provider updates for long-polling adapters."""
|
|
if False:
|
|
yield {} # pragma: no cover
|
|
raise NotImplementedError("This adapter does not support long-polling")
|