Skip to content

check field type in routing. #390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using BotSharp.Abstraction.Conversations.Enums;
using BotSharp.Abstraction.Routing.Models;
using System.Drawing;

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -25,6 +26,7 @@ public static RoutingRuleMongoElement ToMongoElement(RoutingRule routingRule)
Required = routingRule.Required,
RedirectTo = routingRule.RedirectTo,
Type = routingRule.Type,
FieldType = routingRule.FieldType
};
}

Expand All @@ -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})";
}
}