n8n workflow blueprint

Telegram Gym Pass Automation

A polished implementation blueprint for a Telegram bot that verifies SMU students, presents available gyms, collects PayNow proof, supports payment verification, and issues a one-time pass for counter staff redemption.

Telegram Bot online
Welcome! Please enter your SMU student number.
S1234567A
Verified. Available gym: 1. Example Gym — $8.00
YES, confirm
Payment verified. Your pass code is GYM-X8K2P9QA.

System Overview

The first version can support one gym, while the schema and routing are designed to scale when additional gyms are onboarded.

1

Verify Student

Student enters an SMU number in Telegram. n8n checks it against the existing student database and links the Telegram user ID.

2

Purchase Pass

The bot displays gym options, confirms the chosen gym, creates an order, then shows price, PayNow number, and no-refund terms.

3

Issue Verification

After payment proof is approved, the bot sends a unique pass code or QR/image that the student shows at the gym counter.

Animated Workflow

Each step maps directly to an n8n branch, node group, or sub-workflow.

STEP 01

Telegram Trigger receives message

Capture text, photo, document, Telegram user ID, and chat ID. Route /start or new users to the login step.

Telegram TriggerSetCode
STEP 02

Load conversation state

Retrieve the current stage from conversation_states. If none exists, create awaiting_smu_number.

Database LookupIF
STEP 03

Verify SMU student number

Validate the format, then query active student records. If invalid, ask the student to try again.

Postgres/MySQLSwitch
STEP 04

Show available gyms

Query active gyms and present a numbered list. In MVP mode, show one gym and ask the student to reply with 1.

gyms tableTelegram Send
STEP 05

Confirm gym selection

Save the selected gym temporarily, then ask the student to reply YES or NO before creating the order.

awaiting_gym_confirmation
STEP 06

Create pending order

Generate an order reference, freeze the selected gym price, and set status to pending_payment.

pass_ordersorder_reference
STEP 07

Collect PayNow screenshot

Send PayNow number, amount, order reference, and no-refund warning. Wait for an image upload.

PhotoDocumentpayment_uploaded
STEP 08

Verify payment

MVP path: forward screenshot to an admin Telegram group. Admin approves or rejects using the order reference.

Manual approvalOCR optionalAPI future
STEP 09

Generate pass and send to student

Create a unique code, optional QR/pass image, expiry time, and one-time-use redemption status.

Code NodeQRTelegram Send Photo
STEP 10

Counter staff redemption

Staff checks or redeems the pass code. n8n rejects expired, already used, or invalid passes.

REDEEM commandstatus: redeemed

Database Blueprint

Use these tables in PostgreSQL, MySQL, Supabase, Airtable, or Google Sheets depending on your stack.

students

FieldPurpose
smu_numberStudent card number for login verification.
full_nameDisplayed on final pass.
telegram_user_idLinks Telegram account after verification.
statusactive, inactive, or blocked.

gyms

FieldPurpose
gym_nameShown in Telegram selection list.
pricePer-entry pass price.
paynow_numberPayment recipient number.
is_activeControls availability.

pass_orders

FieldPurpose
order_referencePayment note and admin approval key.
statuspending_payment, verified, redeemed, expired.
pass_codeUnique one-time verification code.
expires_atOptional pass expiry timestamp.

conversation_states

FieldPurpose
telegram_user_idIdentifies the active conversation.
current_stepRoutes the next message.
selected_gym_idStores temporary gym choice.
active_order_idConnects payment upload to an order.

n8n Node Map

Recommended nodes for the MVP workflow and future-ready payment verification.

Telegram TriggerReceive messages, commands, photos, and document uploads.
Normalize MessageExtract chat ID, user ID, text, file IDs, and attachment flags.
State LookupRead conversation state and route to the correct branch.
Student DB QueryCheck SMU number against active student records.
Gym DB QueryReturn active gyms with name, location, price, and PayNow number.
Order CreationCreate pending order and freeze selected price.
Admin VerificationForward screenshot to admin group for approve/reject commands.
Pass GeneratorCreate unique code, optional QR, expiry, and final Telegram response.

Core Logic Snippets

Drop these into n8n Code or database nodes and adapt field names to your actual database.

MVP recommendation:
Start with manual admin payment verification. Screenshot-only automation is easy to spoof, so full automation should wait until you have a payment API or reconciliation feed.
// Generate a pass code in n8n Code node
function randomCode(length = 8) {
  const chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
  let result = '';
  for (let i = 0; i < length; i++) {
    result += chars[Math.floor(Math.random() * chars.length)];
  }
  return result;
}

return [{
  json: {
    pass_code: `GYM-${randomCode(8)}`,
    expires_in_hours: 24
  }
}];