新增 LINE 渠道扩展,支持在 Yuxi 平台中集成 LINE 即时通讯渠道。 包含以下功能模块: - bot: LINE Bot 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - streaming: 流式消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - signature: 请求签名验证 - token_manager: Token 管理 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - session: 会话管理 - flex_templates: Flex 模板消息 - card_command: 卡片指令处理 - template_messages: 模板消息 - rich_menu: 富菜单管理 - actions: 动作处理 - directives: 指令处理 - delivery: 消息送达确认 - loading: 加载动画 - media: 媒体资源处理 - types: 类型定义
69 lines
1.7 KiB
Python
69 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
|
|
|
|
@dataclass
|
|
class QuickReplyItem:
|
|
image_url: str | None = None
|
|
action: dict = field(default_factory=dict)
|
|
|
|
|
|
def create_quick_reply(items: list[dict]) -> dict:
|
|
return {"items": items}
|
|
|
|
|
|
def build_quick_reply_items(labels: list[str]) -> list[dict]:
|
|
return [
|
|
{
|
|
"type": "action",
|
|
"action": {"type": "message", "label": label[:20], "text": label},
|
|
}
|
|
for label in labels[:13]
|
|
]
|
|
|
|
|
|
def create_quick_reply_message(text: str, items: list[str]) -> dict:
|
|
return {
|
|
"type": "text",
|
|
"text": text,
|
|
"quickReply": {"items": build_quick_reply_items(items)},
|
|
}
|
|
|
|
|
|
def create_message_action(label: str, text: str) -> dict:
|
|
return {"type": "message", "label": label[:20], "text": text}
|
|
|
|
|
|
def create_uri_action(label: str, uri: str) -> dict:
|
|
return {"type": "uri", "label": label[:20], "uri": uri}
|
|
|
|
|
|
def create_postback_action(label: str, data: str, display_text: str | None = None) -> dict:
|
|
action = {"type": "postback", "label": label[:20], "data": data}
|
|
if display_text:
|
|
action["displayText"] = display_text
|
|
return action
|
|
|
|
|
|
def create_datetime_picker_action(
|
|
label: str,
|
|
data: str,
|
|
mode: str = "datetime",
|
|
initial: str | None = None,
|
|
max_value: str | None = None,
|
|
min_value: str | None = None,
|
|
) -> dict:
|
|
action = {
|
|
"type": "datetimePicker",
|
|
"label": label[:20],
|
|
"data": data,
|
|
"mode": mode,
|
|
}
|
|
if initial:
|
|
action["initial"] = initial
|
|
if max_value:
|
|
action["max"] = max_value
|
|
if min_value:
|
|
action["min"] = min_value
|
|
return action |