Add TelegramKeyboardTool to create and manage Telegram keyboards
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
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.",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"text": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The text on the button."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["text"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get_keyboard",
|
||||||
|
"description": "Get the current keyboard layout.",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
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()
|
||||||
|
else:
|
||||||
|
error_message = f"Unknown function: {function_name}"
|
||||||
|
return error_message
|
||||||
|
|
||||||
|
def _add_button(self, text):
|
||||||
|
self.keyboard.append({"text": text})
|
||||||
|
return f"Button '{text}' added."
|
||||||
|
|
||||||
|
def _get_keyboard(self):
|
||||||
|
return self.keyboard
|
||||||
Reference in New Issue
Block a user