feat: complete SMS unsubscribe lifecycle with inbound detection and template-based auto-reply - #673
Merged
Conversation
- 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
approved these changes
Jun 30, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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
Enhance SMS inbound processing
Providerfilter in inbound queryUnsubscribe)Refactor auto-reply flow (
SmsInboundAutoReplyService)Unify template config and validation
*TemplateIdGuidQuery and localization updates
Engineering cleanup
Impact
Test Plan
ProviderGuid) read/write and validation chain