/ Cases / Restaurants / Finance

FEL e-invoicing with no typing

The invoice is built in a Telegram mini-app from the POS receipt, and a bot issues it with the SAT (Guatemala's tax authority) as FEL, the country's electronic invoice. Another bot pulls supplier invoices every hour for costing.

/ Restaurantes Atitlán · The Coffee Lab/ 2026/ Bots with a queue and a watchdog every 10 min

1 h

between purchase downloads

10 min

queue monitoring

/ The problem

Every invoice was typed by hand into the SAT's online portal, and supplier invoices were downloaded one by one. The SAT blocks common cloud networks.

/ What we built

  • Telegram mini-app: the cashier picks the POS receipt and the invoice builds itself.
  • A bot signs it in the SAT portal and sends the link to the customer.
  • Another bot pulls received invoices every hour to cost inventory.
  • A queue with statuses and a watchdog every 10 minutes; when the SAT changed its portal, the bots were updated the same day.
  • Another business (The Coffee Lab) requests its invoices by API.

/ How it works

  1. 01POS receipt
  2. 02Telegram mini-app
  3. 03Queue
  4. 04Bot at the SAT
  5. 05Invoice delivered

/ By the numbers

E-invoices issued per month

■ Real production data · counts per month, no amounts or personal data · November through the 27th.

Supplier invoices downloaded by the bot

■ Real production data · counts per month, no amounts or personal data · November through the 27th.

/ Real code

supabase/migrations/20261030041801_fel_documentos_cola.sqlsql
create table if not exists public.fel_documentos (
  origen           text not null check (origen in ('telegram','admin','pos','loyverse')),
  -- …
  estado           text not null default 'borrador'
                   check (estado in ('borrador','pendiente','emitiendo','certificada','rechazada','error','incierta','cancelada')),
  -- …
  constraint fel_documentos_origen_uq unique (origen, origen_id),
  constraint fel_documentos_cf_tope check (receptor_tipo <> 'CF' or total < 2500)
);
-- …
-- El emisor toma UNA pendiente, la pasa a «emitiendo» y la devuelve. Si dos
-- emisores preguntan a la vez, cada uno recibe una distinta (skip locked).
create or replace function public.fel_tomar_siguiente()
returns setof public.fel_documentos
language sql
security invoker
set search_path = ''
as $$
  update public.fel_documentos d
     set estado = 'emitiendo', tomado_en = now(), intentos = d.intentos + 1, actualizado_en = now()
   where d.id = (
     select p.id from public.fel_documentos p
      where p.estado = 'pendiente'
      order by p.creado_en
      for update skip locked
      limit 1)
  returning d.*;
$$;

■ The same sale is never invoiced twice (unique per source) and two robots never pick the same invoice (for update skip locked).

/ Stack

PlaywrightDockerGoogle Cloud VMTelegramPostgres