Skip to content

Avanza Notifier Telegram Bot

What I did

  • Development
  • Deployment
Challenge
On the Segovia–Madrid route the seats for high-demand dates sell out, and cancellations free them without any notice.
Solution
A Telegram bot that repeats the requests of the reservations website to monitor a route and date, and alerts as soon as a seat is free.
Outcome
Two sprints: first the end-to-end flow (bot, scraping, persistence), then stop selector, destination filtering, search and passenger selection.
Challenge
En el trayecto Segovia–Madrid las plazas de las fechas de mayor demanda se agotan, y las cancelaciones las liberan sin avisar.
Solution
Un bot de Telegram que reproduce las peticiones de la web de reservas para vigilar una ruta y una fecha, y avisa en cuanto queda una plaza libre.
Outcome
Dos sprints: primero el flujo completo (bot, scraping y persistencia) y después selector de paradas, filtro de destinos, búsqueda y selección de pasajeros.

This project arose from the existence of the problem En el trayecto Segovia - Madrid that covers Avanza Bus, the seats in high demand dates are sold out in advance, but free spaces are released by other passengers due to cancellations, without any notice. The alternative was to refresh the reservations web manually every so often in case a seat became available. AvanzaNotifierBot is a Telegram bot that monitors a specific route and date, and alerts you as soon as a seat becomes available.

The repository collects two sprints of work: The first Sprint focused on having a functional end-to-end flow — bot, scraping and persistence —. The second Sprint included the expansion of the user experience: real stop selector, direct destination filtering, pagination, text search and passenger selection.

Avanza Bus does not offer a public availability API. The bot reproduces the same sequence of requests that the reservations web uses to query schedules through scraping (requests + BeautifulSoup). To be able to filter which destinations have real connection from each origin, it crosses two stop catalogs with different identifier systems — one from the public web (684 stops) and another from the reservations searcher (691 stops, with another code prefix) — matching them by normalized name, since neither of them directly exposes that relationship.

What it offers

For who uses the bot in Telegram

  • Guided flow (/buscar) to choose origin and destination stop, with paginated listing (8 stops per page) and text search that ignores accents and uppercase.
  • When choosing the origin, only the destinations with real direct connection are shown; if it cannot be determined, the full list is offered as an alternative.
  • Selection of date and between 1 and 25 passengers.
  • Immediate notification if there are free seats when creating the watch, and management of active watches (list and cancel) with /vigilancias.

Automatic watch

  • Periodic check every 5 minutes for each active watch, through an internal job of the bot itself.
  • Only notifies when a new free trip appears compared to the last check, comparing against the known state stored in the database, to avoid repeating notifications for the same empty space.
  • Watches survive bot restarts: they are restored from the database when the bot starts.
  • Daily automatic cleanup (GitHub Actions, cron) of watches with past dates, with a warning to the user about the cancellation.

Disclaimer

This is an unofficial, non-commercial fan project built for portfolio and learning purposes. It is not affiliated with or endorsed by Avanza Bus or any related entity.

Este proyecto nace de la existencia del problema En el trayecto Segovia - Madrid que cubre Avanza Bus, las plazas en fechas de alta demanda se agotan con antelación, pero se liberan huecos por cancelaciones de otros viajeros, sin ningún aviso. La alternativa era refrescar la web de reservas a mano cada cierto tiempo por si aparecía sitio. AvanzaNotifierBot es un bot de Telegram que vigila un trayecto y una fecha concretos, y avisa en cuanto se libera una plaza.

El repositorio recoge dos sprints de trabajo: El primer Sprint se priorizó el tener un flujo funcional de extremo a extremo — bot, scraping y persistencia —. El segundo Sprint se incluyó la ampliación de la experiencia de uso: selector real de paradas, filtrado de destinos con conexión directa, paginación, búsqueda por texto y selección de número de pasajeros.

Avanza Bus no ofrece una API pública de disponibilidad. El bot reproduce mediante scraping (requests + BeautifulSoup) la misma secuencia de peticiones que usa la propia web de reservas para consultar horarios. Para poder filtrar qué destinos tienen conexión real desde cada origen, cruza dos catálogos de paradas con sistemas de identificadores distintos — uno de la web pública (684 paradas) y otro del buscador de reservas (691 paradas, con otro prefijo de código) — emparejándolos por nombre normalizado, ya que ninguno de los dos expone directamente esa relación.

Qué ofrece

Para quien usa el bot en Telegram

  • Flujo guiado (/buscar) para elegir parada de origen y destino, con listado paginado (8 paradas por página) y buscador por texto que ignora tildes y mayúsculas.
  • Al elegir el origen, solo se muestran los destinos con conexión directa real; si no se puede determinar, se ofrece el listado completo como alternativa.
  • Selección de fecha y de entre 1 y 25 pasajeros.
  • Aviso inmediato si ya hay plazas libres al crear la vigilancia, y gestión de las vigilancias activas (listar y cancelar) con /vigilancias.

Vigilancia automática

  • Comprobación periódica cada 5 minutos de cada vigilancia activa, mediante un job interno del propio bot.
  • Solo notifica cuando aparece un viaje libre nuevo respecto a la última comprobación, comparando contra el estado conocido guardado en base de datos, para no repetir avisos de un mismo hueco.
  • Las vigilancias sobreviven a reinicios del bot: se restauran desde la base de datos al arrancar.
  • Limpieza diaria automática (GitHub Actions, cron) de vigilancias con fecha ya pasada, con aviso al usuario de la cancelación.

Descargo de responsabilidad

Este es un proyecto no oficial, no comercial y fanático construido con fines de portafolio y aprendizaje. No está afiliado ni respaldado por Avanza Bus o cualquier entidad relacionada.