Update voice bot functionality and clean up project structure
- Added voice message handling capabilities, including saving and deleting audio messages via callback queries. - Refactored audio record management in the database to remove unnecessary fields and streamline operations. - Introduced new keyboard options for voice interactions in the bot. - Updated `.gitignore` to include voice user files for better project organization. - Removed obsolete voice bot handler files to simplify the codebase.
This commit is contained in:
@@ -16,12 +16,20 @@ try:
|
||||
from ..handlers.private.constants import BUTTON_COMMAND_MAPPING
|
||||
from ..handlers.callback.constants import CALLBACK_COMMAND_MAPPING
|
||||
from ..handlers.admin.constants import ADMIN_BUTTON_COMMAND_MAPPING, ADMIN_COMMANDS
|
||||
from ..handlers.voice.constants import (
|
||||
BUTTON_COMMAND_MAPPING as VOICE_BUTTON_COMMAND_MAPPING,
|
||||
COMMAND_MAPPING as VOICE_COMMAND_MAPPING,
|
||||
CALLBACK_COMMAND_MAPPING as VOICE_CALLBACK_COMMAND_MAPPING
|
||||
)
|
||||
except ImportError:
|
||||
# Fallback if constants not available
|
||||
BUTTON_COMMAND_MAPPING = {}
|
||||
CALLBACK_COMMAND_MAPPING = {}
|
||||
ADMIN_BUTTON_COMMAND_MAPPING = {}
|
||||
ADMIN_COMMANDS = {}
|
||||
VOICE_BUTTON_COMMAND_MAPPING = {}
|
||||
VOICE_COMMAND_MAPPING = {}
|
||||
VOICE_CALLBACK_COMMAND_MAPPING = {}
|
||||
|
||||
|
||||
class MetricsMiddleware(BaseMiddleware):
|
||||
@@ -183,6 +191,13 @@ class MetricsMiddleware(BaseMiddleware):
|
||||
'user_type': "admin" if message.from_user else "unknown",
|
||||
'handler_type': "admin_handler"
|
||||
}
|
||||
# Check if it's a voice bot command
|
||||
elif command_name in VOICE_COMMAND_MAPPING:
|
||||
return {
|
||||
'command': VOICE_COMMAND_MAPPING[command_name],
|
||||
'user_type': "user" if message.from_user else "unknown",
|
||||
'handler_type': "voice_command_handler"
|
||||
}
|
||||
else:
|
||||
return {
|
||||
'command': command_name,
|
||||
@@ -206,6 +221,14 @@ class MetricsMiddleware(BaseMiddleware):
|
||||
'handler_type': "button_handler"
|
||||
}
|
||||
|
||||
# Check if it's a voice bot button click
|
||||
if message.text in VOICE_BUTTON_COMMAND_MAPPING:
|
||||
return {
|
||||
'command': VOICE_BUTTON_COMMAND_MAPPING[message.text],
|
||||
'user_type': "user" if message.from_user else "unknown",
|
||||
'handler_type': "voice_button_handler"
|
||||
}
|
||||
|
||||
return None
|
||||
|
||||
def _extract_callback_command_info(self, callback: CallbackQuery) -> Optional[Dict[str, str]]:
|
||||
@@ -222,6 +245,14 @@ class MetricsMiddleware(BaseMiddleware):
|
||||
'handler_type': "callback_handler"
|
||||
}
|
||||
|
||||
# Check if it's a voice bot callback
|
||||
if parts and parts[0] in VOICE_CALLBACK_COMMAND_MAPPING:
|
||||
return {
|
||||
'command': VOICE_CALLBACK_COMMAND_MAPPING[parts[0]],
|
||||
'user_type': "user" if callback.from_user else "unknown",
|
||||
'handler_type': "voice_callback_handler"
|
||||
}
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user