ForcePilot/backend/package/yuxi/channel/extensions/workplace/template.py
Kris 7215418610 feat(channel): 添加企业微信、微博、WhatsApp 和 Workplace 渠道扩展
新增企业微信、微博、WhatsApp、Workplace 四个渠道扩展。

企业微信渠道扩展主要模块:config, gateway, webhook, webhook_bot, outbound, streaming, pairing, security, crypto, dedupe, persistent_dedupe, card, directory, events, externalcontact, media, mentions, menu, message, oauth, status

微博渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, passive_reply, broadcast, message, menu, media, subscription, template, status

WhatsApp 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, actions, monitor, status

Workplace 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, actions, challenge, groups, media, mentions, menu, monitor, persona, quick_reply, signature, subscriptions, template, threading, users, status
2026-05-21 12:01:56 +08:00

106 lines
2.6 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_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