diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.HasMissingRequiredField.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.HasMissingRequiredField.cs index 20d75a958..2a6b676c7 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.HasMissingRequiredField.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.HasMissingRequiredField.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Conversations.Enums; using BotSharp.Abstraction.Routing.Models; using System.Drawing; @@ -49,6 +50,17 @@ public bool HasMissingRequiredField(RoleDialogModel message, out string agentId) if (!string.IsNullOrEmpty(states.GetState(field))) { var value = states.GetState(field); + + // Check if the value is correct data type + var rule = routingRules.First(x => x.Field == field); + if (rule.FieldType == "number") + { + if (!long.TryParse(value, out var longValue)) + { + states.SetState(field, "", isNeedVersion: true, source: StateSource.Application); + continue; + } + } message.FunctionArgs = AppendPropertyToArgs(message.FunctionArgs, field, value); missingFields.Remove(field); } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs index 571c6d09b..293ffc47d 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs @@ -10,6 +10,7 @@ public class RoutingRuleMongoElement public bool Required { get; set; } public string? RedirectTo { get; set; } public string Type { get; set; } + public string FieldType { get; set; } public RoutingRuleMongoElement() { @@ -25,6 +26,7 @@ public static RoutingRuleMongoElement ToMongoElement(RoutingRule routingRule) Required = routingRule.Required, RedirectTo = routingRule.RedirectTo, Type = routingRule.Type, + FieldType = routingRule.FieldType }; } @@ -39,6 +41,12 @@ public static RoutingRule ToDomainElement(string agentId, string agentName, Rout Required = rule.Required, RedirectTo = rule.RedirectTo, Type = rule.Type, + FieldType= rule.FieldType }; } + + public override string ToString() + { + return $"{Field} - {FieldType}, Required: {Required} ({Type})"; + } }