McTaba Labs logo
Software EngineeringThe WhiteboardProjectsEventsMasterclassesWebinarsLearn
Book Call

500+ developers already in the community

Get answers, find accountability partners, and stay ahead

Join Discord →
McTaba Labs logo

Educating 1 million students in tech by 2030.

Programs

  • HighSchool Graduates Launchpad
  • AI & Business Automation
  • Corporate Training
  • McTaba Story & Mission
  • Full-Stack Curriculum
  • Course Pricing & Plans
  • Frequently Asked Questions

Resources

  • Join Discord Community
  • Tech Events in Nairobi
  • Masterclasses
  • Free Resources
  • Learn
  • Campus
  • Africa Tech Talent Report
  • Partner With Us
  • Start a Project
  • Our Work

Contact Us

  • 124 Manyani East Road, Lavington, Nairobi
  • +254727795603
  • Book a Discovery Call

Office Hours:

Mon-Fri: 9am - 2pm EAT

Sat: 10am - 12pm EAT

© 2027 McTaba Labs - A product of Edtech Industries. All rights reserved.

Privacy PolicyTerms of ServiceRefund Policy
  1. Learn
  2. Paystack for African Developers
  3. Building a Natural Language Revenue Dashboard
Bonaventure OgetoBy Bonaventure Ogeto|Updated July 22, 2026

Building a Natural Language Revenue Dashboard

Architecture: 1) Define tools for Paystack queries (list_transactions with date/channel/status filters, get_plan_subscriptions, get_settlements). 2) User types a natural language question. 3) LLM translates intent to tool calls — e.g., "last month revenue" → list_transactions({from: "2026-06-01", to: "2026-06-30", status: "success"}). 4) Tool results returned to LLM for aggregation and plain-English response. 5) Keep the dashboard read-only — no write tools in this context.

Dashboard Tools and Query Flow

// Tools for the natural language revenue dashboard
const dashboardTools = [
  {
    name: 'get_revenue_summary',
    description: 'Get total revenue, transaction count, average order value, and channel breakdown for a date range.',
    input_schema: {
      type: 'object',
      properties: {
        from: { type: 'string', description: 'Start date YYYY-MM-DD' },
        to: { type: 'string', description: 'End date YYYY-MM-DD' },
      },
      required: ['from', 'to'],
    },
  },
  {
    name: 'get_top_customers',
    description: 'Get the top customers by total spend in a date range.',
    input_schema: {
      type: 'object',
      properties: {
        from: { type: 'string' },
        to: { type: 'string' },
        limit: { type: 'number', description: 'Number of customers, default 10' },
      },
      required: ['from', 'to'],
    },
  },
  {
    name: 'get_subscription_mrr',
    description: 'Get Monthly Recurring Revenue from active Paystack subscriptions.',
    input_schema: { type: 'object', properties: {} },
  },
];

// Server-side: compute summaries, not raw data
async function executeRevenueTool(toolName, input) {
  var headers = { Authorization: 'Bearer ' + process.env.PAYSTACK_SECRET_KEY };

  if (toolName === 'get_revenue_summary') {
    // Fetch all transactions in range (paginate for large volumes)
    var url = 'https://api.paystack.co/transaction?status=success&from=' + input.from + '&to=' + input.to + '&perPage=100';
    var txns = (await (await fetch(url, { headers })).json()).data || [];

    // Compute server-side — do not send raw array to LLM
    var total = txns.reduce((sum, t) => sum + t.amount, 0);
    var byChannel = txns.reduce((acc, t) => {
      acc[t.channel] = (acc[t.channel] || 0) + t.amount;
      return acc;
    }, {});

    return {
      total_kobo: total,
      total_ngn: total / 100,
      transaction_count: txns.length,
      average_order_ngn: txns.length ? total / 100 / txns.length : 0,
      by_channel: Object.fromEntries(Object.entries(byChannel).map(([k, v]) => [k, v / 100])),
    };
  }

  if (toolName === 'get_subscription_mrr') {
    var subs = (await (await fetch('https://api.paystack.co/subscription?status=active&perPage=100', { headers })).json()).data || [];
    var mrr = subs.reduce((sum, s) => sum + s.amount, 0) / 100;
    return { mrr_ngn: mrr, active_subscriptions: subs.length };
  }
}

