From 8056ed4486b619d1dfcd86629deeb7273386cfd5 Mon Sep 17 00:00:00 2001 From: "aden.chen" Date: Thu, 3 Sep 2026 16:36:13 +0800 Subject: [PATCH] GTR-13432 Handle multiple Twilio error codes in call handling Replaced single error code constant with a HashSet to handle multiple Twilio error codes (21215, 21216). Updated the `catch` block to check for error codes in the set. Added `message.StopCompletion` to stop further execution on error. Improved comments for clarity. --- .../Functions/OutboundPhoneCallFn.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/OutboundPhoneCallFn.cs b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/OutboundPhoneCallFn.cs index 5b833fdad..75bde287e 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/OutboundPhoneCallFn.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/OutboundPhoneCallFn.cs @@ -19,8 +19,9 @@ namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Functions; public class OutboundPhoneCallFn : IFunctionCallback { - // https://www.twilio.com/docs/api/errors/21215 - private const int TwilioGeoPermissionNotAllowedErrorCode = 21215; + // https://www.twilio.com/docs/api/errors/21215 - Geo Permission configuration is not permitting call + // https://www.twilio.com/docs/api/errors/21216 - API: Call blocked by Twilio + private static readonly HashSet NotAllowedToCallErrorCodes = [21215, 21216]; private readonly IServiceProvider _services; private readonly ILogger _logger; @@ -125,10 +126,11 @@ public async Task Execute(RoleDialogModel message) record: _twilioSetting.RecordingEnabled, recordingStatusCallback: $"{_twilioSetting.CallbackHost}/twilio/record/status?agent-id={message.CurrentAgentId}&conversation-id={newConversationId}"); } - catch (ApiException ex) when (ex.Code == TwilioGeoPermissionNotAllowedErrorCode) + catch (ApiException ex) when (NotAllowedToCallErrorCodes.Contains(ex.Code)) { _logger.LogWarning(ex, "Not allowed to call {PhoneNumber}", args.PhoneNumber); message.Content = $"Not allowed to call {args.PhoneNumber}."; + message.StopCompletion = true; return false; }