新增 Facebook Messenger 渠道扩展,支持在 Yuxi 平台中集成 Messenger 即时通讯渠道。 包含以下功能模块: - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - streaming: 流式消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - actions: 动作处理 - template: 消息模板 - quick_reply: 快捷回复 - private_reply: 私密回复 - handover: 转人工切换 - persona: 人设管理 - profile: 主页配置 - user: 用户信息 - insights: 数据洞察 - notification: 通知推送 - media: 媒体资源处理 - types: 类型定义
164 lines
3.9 KiB
Python
164 lines
3.9 KiB
Python
BUTTON_MAX = 3
|
|
BUTTON_TITLE_MAX = 20
|
|
GENERIC_CARD_MAX = 10
|
|
CARD_TITLE_MAX = 80
|
|
CARD_SUBTITLE_MAX = 80
|
|
|
|
|
|
def build_button_template(text: str, buttons: list[dict]) -> dict:
|
|
return {
|
|
"text": text[:640],
|
|
"buttons": buttons[:BUTTON_MAX],
|
|
}
|
|
|
|
|
|
def build_generic_template(cards: list[dict], image_aspect_ratio: str = "horizontal") -> dict:
|
|
return {
|
|
"elements": cards[:GENERIC_CARD_MAX],
|
|
"image_aspect_ratio": image_aspect_ratio,
|
|
}
|
|
|
|
|
|
def build_media_template(media_type: str, url: str, button: dict | None = None) -> dict:
|
|
result: dict = {
|
|
"elements": [
|
|
{
|
|
"media_type": media_type,
|
|
"url": url,
|
|
}
|
|
],
|
|
}
|
|
if button:
|
|
result["elements"][0]["buttons"] = [button]
|
|
return result
|
|
|
|
|
|
def build_receipt_template(
|
|
recipient_name: str,
|
|
order_number: str,
|
|
currency: str,
|
|
payment_method: str,
|
|
summary: dict,
|
|
elements: list[dict] | None = None,
|
|
address: dict | None = None,
|
|
adjustments: list[dict] | None = None,
|
|
) -> dict:
|
|
result: dict = {
|
|
"recipient_name": recipient_name,
|
|
"order_number": order_number,
|
|
"currency": currency,
|
|
"payment_method": payment_method,
|
|
"summary": summary,
|
|
}
|
|
if elements:
|
|
result["elements"] = elements[:100]
|
|
if address:
|
|
result["address"] = address
|
|
if adjustments:
|
|
result["adjustments"] = adjustments
|
|
return result
|
|
|
|
|
|
def build_url_button(title: str, url: str, webview_height_ratio: str = "full") -> dict:
|
|
return {
|
|
"type": "web_url",
|
|
"url": url,
|
|
"title": title[:BUTTON_TITLE_MAX],
|
|
"webview_height_ratio": webview_height_ratio,
|
|
}
|
|
|
|
|
|
def build_postback_button(title: str, payload: str) -> dict:
|
|
return {
|
|
"type": "postback",
|
|
"title": title[:BUTTON_TITLE_MAX],
|
|
"payload": payload,
|
|
}
|
|
|
|
|
|
def build_phone_number_button(title: str, phone_number: str) -> dict:
|
|
return {
|
|
"type": "phone_number",
|
|
"title": title[:BUTTON_TITLE_MAX],
|
|
"payload": phone_number,
|
|
}
|
|
|
|
|
|
def build_share_button() -> dict:
|
|
return {"type": "element_share"}
|
|
|
|
|
|
def build_login_button(url: str) -> dict:
|
|
return {"type": "account_link", "url": url}
|
|
|
|
|
|
def build_logout_button() -> dict:
|
|
return {"type": "account_unlink"}
|
|
|
|
|
|
def build_generic_card(
|
|
title: str,
|
|
subtitle: str = "",
|
|
image_url: str = "",
|
|
buttons: list[dict] | None = None,
|
|
default_action: dict | None = None,
|
|
) -> dict:
|
|
card: dict = {
|
|
"title": title[:CARD_TITLE_MAX],
|
|
}
|
|
if subtitle:
|
|
card["subtitle"] = subtitle[:CARD_SUBTITLE_MAX]
|
|
if image_url:
|
|
card["image_url"] = image_url
|
|
if buttons:
|
|
card["buttons"] = buttons[:BUTTON_MAX]
|
|
if default_action:
|
|
card["default_action"] = default_action
|
|
return card
|
|
|
|
|
|
def build_airline_boarding_pass_template(
|
|
intro_message: str,
|
|
locale: str,
|
|
boarding_pass: list[dict],
|
|
) -> dict:
|
|
return {
|
|
"template_type": "airline_boardingpass",
|
|
"intro_message": intro_message,
|
|
"locale": locale,
|
|
"boarding_pass": boarding_pass,
|
|
}
|
|
|
|
|
|
def build_airline_checkin_template(
|
|
intro_message: str,
|
|
locale: str,
|
|
flight_info: list[dict],
|
|
checkin_url: str,
|
|
) -> dict:
|
|
return {
|
|
"template_type": "airline_checkin",
|
|
"intro_message": intro_message,
|
|
"locale": locale,
|
|
"pnr_number": flight_info[0].get("pnr_number", "") if flight_info else "",
|
|
"flight_info": flight_info,
|
|
"checkin_url": checkin_url,
|
|
}
|
|
|
|
|
|
def build_airline_itinerary_template(
|
|
intro_message: str,
|
|
locale: str,
|
|
pnr_number: str,
|
|
passenger_info: list[dict],
|
|
flight_info: list[dict],
|
|
) -> dict:
|
|
return {
|
|
"template_type": "airline_itinerary",
|
|
"intro_message": intro_message,
|
|
"locale": locale,
|
|
"pnr_number": pnr_number,
|
|
"passenger_info": passenger_info,
|
|
"flight_info": flight_info,
|
|
}
|