Skip to content

Conversation

@iceljc
Copy link
Collaborator

@iceljc iceljc commented Jul 14, 2025

PR Type

Enhancement


Description

  • Add Global property to MessageState class

  • Update state handling to support global/versioned states

  • Refactor Twilio plugin to use global states

  • Clean up unused imports and variable naming


Changes diagram

flowchart LR
  A["MessageState"] --> B["Add Global property"]
  B --> C["Update constructor"]
  C --> D["ConversationService"]
  D --> E["Use Global for versioning"]
  E --> F["Twilio Plugin"]
  F --> G["Mark phone states as global"]
Loading

Changes walkthrough 📝

Relevant files
Enhancement
MessageState.cs
Add Global property to MessageState                                           

src/Infrastructure/BotSharp.Abstraction/Models/MessageState.cs

  • Add Global boolean property with JSON serialization
  • Update constructor to accept global parameter
  • Modify ToString() method to include Global value
  • +6/-2     
    ConversationService.cs
    Use Global property for versioning control                             

    src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs

  • Update state setting to use !x.Global for isNeedVersion parameter
  • +1/-1     
    TwilioInboundController.cs
    Set phone states as global                                                             

    src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioInboundController.cs

    • Mark phone-related states as global in MessageState constructors
    +6/-6     
    OutboundPhoneCallFn.cs
    Refactor state handling with global support                           

    src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/OutboundPhoneCallFn.cs

  • Add unused import for Twilio messaging
  • Fix typo: excludStates to excludeStates
  • Refactor state mapping into separate MapStates method
  • Use Global property to control state versioning
  • +25/-14 
    Miscellaneous
    RateLimitConversationHook.cs
    Remove unused statistics imports                                                 

    src/Infrastructure/BotSharp.Logger/Hooks/RateLimitConversationHook.cs

    • Remove unused imports for statistics services
    +0/-3     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @qodo-merge-pro
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Unused Import

    The import using Twilio.TwiML.Messaging; is added but appears to be unused in the code. This could indicate incomplete implementation or should be removed to keep the code clean.

    using Twilio.TwiML.Messaging;
    using Twilio.Types;
    Logic Inversion

    The isNeedVersion parameter is set to !x.Global, which means global states will not be versioned. This logic should be validated to ensure it aligns with the intended behavior for global vs versioned states.

        states.ForEach(x => _state.SetState(x.Key, x.Value, activeRounds: x.ActiveRounds, isNeedVersion: !x.Global, source: StateSource.External));
    }
    Variable Naming

    The variable curConvStates is renamed from curStates but the naming could be more descriptive. Consider using currentConversationStates for better readability and consistency with the codebase.

    var curConvStates = state.GetStates().Select(x => new MessageState(x.Key, x.Value)).ToList();
    var subConvStates = new List<MessageState>

    @qodo-merge-pro
    Copy link

    qodo-merge-pro bot commented Jul 14, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Improve null parameter handling

    The method should handle null states parameter more explicitly. Consider using a
    null check instead of relying on IsNullOrEmpty() extension method behavior.

    src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/OutboundPhoneCallFn.cs [209-229]

     private IEnumerable<StateKeyValue> MapStates(IEnumerable<MessageState> states, string messageId, DateTime updateTime)
     {
    -    if (states.IsNullOrEmpty()) return [];
    +    if (states == null || !states.Any()) return [];
     
         return states.Select(x => new StateKeyValue
         {
             Key = x.Key,
             Versioning = !x.Global,
             Values = [
                 new StateValue
                 {
                     Data = x.Value.ConvertToString(_options.JsonSerializerOptions),
    -                ...
    +                MessageId = messageId,
    +                Active = true,
    +                ActiveRounds = x.ActiveRounds,
    +                Source = StateSource.Application,
    +                UpdateTime = updateTime
                 }
             ]
         }).ToList();
     }

    [To ensure code accuracy, apply this suggestion manually]

    Suggestion importance[1-10]: 3

    __

    Why: The suggestion to replace IsNullOrEmpty() with an explicit states == null || !states.Any() check is a minor stylistic improvement for readability, as IsNullOrEmpty() likely performs the same check.

    Low
    • Update

    @iceljc iceljc merged commit cb7159e into SciSharp:master Jul 14, 2025
    0 of 4 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant