Skip to content

Request limit#19

Merged
yenslife merged 2 commits into
mainfrom
request-limit
Jun 2, 2025
Merged

Request limit#19
yenslife merged 2 commits into
mainfrom
request-limit

Conversation

@yenslife
Copy link
Copy Markdown
Contributor

Add rate limiting to prevent excessive Dify API usage

yenslife added 2 commits June 2, 2025 19:22
This commit introduces rate limiting to the linebot to prevent abuse and ensure fair usage.

- Added a new `redis_client.py` to manage the Redis connection.
- Added a `RateLimiter` class in `rate_limiter.py` to handle rate limiting logic using Redis.
- Modified `text_handler.py` to integrate the `RateLimiter`.
  - Implemented a check to determine if a user has exceeded their request limit.
  - If the limit is exceeded, a message is sent to the user informing them of the rate limit and the time remaining until they can make another request.
- Added `flex_message.py` to convert flex message to json.
- Added `__init__.py` to export the utils.
- Added `redis` to `pyproject.toml`.
- Added `*.rdb` to `.gitignore`.
This commit introduces Redis integration for rate limiting in the Line
Bot application. It includes the following changes:

- Added Redis configuration parameters (REDIS_HOST, REDIS_PORT,
  REDIS_DB) to the .env.example file.
- Updated the README.md file to include instructions for installing
  sqlite3 and redis.
- Modified the redis_client.py file to read Redis configuration from
  environment variables, allowing for flexible deployment.

The addition of Redis enables the implementation of robust rate
limiting mechanisms, preventing abuse and ensuring the stability of
the Line Bot service.
@yenslife yenslife merged commit d7d5322 into main Jun 2, 2025
1 check passed
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.

1 participant