新增 LINE 官方账号对接的全套功能,包括: 1. 基础的 Bot 探测、会话解析、消息格式化能力 2. 富媒体消息模板、快速回复、卡片指令支持 3. Webhook 签名验证、重放防护、多账户路由管理 4. 消息发送、回复、分块传输、用户绑定管理 5. 交互式配置向导与诊断工具
28 lines
748 B
Python
28 lines
748 B
Python
from __future__ import annotations
|
|
|
|
|
|
def build_quick_reply_items(options: list[str]) -> list[dict]:
|
|
items = []
|
|
for label in options[:13]:
|
|
if not label or not label.strip():
|
|
continue
|
|
safe_label = label.strip()[:20]
|
|
items.append(
|
|
{
|
|
"type": "action",
|
|
"action": {"type": "message", "label": safe_label, "text": label},
|
|
}
|
|
)
|
|
return items
|
|
|
|
|
|
def build_text_with_quick_reply(text: str, options: list[str]) -> dict:
|
|
if not options:
|
|
return {"type": "text", "text": text[:5000]}
|
|
items = build_quick_reply_items(options)
|
|
return {
|
|
"type": "text",
|
|
"text": text[:5000],
|
|
"quickReply": {"items": items},
|
|
}
|