Skip to content
IP FediuninFull-Stack & AI Engineer
← All case studies

Case 08 · Automation / Backend / Integrations

Bots & API Integrations

Smart bots and automated services

Overview

Bots and automated programs that talk to users, external APIs and internal systems. A bot here is not a message window but a software system with business logic, state and integrations.

Generalised experience across several systems

The charts are computed by this case's model on synthetic data — the same model that runs the interactive demo. They show what the approach changes, not figures from a client's system.

What I did

  1. Bot logic and command handling
  2. Backend handlers with Flask
  3. Third-party API integrations
  4. Dialog state in Redis, data in PostgreSQL
  5. AI features through an LLM API

Before

  • Simple tasks need a separate application
  • Multi-step scenarios need a dialog that remembers
  • External services can fail in the middle of a request

After

  • Status checks, reports and questions right in the messenger
  • Multi-step scenarios guided step by step
  • Results stored in the database, not only in the chat

Multi-step reports completed

100%of report dialogs end with the report saved, typos included

  • A handler that forgets the dialog0%
  • State machine, state in Redis100%
Four synthetic /report dialogs with an impossible date, a vague answer and a second thought.

How it works

A model of the system you can run: watch requests and data move through the components. It is a simplified reconstruction on synthetic data, not the production code.

What is happening

Write to the bot: /start, /status 42, /report — or just a question. Every message goes through the webhook, Redis and the integration it needs.

The model runs in the browser on synthetic data. Times on the cards are illustrative, and motion is slowed down so the path can be followed.

Chat with the bot

    Quick messages

    Dialog state in Redis

    chat:stateidle

    Reports in PostgreSQL

    None yet — send /report.

    Engineering detailsThe full write-up: problem, architecture, implementation decisions and outcome.

    Problem

    Many everyday tasks are easier in a messenger than in a separate application: checking a status, sending a report, asking a question. That takes a bot that understands commands, guides the user through multi-step scenarios, calls external services and stores the result.

    Solution

    Messenger bots with a Flask backend: commands arrive by webhook, multi-step scenarios run as finite-state machines with the dialog state in Redis, and the bots call external APIs, store results in PostgreSQL and pass free-text questions to a language model.

    My role

    • Designed the bots' logic and the handling of user commands.
    • Built the backend handlers with Flask.
    • Integrated third-party APIs.
    • Built automated scenarios and worked with the data.
    • Kept dialog state and results in Redis and PostgreSQL.
    • Added AI features through an LLM API.

    Technical architecture

    User → messenger platform → Flask webhook → command handler → external API, LLM or database → reply to the user. The dialog state lives apart from the handler, in Redis, so every message is handled with the previous steps in mind.

    Implementation

    • Commands and scenarios. Simple commands answer at once, while multi-step scenarios are built as a finite-state machine: at every step the bot knows what it expects from the user.
    • External APIs. An unavailable external service is no reason to stay silent: the user gets a clear answer.
    • An LLM for free text. Questions outside the commands go to a language model.
    • Data. Scenario results are stored in the database, not only in the chat history.

    Functional outcome

    The bots get users' tasks done right in the messenger: they answer commands, guide through multi-step scenarios, fetch data from external systems and store the results.

    Need a system like this?

    Tell me about the problem — I'll come back with questions and a proposed approach.