Skip to content

fix: deduplicate incoming messages to prevent multiple auto-replies#85

Open
octo-patch wants to merge 1 commit into
shaxiu:mainfrom
octo-patch:fix/issue-75-duplicate-message-dedup
Open

fix: deduplicate incoming messages to prevent multiple auto-replies#85
octo-patch wants to merge 1 commit into
shaxiu:mainfrom
octo-patch:fix/issue-75-duplicate-message-dedup

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #75

Problem

The same seller message was being read multiple times (with different timestamps in some cases), causing the bot to generate and send multiple replies for a single incoming message. This resulted in buyers receiving duplicate or repeated responses.

Solution

Add message deduplication using the messageId extracted from the reminderUrl field in each message:

  • In __init__, added self.processed_message_ids (a set) and self.max_processed_ids (configurable via MAX_PROCESSED_IDS env var, default 1000) to track recently-processed message IDs.
  • In handle_message, after extracting url_info, extract messageId from the URL and check it against self.processed_message_ids before processing.
  • If the message ID has already been seen, log a debug message and return early — skipping AI generation and reply.
  • To prevent unbounded memory growth, the set is cleared when it reaches max_processed_ids entries.

Testing

  • Verified that the messageId parameter is present in reminderUrl for standard chat messages.
  • The fix is minimal and does not affect messages lacking a messageId (they are still processed normally).
  • No new dependencies introduced.

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.

会出现同一条卖家消息被重复读取的bug

1 participant