Skip to content

feat: complete SMS unsubscribe lifecycle with inbound detection and template-based auto-reply - #673

Merged
MayueCif merged 16 commits into
mainfrom
feature/sms-unsubscribe
Jun 30, 2026
Merged

feat: complete SMS unsubscribe lifecycle with inbound detection and template-based auto-reply#673
MayueCif merged 16 commits into
mainfrom
feature/sms-unsubscribe

Conversation

@wzh425

@wzh425 wzh425 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Background

This PR completes the SMS unsubscribe lifecycle, covering blacklist management, inbound unsubscribe detection, template-driven auto-reply, query filtering, and configuration consistency improvements.

Changes

  • Add/Improve unsubscribe blacklist management

    • Introduce DTOs/commands/services for adding and removing channel user identities from blacklist
    • Improve identity resolution and timeline detail recording
  • Enhance SMS inbound processing

    • Add optional Provider filter in inbound query
    • Introduce inbound type classification (including Unsubscribe)
    • Improve unsubscribe keyword handling in message receipt flow
  • Refactor auto-reply flow (SmsInboundAutoReplyService)

    • Move to template-driven auto-reply logic
    • Support fallback between message template and SMS template
    • Add pre-send validation, send-limit checks, and non-production safeguards
  • Unify template config and validation

    • Extend SMS template types (including Unsubscribe/Resubscribe)
    • Rename unsubscribe config fields to *TemplateId
    • Upgrade template ID type to Guid
    • Remove obsolete cooldown validation for simpler config semantics
  • Query and localization updates

    • Add SMS interaction history retrieval by mobile + channel
    • Add/update i18n messages in English and Chinese
  • Engineering cleanup

    • Remove unused import-related files
    • Update local launch settings for development environment

Impact

  • Affects unsubscribe management, inbound SMS processing, auto-reply behavior, template validation, and local environment configuration.
  • Includes schema/config model related updates; migration and environment validation are recommended.

Test Plan

  • Verify unsubscribe keyword (e.g. STOP) flow:
    • blacklist insertion
    • inbound type marked as unsubscribe
    • auto-reply template selection
  • Verify resubscribe keyword (e.g. START) reverse flow and timeline details
  • Verify behavior differences in production vs non-production environments
  • Verify inbound list filtering by Provider
  • Regression test template ID (Guid) read/write and validation chain

wzh425 added 16 commits June 24, 2026 14:45
- Added new DTOs for unsubscription management, including AddChannelUserIdentityToUnsubscriptionBlacklistInputDto and ChannelUserIdentityUnsubscriptionItemDto.
- Implemented commands for adding and removing channel user identities from the unsubscription blacklist.
- Introduced a new service for handling unsubscription logic, including methods for adding and removing identities from the blacklist.
- Enhanced SMS record handling with a new query to retrieve SMS records by mobile number and channel code.
- Updated existing services and handlers to integrate new unsubscription features and SMS record queries.
- Added localization support for unsubscription reasons in English and Chinese.
- Improved error handling and validation in unsubscription processes.
- Added a new optional property `Provider` to `GetSmsInboundInputDto` for filtering SMS records by provider.
- Updated `MessageReceiptQueryHandler` to include provider filtering in query conditions.
- Modified `SmsInboundService` to accept the provider parameter when retrieving SMS records.
- Removed unused `_Imports.cs`, `_Imports.razor`, and other related files to clean up the project structure.
- Added a new optional property `Provider` to `GetSmsInboundInputDto` for filtering SMS records by provider.
- Updated `MessageReceiptQueryHandler` to include provider filtering in query conditions.
- Modified `SmsInboundService` to accept the provider parameter when retrieving SMS records.
- Removed unused `_Imports.cs`, `_Imports.razor`, and other related files to clean up the project structure.
- Introduced `SmsInboundTypes` enum to categorize inbound SMS types, including `Unsubscribe`.
- Updated `SmsInboundDto` to include a new property `InboundType` for tracking unsubscription status.
- Enhanced `MessageReceiptCommandHandler` to process channel-level unsubscriptions based on reserved keywords.
- Implemented logic to check for unsubscriptions in `MessageReceiptQueryHandler` and mark relevant SMS records accordingly.
- Refactored message event handlers to improve handling of unsubscription scenarios and ensure robust message processing.
- Added helper methods for generating unsubscription-related messages and improved error handling in SMS sending logic.
- Added `UserId` property to `AddChannelUserIdentityToUnsubscriptionBlacklistInputDto` for improved user identification during unsubscription processes.
- Updated `MessageTemplate` to handle unsubscribe configuration more robustly, ensuring proper application of settings.
- Introduced `Apply` method in `MessageTemplateUnsubscribeConfig` to streamline configuration updates.
- Enhanced `UnsubscriptionCommandHandler` to resolve target user identities based on channel type and input parameters, improving the accuracy of unsubscription actions.
- Refactored `UnsubscriptionDomainService` to utilize user ID in blacklist operations, ensuring correct user associations during unsubscription.
- Removed unnecessary properties from UnsubscriptionTimelineDto and related classes to simplify the data model.
- Updated Unsubscription and UnsubscriptionTimeline classes to accept a timeline detail parameter, improving the clarity of unsubscription actions.
- Enhanced the UnsubscriptionDomainService to build detailed timeline messages for inbound and outbound actions, ensuring better tracking of user interactions.
- Adjusted database context and migrations to reflect the removal of obsolete fields, maintaining a clean schema.
…validation