Learn More

See building a Paystack query agent for the underlying tool calling pattern.

Sign up for the McTaba newsletter

Key Takeaways

  • ✓Natural language dashboards translate user questions to Paystack API calls via LLM tool calling.
  • ✓Feed aggregated summaries to the LLM, not raw transaction arrays — reduce token cost and hallucination risk.
  • ✓Include a date resolution tool so the LLM can convert "last month" to exact dates before querying.
  • ✓The dashboard is read-only — no payment actions, only data retrieval and aggregation.
  • ✓Compute KPIs server-side (total, average, growth %) before returning to LLM — do not rely on LLM arithmetic.

Frequently Asked Questions

How do I handle "last month" or "this week" in natural language queries?
Add a date resolution tool or pre-process the user query server-side. Before sending to the LLM, replace relative date references with absolute dates using your server's current date. Or add a resolve_date_range tool that the LLM calls first: resolve_date_range("last month") → { from: "2026-06-01", to: "2026-06-30" }. Never rely on the LLM to know what "today" is without giving it the current date in the system prompt.
Can I display charts in the response?
Yes — return structured data alongside the natural language answer. Have the LLM return a JSON block with chart_data (array of {label, value} objects) alongside the text response. Your frontend renders the chart using the structured data, while the text provides the narrative. The LLM is good at formatting data for charts; it just needs to know to include it.
How do I handle multi-currency businesses?
Paystack returns amounts in the smallest currency unit for the transaction currency. Your summary tool should group by currency before aggregating — do not add NGN and KES together. Return separate summaries per currency and let the LLM present them clearly. If you need a combined number, convert using an exchange rate you supply — do not let the LLM guess exchange rates.

Learn Paystack Integration

KES 2,999

The definitive guide to building payment systems with Paystack — from your first transaction to production-grade payment infrastructure across Africa. 9 modules, 47 lessons. Free preview available.

Start Paystack Course

Not ready? Create Free Account

Keep reading

Paystack AI Agents and the MCP Server: The Complete Guide

A comprehensive guide to building AI agents that interact with Paystack through the Model Context Protocol (MCP) server. Covers connecting the MCP server to Claude Code, querying transactions with natural language, building payment support chatbots, AI-assisted reconciliation, agentic payouts with safety rails, secret key security, human-in-the-loop design, prompt injection risks, and audit trails for AI-initiated financial actions.

Read more

RAG Over Your Payment Documentation and Transaction History

RAG lets an LLM answer questions grounded in your actual Paystack docs and transaction history instead of its training data. "What does this error code mean?" retrieves from your embedded docs. "What happened to transaction X?" retrieves from your transaction store.

Read more

Why You Should Never Give an LLM Your Paystack Secret Key

Your Paystack secret key can initialize transactions, trigger transfers, and access all your transaction data. Giving it to an LLM — even once — creates risks that do not go away when you close the chat window.

Read more

Building a Voice Agent That Collects Payment

A customer calls your number. They say what they want to pay for. The voice agent creates a Paystack payment link and texts it to their phone. No human operator needed. Here is how to build it.

Read more

Accept Payments with Paystack in Supabase Edge Functions

Supabase Edge Functions run Deno TypeScript at the edge. Use them as your Paystack backend to initialize transactions, verify payments, and handle webhooks without deploying a separate server.

Read more

Explore related topics

M-Pesa & African Stack

M-Pesa Daraja API tutorials, USSD development, and WhatsApp Business API guides. The African Stack that global bootcamps do not teach.

Learn to Code in Kenya

Everything a Kenyan needs to know before writing their first line of code. Career paths, real costs, hardware requirements, and honest answers about what it takes.

Learning to Code

Roadmaps, language guides, and practical advice for learning to code and launching a programming career.

Breaking Into Tech

Practical, no-nonsense guides for anyone looking to start or change their career in tech. From choosing your first language to acing interviews.

The African Stack: Skills for This Market

The skills that make Kenyan developers hard to replace: M-Pesa, USSD, WhatsApp, fintech, and building for the African market.

Bonaventure Ogeto

Bonaventure Ogeto

Founder, McTaba Labs

Bonaventure is the founder of McTaba Labs, a coding bootcamp in Nairobi, Kenya. He has spent years building products for the African market and mentoring the next generation of developers across the continent.