Skip to content

Mole9000/speech input#11

Closed
yenslife wants to merge 15 commits into
mainfrom
mole9000/speech_input
Closed

Mole9000/speech input#11
yenslife wants to merge 15 commits into
mainfrom
mole9000/speech_input

Conversation

@yenslife
Copy link
Copy Markdown
Contributor

No description provided.

yenslife and others added 15 commits May 22, 2025 17:19
This commit introduces a significant refactoring of the message
handling logic in the Line Bot application. The core changes involve:

- Creation of handler modules: New modules for handling text, image,
  and audio messages have been created under the `linebot/app/services/
  handlers/` directory. These modules encapsulate the specific logic
  for processing each type of message.
- Common utilities module: A `common.py` module has been added to
  provide shared functions and constants used across different handler
  modules, such as creating quick reply buttons and sending messages.
- Message service update: The `MessageService` class has been updated
  to delegate message handling to the appropriate handler module. This
  simplifies the `MessageService` class and makes it more maintainable.
- Webhook handler update: The webhook handlers in `webhooks/handlers.py`
  have been updated to use the `MessageService` to handle messages.
- API Compatibility: The `MessageService` class is kept as a wrapper
  to maintain compatibility with the old API.

These changes improve the modularity, readability, and maintainability
of the codebase. By separating the message handling logic into
dedicated modules, it becomes easier to add new message types and
modify existing ones. The use of a common utilities module promotes
code reuse and reduces redundancy.
This commit introduces a centralized logging system. A new module
`linebot/app/config/logger.py` is created to configure and provide
logger instances. The logging configuration includes:

-   Log formatting with timestamp, logger name, level, and message.
-   Console output with configurable log level.
-   File output with rotating file handler (max 10MB, 5 backups).
-   A global `app_logger` instance for general application logging.

The existing `print` statements in `linebot/app/api/vision.py` and
`linebot/app/routers/linebot.py` are replaced with calls to the new
logging system. This allows for better control and management of
application logs.

Additionally, the `.gitignore` file is updated to ignore the `logs/`
directory, preventing log files from being committed to the repository.
This commit introduces the ability to handle postback events,
specifically for terms and conditions acceptance/rejection.

- Added `PostbackService` to manage postback event logic.
- Created `handle_postback_event` in `services/handlers/postback.py`
  to process different postback data values.
- Registered `PostbackEvent` handler in `linebot.py` to route
  events to the `PostbackService`.
- Added `show_loading_animation` before handling the postback event.
- Added `send_message` to send the reply messages to the user.
- Created a new file `linebot/flex_messages/welcome/terms.json`
  (empty file, to be populated later with the flex message for
  terms and conditions).

This allows the bot to respond to user interactions with buttons
related to accepting or rejecting terms and conditions.
This commit introduces a welcome flow for new users, including:
- Terms of service agreement with accept/reject options.
- Language selection (Traditional Chinese/English).
- Role selection (Faculty/Student/Visitor).
- Welcome messages tailored to the selected role.
- Quick reply buttons for help and settings.

The implementation involves:
- Adding new flex messages for terms, language, and role selection.
- Updating the postback handler to process the new postback data.
- Adding a utility function to convert flex message JSON files to Python objects.
- Adding a constant for default message after setting up.
- Adding a quickreply function to create quickreply buttons.
- Adding error handling for sending messages to LINE.
- Adding logging for messages sent to LINE.

These changes enhance the user experience by providing a guided onboarding process and personalized welcome messages.
@yenslife yenslife force-pushed the mole9000/speech_input branch from 7adb7dc to 9876f3c Compare May 22, 2025 09:20
@yenslife yenslife closed this May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants