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
|
||||
|
||||
class TelegramKeyboardTool(BaseTool):
|
||||
def __init__(self):
|
||||
self.keyboard = []
|
||||
|
||||
|
||||
def get_functions(self):
|
||||
return [
|
||||
{
|
||||
"name": "add_button",
|
||||
"description": "Add a button to the keyboard.",
|
||||
"name": "create_keyboard",
|
||||
"description": "Create a Telegram keyboard layout.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"text": {
|
||||
"type": "string",
|
||||
"description": "The text on the button."
|
||||
"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": ["text"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "get_keyboard",
|
||||
"description": "Get the current keyboard layout.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
"required": ["buttons"]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
def execute(self, function_name, **kwargs):
|
||||
if function_name == "add_button":
|
||||
return self._add_button(kwargs["text"])
|
||||
elif function_name == "get_keyboard":
|
||||
return self._get_keyboard()
|
||||
if function_name == "create_keyboard":
|
||||
return self._create_keyboard(kwargs.get("buttons"))
|
||||
else:
|
||||
error_message = f"Unknown function: {function_name}"
|
||||
return error_message
|
||||
return f"Unknown function: {function_name}"
|
||||
|
||||
def _add_button(self, text):
|
||||
self.keyboard.append({"text": text})
|
||||
return f"Button '{text}' added."
|
||||
def _create_keyboard(self, buttons):
|
||||
if not isinstance(buttons, list):
|
||||
return "Invalid input: 'buttons' must be a list of lists."
|
||||
|
||||
def _get_keyboard(self):
|
||||
return self.keyboard
|
||||
keyboard = {
|
||||
"keyboard": buttons,
|
||||
"resize_keyboard": True,
|
||||
"one_time_keyboard": True
|
||||
}
|
||||
|
||||
return keyboard
|
||||
|
||||
Reference in New Issue
Block a user