2024-08-17 19:10:18 -05:00
|
|
|
# tools/telegram_keyboard_tool.py
|
|
|
|
|
|
2024-08-17 19:10:09 -05:00
|
|
|
from .base_tool import BaseTool
|
|
|
|
|
|
|
|
|
|
class TelegramKeyboardTool(BaseTool):
|
2024-08-17 19:10:18 -05:00
|
|
|
|
2024-08-17 19:10:09 -05:00
|
|
|
def get_functions(self):
|
|
|
|
|
return [
|
|
|
|
|
{
|
2024-08-17 19:10:18 -05:00
|
|
|
"name": "create_keyboard",
|
|
|
|
|
"description": "Create a Telegram keyboard layout.",
|
2024-08-17 19:10:09 -05:00
|
|
|
"parameters": {
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
2024-08-17 19:10:18 -05:00
|
|
|
"buttons": {
|
|
|
|
|
"type": "array",
|
|
|
|
|
"items": {
|
|
|
|
|
"type": "array",
|
|
|
|
|
"items": {
|
|
|
|
|
"type": "string",
|
|
|
|
|
"description": "Text on the button."
|
|
|
|
|
},
|
|
|
|
|
"description": "A row of buttons."
|
|
|
|
|
},
|
|
|
|
|
"description": "List of rows of buttons."
|
2024-08-17 19:10:09 -05:00
|
|
|
}
|
|
|
|
|
},
|
2024-08-17 19:10:18 -05:00
|
|
|
"required": ["buttons"]
|
2024-08-17 19:10:09 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
def execute(self, function_name, **kwargs):
|
2024-08-17 19:10:18 -05:00
|
|
|
if function_name == "create_keyboard":
|
|
|
|
|
return self._create_keyboard(kwargs.get("buttons"))
|
2024-08-17 19:10:09 -05:00
|
|
|
else:
|
2024-08-17 19:10:18 -05:00
|
|
|
return f"Unknown function: {function_name}"
|
|
|
|
|
|
|
|
|
|
def _create_keyboard(self, buttons):
|
|
|
|
|
if not isinstance(buttons, list):
|
|
|
|
|
return "Invalid input: 'buttons' must be a list of lists."
|
2024-08-17 19:10:09 -05:00
|
|
|
|
2024-08-17 19:10:18 -05:00
|
|
|
keyboard = {
|
|
|
|
|
"keyboard": buttons,
|
|
|
|
|
"resize_keyboard": True,
|
|
|
|
|
"one_time_keyboard": True
|
|
|
|
|
}
|
2024-08-17 19:10:09 -05:00
|
|
|
|
2024-08-17 19:10:18 -05:00
|
|
|
return keyboard
|