Skip to content

Commit c10b8d4

Browse files
authored
Merge pull request #390 from hchen2020/master
check field type in routing.
2 parents 3b248c3 + 551c2f8 commit c10b8d4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Infrastructure/BotSharp.Core/Routing/RoutingService.HasMissingRequiredField.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using BotSharp.Abstraction.Conversations.Enums;
12
using BotSharp.Abstraction.Routing.Models;
23
using System.Drawing;
34

@@ -49,6 +50,17 @@ public bool HasMissingRequiredField(RoleDialogModel message, out string agentId)
4950
if (!string.IsNullOrEmpty(states.GetState(field)))
5051
{
5152
var value = states.GetState(field);
53+
54+
// Check if the value is correct data type
55+
var rule = routingRules.First(x => x.Field == field);
56+
if (rule.FieldType == "number")
57+
{
58+
if (!long.TryParse(value, out var longValue))
59+
{
60+
states.SetState(field, "", isNeedVersion: true, source: StateSource.Application);
61+
continue;
62+
}
63+
}
5264
message.FunctionArgs = AppendPropertyToArgs(message.FunctionArgs, field, value);
5365
missingFields.Remove(field);
5466
}

src/Plugins/BotSharp.Plugin.MongoStorage/Models/RoutingRuleMongoElement.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class RoutingRuleMongoElement
1010
public bool Required { get; set; }
1111
public string? RedirectTo { get; set; }
1212
public string Type { get; set; }
13+
public string FieldType { get; set; }
1314

1415
public RoutingRuleMongoElement()
1516
{
@@ -25,6 +26,7 @@ public static RoutingRuleMongoElement ToMongoElement(RoutingRule routingRule)
2526
Required = routingRule.Required,
2627
RedirectTo = routingRule.RedirectTo,
2728
Type = routingRule.Type,
29+
FieldType = routingRule.FieldType
2830
};
2931
}
3032

@@ -39,6 +41,12 @@ public static RoutingRule ToDomainElement(string agentId, string agentName, Rout
3941
Required = rule.Required,
4042
RedirectTo = rule.RedirectTo,
4143
Type = rule.Type,
44+
FieldType= rule.FieldType
4245
};
4346
}
47+
48+
public override string ToString()
49+
{
50+
return $"{Field} - {FieldType}, Required: {Required} ({Type})";
51+
}
4452
}

0 commit comments

Comments
 (0)