Business problem

Automatically route a support ticket to:

  • Billing
  • Technical
  • Retention
  • General

We will first build a traditional rule-based version. This lets us understand what ML would eventually replace.

Create a console project:

dotnet new console -n AiDay01
cd AiDay01

Replace Program.cs with:

using System;
using System.Collections.Generic;
using System.Linq;

var tickets = new[]
{
    "My payment was deducted twice.",
    "I cannot reset my password.",
    "Please cancel my subscription.",
    "I need information about your services."
};

foreach (var ticket in tickets)
{
    var result = TicketRouter.Predict(ticket);

    Console.WriteLine($"Ticket: {ticket}");
    Console.WriteLine($"Department: {result.Department}");
    Console.WriteLine($"Reason: {result.Reason}");
    Console.WriteLine();
}

public record RoutingResult(string Department, string Reason);

public static class TicketRouter
{
    private static readonly Dictionary<string, string[]> Keywords =
        new(StringComparer.OrdinalIgnoreCase)
        {
            ["Billing"] =
            [
                "payment", "invoice", "refund", "deducted", "gst"
            ],
            ["Technical"] =
            [
                "password", "login", "error", "not working", "unable"
            ],
            ["Retention"] =
            [
                "cancel", "close account", "unsubscribe", "terminate"
            ]
        };

    public static RoutingResult Predict(string ticket)
    {
        var normalizedTicket = ticket.ToLowerInvariant();

        foreach (var department in Keywords)
        {
            var matchedKeyword = department.Value.FirstOrDefault(
                keyword => normalizedTicket.Contains(keyword));

            if (matchedKeyword is not null)
            {
                return new RoutingResult(
                    department.Key,
                    $"Matched keyword: {matchedKeyword}");
            }
        }

        return new RoutingResult(
            "General",
            "No configured keyword matched.");
    }
}

Run it:

dotnet run

What this program teaches

The method is called Predict, but it is not machine learning.

Why?

  • A human wrote every keyword.
  • No historical data was used for training.
  • The program cannot discover a new pattern.
  • Its behavior changes only when a developer changes the code or configuration.

Now consider:

“My card was charged two times.”

Our program may classify it as General because we added deducted but not charged.

You could add more keywords, but natural language has countless variations:

  • charged twice
  • duplicate debit
  • paid two times
  • repeated transaction
  • amount taken again

This is where ML may become useful.