Merge pull request #12 from bucolucas/telegram-keyboard-creator-tool-7
Add Telegram Keyboard Creator Tool
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
# tools/telegram_keyboard_tool.py
|
||||
|
||||
from .base_tool import BaseTool
|
||||
|
||||
class TelegramKeyboardTool(BaseTool):
|
||||
|
||||
def get_functions(self):
|
||||
return [
|
||||
{
|
||||
"name": "create_keyboard",
|
||||
"description": "Create a Telegram keyboard layout.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"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."
|
||||
}
|
||||
},
|
||||
"required": ["buttons"]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
def execute(self, function_name, **kwargs):
|
||||
if function_name == "create_keyboard":
|
||||
return self._create_keyboard(kwargs.get("buttons"))
|
||||
else:
|
||||
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."
|
||||
|
||||
keyboard = {
|
||||
"keyboard": buttons,
|
||||
"resize_keyboard": True,
|
||||
"one_time_keyboard": True
|
||||
}
|
||||
|
||||
return keyboard
|
||||
Reference in New Issue
Block a user