I added a Telegram bot to SpendFlow, my personal expense manager, so I can log spending by sending a message like "50 coffee" instead of opening the app. This post summarizes how it is wired into a Next.js app.

What the walkthrough covers:

  • Receiving Telegram updates through a webhook route handler, since Telegram cannot call Server Actions.
  • Linking a Telegram chat to a signed-in user with a one-time link that expires, so no password is ever sent to the bot.
  • Parsing messages like "50 coffee" and "+5000 salary" into transactions and matching the category to the user's own category names.
  • Keeping the webhook authenticated with a secret header.

The full step-by-step guide, with code, is on the SpendFlow site: https://spendflow.cloud/guides/build-a-telegram-bot-for-your-nextjs-app

SpendFlow itself is a free personal expense manager for web and Android: https://spendflow.cloud/welcome . It is a side project, and feedback is welcome.