Skip to content

Customer Service Bot

A scripted customer service bot for a telecom company using strict mode in Spanish.

Features

  • 🇪🇸 Spanish language
  • 📋 Strict mode (follows script exactly)
  • 🔀 Multi-branch flow (billing, support, plans)
  • ✅ Satisfaction check at the end

Complete Code

typescript
import {
  agent,
  flow,
  FlowEngine,
  MemoryStorage,
  OllamaAdapter,
  name,
  yesNo,
  oneOf,
} from "@andresaya/flowkit";
import * as readline from "readline";

// Agent with strict mode - follows script exactly
const claroAgent = agent("Claro Assistant")
  .company("Claro Colombia")
  .strict()
  .language("Spanish")
  .personality("profesional, amable y eficiente")
  .context(`
    Eres el asistente virtual oficial de Claro Colombia.
    Tu objetivo es ayudar a los clientes con sus consultas.
    Siempre mantén un tono profesional pero cercano.
  `)
  .build();

// Flow with branching based on user needs
const claroFlow = flow("claro-support", claroAgent)
  // Welcome
  .ask(
    "bienvenida",
    "¡Hola! Bienvenido a Claro Colombia. ¿Me puedes dar tu nombre?",
    name(),
    "nombre_cliente"
  )
  .then("menu_principal")

  // Main menu
  .ask(
    "menu_principal",
    "Gracias {{nombre_cliente}}. ¿En qué puedo ayudarte? (facturacion, soporte, planes)",
    oneOf(["facturacion", "soporte", "planes"]),
    "tipo_consulta"
  )
  .when({
    facturacion: "facturacion_flow",
    soporte: "soporte_flow",
    planes: "planes_flow",
  })

  // Billing branch
  .ask(
    "facturacion_flow",
    "¿Deseas consultar tu saldo o reportar un problema?",
    oneOf(["saldo", "problema"]),
    "tipo_facturacion"
  )
  .when({
    saldo: "consulta_saldo",
    problema: "problema_factura",
  })

  .say(
    "consulta_saldo",
    "Para consultar tu saldo, marca *611 o ingresa a MiClaro.com.co"
  )
  .then("satisfaccion")

  .say(
    "problema_factura",
    "Para reportar problemas, visita una tienda Claro o llama al *611."
  )
  .then("satisfaccion")

  // Support branch
  .ask(
    "soporte_flow",
    "¿El problema es con internet, móvil o televisión?",
    oneOf(["internet", "movil", "television"]),
    "tipo_soporte"
  )
  .when({
    internet: "soporte_internet",
    movil: "soporte_movil",
    television: "soporte_tv",
  })

  .say("soporte_internet", "Reinicia tu router. Si persiste, llama al *611.")
  .then("satisfaccion")

  .say("soporte_movil", "Verifica tu señal y reinicia tu dispositivo.")
  .then("satisfaccion")

  .say("soporte_tv", "Reinicia tu decodificador. Si persiste, marca *611.")
  .then("satisfaccion")

  // Plans branch
  .say(
    "planes_flow",
    "¡Tenemos planes increíbles! Visita claro.com.co o llama al *611."
  )
  .then("satisfaccion")

  // Satisfaction check
  .ask(
    "satisfaccion",
    "¿Te fue útil esta información, {{nombre_cliente}}?",
    yesNo(),
    "satisfecho"
  )
  .when({
    yes: "despedida_feliz",
    no: "despedida_escalado",
  })

  .say(
    "despedida_feliz",
    "¡Me alegra ayudarte! Gracias por contactar a Claro. ¡Excelente día! 🎉"
  )
  .done()

  .say(
    "despedida_escalado",
    "Un asesor se comunicará contigo pronto. ¡Gracias!"
  )
  .done()

  .build();

// Run the bot
async function main() {
  const adapter = new OllamaAdapter({
    model: "qwen3:4b",
    baseUrl: "http://localhost:11434",
  });

  const storage = new MemoryStorage();
  const engine = new FlowEngine(claroFlow, { llm: adapter, storage });

  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
  });

  const sessionId = `session-${Date.now()}`;

  // Start conversation
  const startResult = await engine.start(sessionId);
  console.log(`\n🤖 Bot: ${startResult.message}\n`);

  // Chat loop
  const chat = () => {
    rl.question("👤 Tú: ", async (input) => {
      if (input.toLowerCase() === "exit") {
        rl.close();
        return;
      }

      const result = await engine.handle(sessionId, input);
      console.log(`\n🤖 Bot: ${result.message}\n`);

      if (result.done) {
        console.log("📊 Datos recolectados:", result.state.slots);
        rl.close();
        return;
      }

      chat();
    });
  };

  chat();
}

main().catch(console.error);

Sample Conversation

🤖 Bot: ¡Hola! Bienvenido a Claro Colombia. ¿Me puedes dar tu nombre?

👤 Tú: Me llamo Carlos

🤖 Bot: Gracias Carlos. ¿En qué puedo ayudarte? (facturacion, soporte, planes)

👤 Tú: tengo problemas con mi internet

🤖 Bot: ¿El problema es con internet, móvil o televisión?

👤 Tú: internet

🤖 Bot: Reinicia tu router. Si persiste, llama al *611.

🤖 Bot: ¿Te fue útil esta información, Carlos?

👤 Tú: sí gracias

🤖 Bot: ¡Me alegra ayudarte! Gracias por contactar a Claro. ¡Excelente día! 🎉

📊 Datos recolectados: { nombre_cliente: "Carlos", tipo_consulta: "soporte", tipo_soporte: "internet", satisfecho: "yes" }

Flow Diagram

┌─────────────┐
│  Bienvenida │
└──────┬──────┘

┌──────▼──────┐
│ Menu Principal │
└──────┬──────┘

   ┌───┼───┐
   │   │   │
┌──▼─┐ ┌▼──┐ ┌─▼──┐
│Fact│ │Sop│ │Plan│
└──┬─┘ └─┬─┘ └──┬─┘
   │     │      │
   └──┬──┴──────┘

┌─────▼─────┐
│Satisfacción│
└─────┬─────┘

  ┌───┴───┐
  │       │
┌─▼─┐   ┌─▼─┐
│ 😊│   │ 😔│
└───┘   └───┘

Released under the MIT License.