48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
TEXT_CHUNK_LIMIT = 30000
|
|
|
|
|
|
def build_dingding_text_payload(content: str) -> dict[str, Any]:
|
|
return {"content": str(content)[:TEXT_CHUNK_LIMIT]}
|
|
|
|
|
|
def build_dingding_markdown_payload(title: str, text: str) -> dict[str, Any]:
|
|
return {
|
|
"title": str(title),
|
|
"text": str(text),
|
|
}
|
|
|
|
|
|
def build_dingding_action_card(
|
|
title: str,
|
|
text: str,
|
|
*,
|
|
single_title: str | None = None,
|
|
single_url: str | None = None,
|
|
buttons: list[dict[str, str]] | None = None,
|
|
btn_orientation: str = "0",
|
|
) -> dict[str, Any]:
|
|
msg_key = "sampleActionCard1" if single_title else "sampleActionCard2"
|
|
params: dict[str, Any] = {
|
|
"title": str(title),
|
|
"text": str(text),
|
|
}
|
|
if single_title and single_url:
|
|
params["singleTitle"] = single_title
|
|
params["singleURL"] = single_url
|
|
if buttons:
|
|
params["btns"] = buttons
|
|
params["btnOrientation"] = btn_orientation
|
|
|
|
return {"msg_key": msg_key, "msg_param": params}
|
|
|
|
|
|
def build_dingding_feed_card(links: list[dict[str, str]]) -> dict[str, Any]:
|
|
return {
|
|
"msg_key": "sampleFeedCard",
|
|
"msg_param": {"links": links},
|
|
}
|