ForcePilot/backend/package/yuxi/channels/adapters/mattermost/gateway.py
Kris 002d601d1b feat(mattermost): 实现完整的 Mattermost 适配器模块
新增 Mattermost 渠道完整实现,包含适配器核心、消息处理、交互回调、命令支持、安全校验、多账号管理等功能,支持机器人消息发送、交互按钮、命令注册、投票功能以及配置动态修改等特性。
2026-05-12 00:46:12 +08:00

57 lines
1.5 KiB
Python

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)