ForcePilot/backend/package/yuxi/channels/adapters/mattermost/gateway.py

57 lines
1.5 KiB
Python
Raw Normal View History

from __future__ import annotations
from typing import Any
class MattermostGateway:
"""Mattermost Gateway 适配器 — HTTP 回调端点 + 账户生命周期管理"""
def __init__(self, adapter: Any):
self._adapter = adapter
@property
def channel_id(self) -> str:
return "mattermost"
def resolve_gateway_auth_bypass_paths(self) -> list[str]:
return [
"/mattermost/slash",
"/mattermost/interactions",
]
async def start_account(self, account_id: str) -> dict:
return {
"account_id": account_id,
"status": "started",
"gateway_paths": self.resolve_gateway_auth_bypass_paths(),
}
async def logout_account(self, ctx: Any) -> None:
if self._adapter:
await self._adapter.disconnect()
async def login_with_qr_start(self, force: bool = False, timeout_ms: int = 60000) -> str:
return ""
async def handle_slash_request(
self,
body: bytes,
headers: dict,
remote_ip: str = "",
account_id: str = "default",
) -> dict:
from .slash_http import handle_slash_command
return await handle_slash_command(body, headers, self._adapter)
async def handle_interaction_request(
self,
body: bytes,
headers: dict,
remote_ip: str = "",
account_id: str = "default",
) -> dict:
from .interaction_http import handle_interaction
return await handle_interaction(body, headers, remote_ip, self._adapter)