Merge pull request #390 from hchen2020/master

check  field type in routing.
This commit is contained in:
C. Oceania 2024-04-03 09:48:41 -05:00 committed by GitHub
commit c10b8d4885
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View file

@ -1,3 +1,4 @@
using BotSharp.Abstraction.Conversations.Enums;
using BotSharp.Abstraction.Routing.Models;
using System.Drawing;
@ -49,6 +50,17 @@ public partial class RoutingService
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);
}

View file

@ -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 class RoutingRuleMongoElement
Required = routingRule.Required,
RedirectTo = routingRule.RedirectTo,
Type = routingRule.Type,
FieldType = routingRule.FieldType
};
}
@ -39,6 +41,12 @@ public class RoutingRuleMongoElement
Required = rule.Required,
RedirectTo = rule.RedirectTo,
Type = rule.Type,
FieldType= rule.FieldType
};
}
public override string ToString()
{
return $"{Field} - {FieldType}, Required: {Required} ({Type})";
}
}