16 KiB
Telegram User Registration Workflow
https://n8nworkflows.xyz/workflows/telegram-user-registration-workflow-2406
Telegram User Registration Workflow
1. Workflow Overview
The Telegram User Registration Workflow automates user management for a Telegram bot by connecting to a Google Sheets database. It identifies whether a Telegram user is new or returning through their unique Telegram ID, stores or updates their registration data accordingly, and sends personalized welcome messages.
Target Use Cases:
- Telegram bots requiring user registration and data management
- Scenarios needing persistent user data storage and status tracking in Google Sheets
- Bots desiring personalized user interaction based on registration status
Logical Blocks:
- 1.1 Input Reception: Trigger the workflow and capture incoming Telegram user data.
- 1.2 User Lookup: Search for the user in Google Sheets by Telegram ID.
- 1.3 Data Preparation: Prepare user data for storage or update.
- 1.4 New vs Returning User Decision: Branch logic depending on whether the user exists.
- 1.5 User Data Storage: Insert new user data or update existing user status in Google Sheets.
- 1.6 Personalized Messaging: Send welcome messages tailored to new or returning users.
2. Block-by-Block Analysis
2.1 Input Reception
-
Overview: Receives the trigger to start the user registration process and initializes user data capture.
-
Nodes Involved:
- Trigger Start
- Trigger_Data
- Data Example (provides example data for testing or initialization)
-
Node Details:
-
Trigger Start
- Type: Execute Workflow Trigger
- Role: Starts the workflow when activated externally (likely by a connected Telegram bot workflow).
- Config: No parameters configured, serves as an entry point.
- Inputs: None (trigger node).
- Outputs: Passes data to
Trigger_Data. - Failures: Trigger misfires or missing data could stop flow.
-
Trigger_Data
- Type: Set
- Role: Prepares or normalizes incoming user data for downstream nodes.
- Config: Likely sets required user fields like Telegram ID, first name, username, etc. (Specific parameters not listed but interpreted by role).
- Inputs: From
Trigger Start. - Outputs: Sends structured data to
Find User. - Failures: Missing or malformed input data may cause lookup failures.
-
Data Example
- Type: Set
- Role: Provides example user data for testing or demonstration purposes.
- Config: Contains static user fields mimicking real Telegram data.
- Inputs: None (standalone or manual trigger).
- Outputs: None connected in this workflow; serves informational or development use.
-
2.2 User Lookup
-
Overview: Queries Google Sheets to find if the user exists based on their Telegram ID.
-
Nodes Involved:
- Find User
-
Node Details:
- Find User
- Type: Google Sheets
- Role: Searches the spreadsheet database for an existing user's Telegram ID.
- Config:
- Operation: Lookup/search rows.
- Key field: Telegram user ID column.
- Sheet and document ID configured to the user database sheet.
- Output: Returns matching user data or empty if not found.
- Inputs: Receives user ID data from
Trigger_Data. - Outputs: Sends found user data or empty result to
Data to Save. - Failures:
- Authentication errors with Google Sheets API.
- No matching rows found leads to empty output (expected).
- API rate limits or connectivity issues.
- Find User
2.3 Data Preparation
-
Overview: Prepares a data object with user info to save or update in the database.
-
Nodes Involved:
- Data to Save
-
Node Details:
- Data to Save
- Type: Set
- Role: Constructs a data object including user fields: first name, last name, username, language code, status, registration date.
- Config: Sets variables based on either found user data or incoming trigger data; likely assigns status "new" or "returning" accordingly.
- Inputs: Receives data from
Find User. - Outputs: Passes the prepared data to decision node
New?. - Failures: Expression errors if expected fields are missing or misnamed.
- Data to Save
2.4 New vs Returning User Decision
-
Overview: Determines if the user is new (not found in the database) or returning (found).
-
Nodes Involved:
- New? (If node)
-
Node Details:
- New?
- Type: If Node
- Role: Checks presence of user data to branch into new user registration or returning user update.
- Config: Condition likely tests if
Find Userreturned any data (e.g., user ID exists). - Inputs: From
Data to Save. - Outputs:
- True (new user): leads to
Write to Data Base. - False (returning user): leads to
Update status.
- True (new user): leads to
- Failures: Logic errors if condition expressions are incorrect or input data missing.
- New?
2.5 User Data Storage
-
Overview: Writes new user data to Google Sheets or updates the status of returning users.
-
Nodes Involved:
- Write to Data Base
- Update status
-
Node Details:
-
Write to Data Base
- Type: Google Sheets
- Role: Inserts new user data row into the user database sheet.
- Config:
- Operation: Append row.
- Uses data from
New?true branch. - Fields: first name, last name, username, language code, status, registration date.
- Inputs: From
New?node (true branch). - Outputs: Leads to
Welcome message. - Failures: Authentication, API limits, data format errors.
-
Update status
- Type: Google Sheets
- Role: Updates existing user's status (e.g., "returning") and possibly the last active date.
- Config:
- Operation: Update row at matched user ID.
- Inputs: From
New?node (false branch). - Outputs: Leads to
Welcome back. - Failures:
- Row not found (inconsistent DB).
- API permissions or connectivity errors.
-
2.6 Personalized Messaging
-
Overview: Sends customized Telegram messages welcoming the user based on their registration status.
-
Nodes Involved:
- Welcome message
- Welcome back
-
Node Details:
-
Welcome message
- Type: Telegram
- Role: Sends a welcome message to newly registered users.
- Config:
- Uses Telegram credentials.
- Message content can include personalization tokens from user data.
- Inputs: From
Write to Data Base. - Outputs: End of new user flow.
- Failures: Telegram API failures, invalid chat IDs.
-
Welcome back
- Type: Telegram
- Role: Sends a greeting to returning users acknowledging their return.
- Config: Similar setup to
Welcome message. - Inputs: From
Update status. - Outputs: End of returning user flow.
- Failures: Same as above.
-
3. Summary Table
| Node Name | Node Type | Functional Role | Input Node(s) | Output Node(s) | Sticky Note |
|---|---|---|---|---|---|
| Note3 | Sticky Note | Informational | |||
| Trigger Start | Execute Workflow Trigger | Entry point | Trigger_Data | ||
| Trigger_Data | Set | Prepare incoming user data | Trigger Start | Find User | |
| Note4 | Sticky Note | Informational | |||
| Note2 | Sticky Note | Informational | |||
| Note | Sticky Note | Informational | |||
| Find User | Google Sheets | Lookup user by Telegram ID | Trigger_Data | Data to Save | |
| Note1 | Sticky Note | Informational | |||
| Data to Save | Set | Prepare data for save/update | Find User | New? | |
| Write to Data Base | Google Sheets | Insert new user record | New? (true branch) | Welcome message | |
| Welcome message | Telegram | Welcome new users | Write to Data Base | ||
| Welcome back | Telegram | Welcome returning users | Update status | ||
| New? | If | Branch for new vs returning | Data to Save | Write to Data Base, Update status | |
| Update status | Google Sheets | Update returning user status | New? (false branch) | Welcome back | |
| Data Example | Set | Sample data for testing |
4. Reproducing the Workflow from Scratch
-
Create Trigger Start Node:
- Type: Execute Workflow Trigger
- Purpose: Entry point when triggered externally (e.g., from Telegram bot starter workflow).
- No special parameters.
-
Create Trigger_Data Node:
- Type: Set
- Purpose: Normalize and prepare incoming Telegram user data.
- Configure fields to capture Telegram user properties (e.g.,
user_id,first_name,last_name,username,language_code). - Connect input from
Trigger Start.
-
Create Find User Node:
- Type: Google Sheets (v4)
- Purpose: Search the user database sheet for the Telegram ID.
- Parameters:
- Operation: Lookup Rows
- Sheet: User database sheet name
- Key Column: Telegram User ID
- Key Value: From
Trigger_Data(Telegram user ID)
- Connect input from
Trigger_Data.
-
Create Data to Save Node:
- Type: Set
- Purpose: Prepare user data object for storage or update.
- Configure fields:
- Copy user properties from
Find Useroutput or fallback toTrigger_Data. - Add fields:
status(default "new"),date_of_registration(current date).
- Copy user properties from
- Connect input from
Find User.
-
Create New? Node:
- Type: If
- Purpose: Determine if user is new or returning.
- Condition: Check if the user exists from the
Find Useroutput (e.g., ifuser_idis empty, user is new). - Connect input from
Data to Save.
-
Create Write to Data Base Node:
- Type: Google Sheets
- Purpose: Append new user data row.
- Operation: Append Row
- Sheet: User database sheet
- Map fields from
Data to Save. - Connect input from
New?true branch.
-
Create Update status Node:
- Type: Google Sheets
- Purpose: Update existing user status to "returning".
- Operation: Update Row based on Telegram user ID.
- Connect input from
New?false branch.
-
Create Welcome message Node:
- Type: Telegram
- Purpose: Send a welcome message to new users.
- Configure Telegram credentials.
- Message text: Personalize using user data fields.
- Connect input from
Write to Data Base.
-
Create Welcome back Node:
- Type: Telegram
- Purpose: Send a greeting message to returning users.
- Configure credentials and message content.
- Connect input from
Update status.
-
Add Data Example Node (optional):
- Type: Set
- Purpose: Provide static example user data for testing.
- Not connected directly but can be used for manual testing.
-
Arrange Sticky Notes:
- Add sticky notes to document workflow sections, instructions, or context.
-
Credentials Setup:
- Configure Google Sheets OAuth2 credentials with read/write access to the target spreadsheet.
- Configure Telegram bot credentials with chat permission to send messages.
5. General Notes & Resources
| Note Content | Context or Link |
|---|---|
| Use the provided Google Sheets template to structure your user database correctly. | See setup instructions and attached images (not included here). |
| For integration, copy Workflow ID and paste it into your Telegram bot starter template’s Register module. | https://n8n.io/workflows/2402-telegram-bot-starter-template-setup/ |
| This workflow enables scalable user registration for Telegram bots in domains like meal planning or customer support. | |
| Reach out to Victor for n8n workflow assistance: https://www.linkedin.com/in/gubanovvictor/ | |
| The workflow uses Google Sheets API v4 and Telegram node version 1; ensure compatibility with your n8n environment. | |
| For testing, use the included example data node and sample Telegram user data to validate the flow before connecting to live bot. |