- Removed the CooldownSeconds validation from MessageTemplateUpsertDtoValidator and related classes to streamline unsubscription handling.
- Updated MessageTemplateUnsubscribeConfig to eliminate unnecessary cooldown checks, improving clarity in unsubscription processes.
- Enhanced database context and migrations to reflect changes in unsubscription configuration, ensuring a clean schema.
- Introduced a new method in MessageRecordService to retrieve SMS interaction history, improving user engagement tracking.
- Added validation for TemplateType in MessageTemplateUpsertDtoValidator to ensure it is defined when ChannelType is SMS, improving data integrity.
- Updated SmsTemplateTypes enum to include new values for Unsubscribe and Resubscribe, expanding the template type options available for SMS messages.
- Renamed properties in MessageTemplateUnsubscribeConfigDto and related classes to use TemplateId suffix for unsubscribe and resubscribe auto-reply configurations, enhancing clarity.
- Updated validation rules in MessageTemplateUpsertDtoValidator to reflect changes in property names and lengths.
- Modified database context and query models to align with the new property names, ensuring consistency across the application.
- Enhanced message receipt handling to utilize the new template ID logic for auto-replies, improving the overall unsubscribe process.
…e integration

- Introduced IMessageTemplateRepository and MessageTemplateDomainService to manage message templates more effectively.
- Updated SmsInboundAutoReplyService to utilize message templates for auto-reply content, improving flexibility in message handling.
- Refactored TrySendAutoReplyInternalAsync to incorporate message template checks and limits, enhancing message sending logic.
- Created a new method, CreateMessageRecord, to streamline message record creation, improving code clarity and maintainability.
… handling

- Updated SmsInboundAutoReplyService to better utilize message templates for auto-reply content, allowing for fallback to SMS templates when message content is not available.
- Refactored the logic for determining the appropriate template to streamline the retrieval process and improve code clarity.
- Ensured that the service can handle both message and SMS templates effectively, enhancing the flexibility of auto-reply responses.
…y template IDs

- Changed the data type of UnsubscribeAutoReplyTemplateId and ResubscribeAutoReplyTemplateId in MessageTemplateUnsubscribeConfigDto and related classes from string to Guid for better type safety.
- Updated validation rules in MessageTemplateUpsertDtoValidator to ensure GUIDs are not empty for auto-reply template IDs.
- Modified MessageTemplateUnsubscribeConfig and related classes to reflect the new GUID type, enhancing clarity and consistency.
- Adjusted database context and migrations to accommodate the changes in property types, ensuring a clean schema.
- Updated the MessageReceiptCommandHandler to include a condition that filters message receipts based on the success status, improving the accuracy of message retrieval for templates.
…ks and template handling

- Updated SmsInboundAutoReplyService to include checks for production environment before sending auto-replies, improving safety in non-production scenarios.
- Refactored message handling logic to streamline the retrieval and validation of message templates, ensuring better adherence to sending limits.
- Introduced helper methods for payload validation and handling send limits, enhancing code clarity and maintainability.
- Added new localization strings for non-production environment notifications in both English and Chinese.
- Changed ASPNETCORE_ENVIRONMENT from Staging to Development for local testing.
- Updated various environment variables including MASA_VERSION, IS_DEMO, and CONNECTIONSTRING to reflect development configurations.
- Adjusted MASA_STACK entries to point to development service domains and web URLs, ensuring proper routing during development.
…andler

- Removed unnecessary using directives related to com.igetui.api.openservice, Masa.Mc.Domain.MessageTemplates.Aggregates, and Masa.Mc.Service.Admin.Domain.MessageTemplates.Services, improving code clarity and maintainability.
@MayueCif
MayueCif merged commit afb3612 into main Jun 30, 2026
2 of 3 checks passed
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
11.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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.

2 participants