Merge pull request #390 from hchen2020/master
check field type in routing.
This commit is contained in:
commit
c10b8d4885
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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})";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue