python-zatolox-bot 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-zatolox-bot
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: SDK ufficiale per costruire bot su Zatolox
5
5
  Home-page: https://github.com/zatolox/python-zatolox-bot
6
6
  Author: Zatolox
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-zatolox-bot
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: SDK ufficiale per costruire bot su Zatolox
5
5
  Home-page: https://github.com/zatolox/python-zatolox-bot
6
6
  Author: Zatolox
@@ -5,7 +5,7 @@ from setuptools import setup, find_packages
5
5
  # sono, meno se ne rompono.
6
6
  setup(
7
7
  name="python-zatolox-bot",
8
- version="0.1.0",
8
+ version="0.1.1",
9
9
  description="SDK ufficiale per costruire bot su Zatolox",
10
10
  long_description=(
11
11
  "Wrapper leggero attorno al gateway HTTP dei bot di Zatolox. "
@@ -3,5 +3,5 @@
3
3
  from .bot import ZatoloxBot, ZatoloxApiError
4
4
  from .types import User, Message, CallbackQuery, Update
5
5
 
6
- __version__ = "0.1.0"
6
+ __version__ = "0.1.1"
7
7
  __all__ = ["ZatoloxBot", "ZatoloxApiError", "User", "Message", "CallbackQuery", "Update"]
@@ -91,6 +91,26 @@ class ZatoloxBot:
91
91
  result = self._call("getUpdates", params, http="get") or []
92
92
  return [Update.from_dict(u) for u in result]
93
93
 
94
+ def set_my_commands(self, commands: List[Any]) -> List[dict]:
95
+ """
96
+ Registra i comandi del bot sul server (come setMyCommands di Telegram).
97
+
98
+ Il client Zatolox li mostra nel menu "/" della barra input: senza almeno un comando quel
99
+ menu non compare proprio. Da chiamare una volta all'avvio.
100
+
101
+ `commands` accetta forme diverse, per comodita':
102
+ - dict: {"command": "start", "description": "avvia il bot"}
103
+ - tupla: ("start", "avvia il bot")
104
+ Lo slash iniziale e' facoltativo: lo normalizza il server. Un array vuoto azzera i comandi.
105
+ """
106
+ norm: List[dict] = []
107
+ for c in commands:
108
+ if isinstance(c, dict):
109
+ norm.append({"command": str(c.get("command", "")), "description": str(c.get("description", ""))})
110
+ elif isinstance(c, (tuple, list)) and len(c) >= 2:
111
+ norm.append({"command": str(c[0]), "description": str(c[1])})
112
+ return self._call("setMyCommands", {"commands": norm})
113
+
94
114
  # ------------------------------------------------------------------ handler
95
115
 
96
116
  def add_command_handler(self, command: str, callback: Callable[[Message], None]) -> None:
@@ -113,6 +133,25 @@ class ZatoloxBot:
113
133
  return fn
114
134
  return deco
115
135
 
136
+ def message_handler(self, fn: Optional[Callable[[Message], None]] = None):
137
+ """
138
+ Decoratore per il fallback sul testo LIBERO (i messaggi che non sono comandi) — la base per
139
+ un bot conversazionale (es. inoltrare il testo a un'IA). Equivale ad add_message_handler.
140
+
141
+ Funziona sia nudo sia con le parentesi::
142
+
143
+ @bot.message_handler
144
+ def on_text(msg): ...
145
+
146
+ @bot.message_handler()
147
+ def on_text(msg): ...
148
+ """
149
+ def register(f: Callable[[Message], None]) -> Callable[[Message], None]:
150
+ self.add_message_handler(f)
151
+ return f
152
+ # Uso nudo (@bot.message_handler): Python passa gia' la funzione qui.
153
+ return register(fn) if fn is not None else register
154
+
116
155
  # ------------------------------------------------------------------ instradamento
117
156
 
118
157
  def _dispatch(self, update: Update) -> None: