Automation library · Alerts and monitoring

Telegram giveaways among channel subscribers with Postgres

Started by an incoming Telegram message, and works across Postgres and Telegram. 37 steps, 8 branches: large, and worth reading before you trust it with anything live.

Large

37 stepsLarge: read it before trusting it with anything live
8Branches: places the flow splits
0Loops or waits
2Services it connects to

The flow

Starts it 1Logic 12Service 24

The steps in the order they run, from what starts it.

  1. 1Telegram TriggerTelegram triggerStarts it
  2. 2Variables TGSetLogic
  3. 3InitializationSetLogic
  4. 4Start?IfLogic
  5. 5Referal?IfLogic
  6. 6Button?IfLogic
  7. 7Welcome message ReferalTelegramService
  8. 8Welcome message ManagerTelegramService
  9. 9ButtonsSwitchLogic
  10. 10Get Bot StatusPostgresService
  11. 11Update bot status and referalPostgresService
  12. 12Upsert bot status on STARTPostgresService
  13. 13Update bot status on GIVEAWAY RUNPostgresService
  14. 14Define flowSwitchLogic
  15. 15Add participant in GiveawayPostgresService
  16. 16Create GiveawayTelegramService
  17. 17CommandsSwitchLogic
  18. 18Add channelPostgresService
  19. 19Define Step GiveawaySwitchLogic
  20. 20List ChannelsTelegramService
  21. 21Request New ChannelTelegramService
  22. 22Channel ExistsTelegramService
  23. 23Get ParticipantsPostgresService
  24. 24Update bot status on GIVEAWAY REQUEST CHANNELPostgresService
  25. 25Random ParticipantsSortLogic
  26. 26Get ChannelsPostgresService
  27. 27TelegramTelegramService
  28. 28Union StatusesAggregateLogic
  29. 29Check Success?IfLogic
  30. 30Check SuccessTelegramService
  31. 31SMS for WinnerTelegramService
  32. 32Check FailedTelegramService
  33. 33SMS for ManagerTelegramService
  34. 34Delete ChannelsPostgresService
  35. 35Delete ParticipantsPostgresService
  36. 36Update bot status on START PostgresService
  37. 37End MessageTelegramService

How it's built

Starts on
An incoming Telegram message
Steps
37, with 8 branches
Size
Large: read it before trusting it with anything live
Connects to
Postgres, Telegram
Model
None. This is plumbing, not judgement

Questions

What does it need to run?

An n8n account, plus your own Postgres and Telegram accounts. You connect your own accounts after importing it; none are included.

What starts it?

It starts on an incoming Telegram message.

Does it use AI?

No. Every step is fixed logic or a call to a service, so it does the same thing every time.

How long does it take to set up?

Take your time. At 37 steps it is large: read it before trusting it with anything live.

How do I import it?

Copy the workflow, open a new workflow in n8n and paste. The steps appear on the canvas, ready for your own accounts.

Before you run it

Nothing here has been tested by us. It is somebody's working automation, read and described from its own steps. Treat the connections it wants as a list of accounts it will touch, and read the 37 steps before you point it at anything that matters.