新增 LINE 官方账号对接的全套功能,包括: 1. 基础的 Bot 探测、会话解析、消息格式化能力 2. 富媒体消息模板、快速回复、卡片指令支持 3. Webhook 签名验证、重放防护、多账户路由管理 4. 消息发送、回复、分块传输、用户绑定管理 5. 交互式配置向导与诊断工具
59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
|
|
def build_bubble_message(
|
|
header_text: str | None = None,
|
|
body_sections: list[dict] | None = None,
|
|
footer_text: str | None = None,
|
|
hero_url: str | None = None,
|
|
alt_text: str = "Flex Message",
|
|
) -> dict:
|
|
contents: dict = {"type": "bubble"}
|
|
|
|
if hero_url:
|
|
contents["hero"] = {
|
|
"type": "image",
|
|
"url": hero_url,
|
|
"size": "full",
|
|
"aspectRatio": "20:13",
|
|
"aspectMode": "cover",
|
|
}
|
|
|
|
if header_text:
|
|
contents["header"] = {
|
|
"type": "box",
|
|
"layout": "vertical",
|
|
"contents": [{"type": "text", "text": header_text, "weight": "bold", "size": "lg"}],
|
|
}
|
|
|
|
if body_sections:
|
|
contents["body"] = {
|
|
"type": "box",
|
|
"layout": "vertical",
|
|
"contents": list(body_sections),
|
|
}
|
|
|
|
if footer_text:
|
|
contents["footer"] = {
|
|
"type": "box",
|
|
"layout": "vertical",
|
|
"contents": [{"type": "text", "text": footer_text, "size": "sm", "color": "#aaaaaa"}],
|
|
}
|
|
|
|
return {
|
|
"type": "flex",
|
|
"altText": alt_text[:400],
|
|
"contents": contents,
|
|
}
|
|
|
|
|
|
def build_carousel_message(bubbles: list[dict], alt_text: str = "Carousel Message") -> dict:
|
|
return {
|
|
"type": "flex",
|
|
"altText": alt_text[:400],
|
|
"contents": {
|
|
"type": "carousel",
|
|
"contents": bubbles[:12],
|
|
},
|
|
}
|