Add TelegramKeyboardTool for creating Telegram keyboard layouts
This commit is contained in:
@@ -1,47 +1,49 @@
|
|||||||
|
# tools/telegram_keyboard_tool.py
|
||||||
|
|
||||||
from .base_tool import BaseTool
|
from .base_tool import BaseTool
|
||||||
|
|
||||||
class TelegramKeyboardTool(BaseTool):
|
class TelegramKeyboardTool(BaseTool):
|
||||||
def __init__(self):
|
|
||||||
self.keyboard = []
|
|
||||||
|
|
||||||
def get_functions(self):
|
def get_functions(self):
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"name": "add_button",
|
"name": "create_keyboard",
|
||||||
"description": "Add a button to the keyboard.",
|
"description": "Create a Telegram keyboard layout.",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"text": {
|
"buttons": {
|
||||||
"type": "string",
|
"type": "array",
|
||||||
"description": "The text on the button."
|
"items": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Text on the button."
|
||||||
|
},
|
||||||
|
"description": "A row of buttons."
|
||||||
|
},
|
||||||
|
"description": "List of rows of buttons."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["text"]
|
"required": ["buttons"]
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "get_keyboard",
|
|
||||||
"description": "Get the current keyboard layout.",
|
|
||||||
"parameters": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
def execute(self, function_name, **kwargs):
|
def execute(self, function_name, **kwargs):
|
||||||
if function_name == "add_button":
|
if function_name == "create_keyboard":
|
||||||
return self._add_button(kwargs["text"])
|
return self._create_keyboard(kwargs.get("buttons"))
|
||||||
elif function_name == "get_keyboard":
|
|
||||||
return self._get_keyboard()
|
|
||||||
else:
|
else:
|
||||||
error_message = f"Unknown function: {function_name}"
|
return f"Unknown function: {function_name}"
|
||||||
return error_message
|
|
||||||
|
|
||||||
def _add_button(self, text):
|
def _create_keyboard(self, buttons):
|
||||||
self.keyboard.append({"text": text})
|
if not isinstance(buttons, list):
|
||||||
return f"Button '{text}' added."
|
return "Invalid input: 'buttons' must be a list of lists."
|
||||||
|
|
||||||
def _get_keyboard(self):
|
keyboard = {
|
||||||
return self.keyboard
|
"keyboard": buttons,
|
||||||
|
"resize_keyboard": True,
|
||||||
|
"one_time_keyboard": True
|
||||||
|
}
|
||||||
|
|
||||||
|
return keyboard
|
||||||
|
|||||||
Reference in New Issue
Block a user