from __future__ import annotations from dataclasses import dataclass, field @dataclass class QuickReplyItem: image_url: str | None = None action: dict = field(default_factory=dict) def create_quick_reply(items: list[dict]) -> dict: return {"items": items} def build_quick_reply_items(labels: list[str]) -> list[dict]: return [ { "type": "action", "action": {"type": "message", "label": label[:20], "text": label}, } for label in labels[:13] ] def create_quick_reply_message(text: str, items: list[str]) -> dict: return { "type": "text", "text": text, "quickReply": {"items": build_quick_reply_items(items)}, } def create_message_action(label: str, text: str) -> dict: return {"type": "message", "label": label[:20], "text": text} def create_uri_action(label: str, uri: str) -> dict: return {"type": "uri", "label": label[:20], "uri": uri} def create_postback_action(label: str, data: str, display_text: str | None = None) -> dict: action = {"type": "postback", "label": label[:20], "data": data} if display_text: action["displayText"] = display_text return action def create_datetime_picker_action( label: str, data: str, mode: str = "datetime", initial: str | None = None, max_value: str | None = None, min_value: str | None = None, ) -> dict: action = { "type": "datetimePicker", "label": label[:20], "data": data, "mode": mode, } if initial: action["initial"] = initial if max_value: action["max"] = max_value if min_value: action["min"] = min_value return action