DEV Community

Samuel Kyeremeh
Samuel Kyeremeh

Posted on

Turning an Existing Express API into a Conversational Backend (Konsier Integration)

In Part 2, I broke down the architecture behind conversational systems:

Agents → Tools → Backend → Channels

Now let’s make it real.

In this post, I’ll walk through how I integrated this model into an existing Express API using Konsier.

No rewrite.
No new backend.

Just layering a conversational interface on top of what already exists.


Starting Point

I already had a simple Express + PostgreSQL backend.

It exposed endpoints like:

GET /menu
POST /orders
GET /orders/:id
PATCH /orders/:id
Enter fullscreen mode Exit fullscreen mode

Typical setup:

Client → Express API → Database
Enter fullscreen mode Exit fullscreen mode

The goal was:

Allow users to interact with this backend through chat (Telegram, WhatsApp, etc.)

without rewriting the API.


What Changes (and What Doesn’t)

The important thing to understand:

Your backend stays the same.

You’re not replacing your API.

You’re adding a new layer:

User (chat)
     ↓
Konsier
     ↓
Express API
     ↓
Database
Enter fullscreen mode Exit fullscreen mode

Step 1 — Install Konsier

npm install konsier
Enter fullscreen mode Exit fullscreen mode

If you're using Express:

npm install express
Enter fullscreen mode Exit fullscreen mode

Step 2 — Define Your First Tool

Tools are how your agent interacts with your backend.

Start with something simple like fetching the menu.

```ts id="tool1"
import { Konsier } from "konsier";
import { z } from "zod";

const getMenu = Konsier.tool({
name: "get_menu",
description: "Returns all menu items",

input: z.object({
category: z.string().optional(),
}),

handler: async (input) => {
const items = await db.query("SELECT * FROM menu_items");
return { items: items.rows };
},
});




This is just a wrapper around your existing logic.

---

## Step 3 — Configure the Agent

Now define an agent that can use this tool.



```ts id="agent1"
const konsier = new Konsier({
  apiKey: process.env.KONSIER_API_KEY!,

  endpointUrl: "https://your-public-url.com/konsier",

  agents: {
    customer_support: {
      name: "Customer Support",
      description: "Helps users browse the menu",

      systemPrompt: "You help users find food and place orders.",

      tools: [getMenu],
    },
  },
});
Enter fullscreen mode Exit fullscreen mode

The agent decides when to call get_menu.


Step 4 — Mount the Webhook

This is the connection point between Konsier and your backend.

```ts id="webhook1"
import express from "express";
import { serveKonsier } from "konsier/express";

const app = express();

serveKonsier(app, konsier);




This automatically:

* creates the webhook route
* validates requests
* routes messages to your agent

---

## Step 5 — Sync Your Configuration

Start your server and sync:



```ts id="sync1"
app.listen(3000, async () => {
  await konsier.sync();
  console.log("Server running");
});
Enter fullscreen mode Exit fullscreen mode

This pushes your local agent + tools config to Konsier Cloud.


Step 6 — Connect a Channel

In the Konsier dashboard:

  1. Create a project
  2. Add your API key
  3. Set your public /konsier endpoint
  4. Link your agent
  5. Connect a channel (Telegram, Slack, etc.)

Now send a message like:

“What food do you have?”

Your agent will automatically call get_menu.


End-to-End Flow

Here’s what happens when a user sends a message:

User → Telegram
        ↓
     Konsier
        ↓
   /konsier webhook
        ↓
     Agent
        ↓
     Tool (get_menu)
        ↓
     Database
        ↓
     Response → User
Enter fullscreen mode Exit fullscreen mode

Key Takeaway

You didn’t rebuild your backend.

You didn’t duplicate logic.

You simply exposed your existing functionality as tools.

That’s the power of this approach.


What’s Next

So far we’ve only used a simple read operation (get_menu).

But real systems need more:

  • creating orders
  • updating orders
  • tracking status
  • handling edge cases

In Part 4, we’ll go deeper into tool design:

  • how to structure tools properly
  • how to validate inputs
  • how to avoid breaking your backend
  • and how to handle real business logic

If you're already running an Express backend, you're closer than you think to having a conversational interface.

In the next post, we’ll build real tools on top of it.

Top comments (0)