19 KiB
Convert Telegram Channel Posts to WooCommerce Products Automatically
Convert Telegram Channel Posts to WooCommerce Products Automatically
1. Workflow Overview
This workflow automates the process of converting Telegram channel posts into WooCommerce products. It listens for new posts on a Telegram channel, extracts relevant content including text and images, processes the data, and creates or updates corresponding WooCommerce products with proper categorization and images.
The workflow is logically organized into the following blocks:
- 1.1 Telegram Input Reception: Captures new Telegram channel posts and filters incoming data.
- 1.2 Image Handling: Downloads images from Telegram messages, uploads them to an image hosting endpoint, and manages image arrays.
- 1.3 Category Resolution: Retrieves WooCommerce product categories and determines the correct category ID from the Telegram post text.
- 1.4 WooCommerce Product Management: Retrieves existing product data if any, creates new products, or updates existing ones with the processed content and images.
- 1.5 File Management: Reads from and writes to disk for temporary data persistence and file conversions.
- 1.6 Control Flow and Logic: Conditional checks and code nodes to control the flow, handle image presence, and assemble data structures.
2. Block-by-Block Analysis
2.1 Telegram Input Reception
-
Overview:
Listens for new posts on a Telegram channel, extracts initial post data, and sets fields for further processing. -
Nodes Involved:
- Telegram Trigger
- SetFields
- If
-
Node Details:
-
Telegram Trigger
- Type: Telegram Trigger
- Role: Entry point capturing new channel posts automatically
- Configuration: Default settings; webhook active to listen to new Telegram channel messages
- Inputs: None (trigger node)
- Outputs: Post data (text, media info)
- Edge cases: No new posts or unsupported message types
-
SetFields
- Type: Set
- Role: Normalizes and prepares incoming Telegram message data for workflow
- Configuration: Sets specific fields extracted from Telegram message for downstream nodes (e.g., text content, media info)
- Inputs: From Telegram Trigger
- Outputs: Structured message data
- Edge cases: Missing or malformed fields could cause downstream errors
-
If
- Type: If (Conditional)
- Role: Branches flow based on conditions (e.g., presence of media or text)
- Configuration: Checks for specific conditions in the Telegram post data (e.g., presence of photo)
- Inputs: From SetFields
- Outputs: Two branches — one for posts with files, another for posts without files
- Edge cases: Incorrect condition evaluation may misroute data
-
2.2 Image Handling
-
Overview:
Handles image extraction from Telegram posts, downloads files, uploads them to an image server, and manages image arrays for WooCommerce product images. -
Nodes Involved:
- IfHasPhoto (If)
- Get a file1 (Telegram)
- UploadImage (HTTP Request)
- Wait
- Read/Write Files from Disk1
- LastSavedJson (Extract From File)
- Get a product (WooCommerce)
- Code3 (Code)
- AppendImages (HTTP Request)
- Get a file (Telegram)
- UploadImage1 (HTTP Request)
- GetCategories (HTTP Request)
-
Node Details:
-
IfHasPhoto
- Type: If
- Role: Checks if the Telegram post has attached photos
- Configuration: Condition based on message media presence
- Inputs: From Code node (which processes data post initial filtering)
- Outputs: Branches to image download or skip
- Edge cases: Misidentification of media type may cause flow issues
-
Get a file1 & Get a file
- Type: Telegram nodes
- Role: Downloads Telegram files (photos) using Telegram API
- Configuration: Uses Telegram credentials and file_id from post
- Inputs: From IfHasPhoto or If node branches
- Outputs: Binary image data
- Edge cases: File might be unavailable, deleted, or inaccessible
-
UploadImage & UploadImage1
- Type: HTTP Request
- Role: Uploads downloaded images to external image hosting or WooCommerce media library endpoint
- Configuration: POST requests with multipart/form-data or base64 images to image upload API
- Inputs: Binary image data from Get a file nodes
- Outputs: Response containing uploaded image URLs or media IDs
- Edge cases: Network errors, authentication failures, or API limits
-
Wait
- Type: Wait
- Role: Introduces delay to ensure image upload completes before next steps (rate limiting or sync)
- Configuration: Configured with a delay duration (default or custom)
- Inputs: From UploadImage
- Outputs: Delayed trigger to next node
-
Read/Write Files from Disk1
- Type: Read/Write File
- Role: Reads or writes temporary JSON or image data to local disk for persistence across runs
- Configuration: File path and operation mode (read or write)
- Inputs: From Wait
- Outputs: File content or confirmation of write
- Edge cases: File access permissions, disk full, or missing files
-
LastSavedJson
- Type: Extract From File
- Role: Extracts JSON content from saved files for processing
- Configuration: Points to saved JSON file location on disk
- Inputs: From Read/Write Files from Disk1
- Outputs: Parsed JSON data for further use
-
Get a product
- Type: WooCommerce node
- Role: Retrieves existing WooCommerce product by SKU or ID to check for update necessity
- Configuration: WooCommerce credentials, product lookup parameters
- Inputs: From LastSavedJson
- Outputs: Product details or empty if not found
- Edge cases: API rate limits, authentication failures
-
Code3
- Type: Code (JavaScript)
- Role: Processes product images array, pushes new images for upload or association
- Configuration: Custom JS logic manipulating images array
- Inputs: From Get a product
- Outputs: Modified product data with updated images array
-
AppendImages
- Type: HTTP Request
- Role: Possibly a final API call to update product images or append images to product
- Configuration: POST or PUT request to WooCommerce or image service API
- Inputs: Processed product data from Code3
- Outputs: API response on image append success/failure
- Edge cases: API errors, invalid image URLs
-
GetCategories
- Type: HTTP Request
- Role: Retrieves WooCommerce product categories for mapping text to category ID
- Configuration: GET request to WooCommerce REST API categories endpoint
- Inputs: From UploadImage1 (triggered post image upload)
- Outputs: List of categories JSON
-
2.3 Category Resolution
-
Overview:
Converts category names or keywords extracted from Telegram posts into corresponding WooCommerce category IDs. -
Nodes Involved:
- FindCatId_From_Text (Code)
- GetCategories (HTTP Request)
-
Node Details:
-
FindCatId_From_Text
- Type: Code (JavaScript)
- Role: Parses post text, searches through categories list, and returns matching category ID
- Configuration: Custom code to match keywords with categories
- Inputs: From GetCategories
- Outputs: Category ID for product creation
- Edge cases: No matching category found; ambiguous matches
-
GetCategories
- See above in Image Handling block
-
2.4 WooCommerce Product Management
-
Overview:
Creates new WooCommerce products or updates existing ones using the processed data including text, category, and images. -
Nodes Involved:
- Create a product (WooCommerce)
- Convert to File
- Read/Write Files from Disk
- FindCatId_From_Text (Code)
- GetCategories (HTTP Request)
- Get a product (WooCommerce)
- AppendImages (HTTP Request)
- Code3 (Code)
-
Node Details:
-
Create a product
- Type: WooCommerce node
- Role: Creates new product in WooCommerce store with given attributes
- Configuration: Product data includes title, description, price, category ID, images array
- Inputs: From FindCatId_From_Text (category resolved)
- Outputs: WooCommerce API response for product creation
-
Convert to File
- Type: Convert To File
- Role: Converts product data JSON to file format for storage or further processing
- Configuration: JSON to .json file conversion
- Inputs: From Create a product
- Outputs: Binary file data
-
Read/Write Files from Disk
- Type: Read/Write File
- Role: Save converted product JSON file to local disk for record keeping or future use
- Configuration: File path and write mode
- Inputs: From Convert to File
- Outputs: Confirmation of file write
-
FindCatId_From_Text, GetCategories, Get a product, AppendImages, Code3
- See previous blocks for detailed descriptions
-
2.5 Control Flow and Logic
-
Overview:
Contains conditional nodes and code nodes that orchestrate the flow based on Telegram message content and image presence. -
Nodes Involved:
- If
- Code
- IfHasPhoto
- SetFields
-
Node Details:
- If
- Used to branch flow based on presence or absence of files or specific conditions in data
- Code
- Custom JavaScript logic to manipulate, enrich, or prepare data objects
- IfHasPhoto
- Conditional check specifically for image presence
- SetFields
- Normalizes and prepares data fields for consistent downstream usage
- If
3. Summary Table
| Node Name | Node Type | Functional Role | Input Node(s) | Output Node(s) | Sticky Note |
|---|---|---|---|---|---|
| Telegram Trigger | Telegram Trigger | Entry point, captures new Telegram posts | None | SetFields | |
| SetFields | Set | Prepares and normalizes Telegram message data | Telegram Trigger | If | |
| If | If | Branches flow based on data conditions | SetFields | Get a file1, Code | |
| Get a file1 | Telegram | Downloads Telegram file (image) | If | UploadImage | |
| UploadImage | HTTP Request | Uploads image to hosting endpoint | Get a file1 | Wait | |
| Wait | Wait | Delays flow to ensure image upload completion | UploadImage | Read/Write Files from Disk1 | |
| Read/Write Files from Disk1 | Read/Write File | Reads/writes temporary JSON data on disk | Wait | LastSavedJson | |
| LastSavedJson | Extract From File | Extracts JSON data from disk file | Read/Write Files from Disk1 | Get a product | |
| Get a product | WooCommerce | Retrieves existing product data | LastSavedJson | Code3 | |
| Code3 | Code | Updates images array in product data | Get a product | AppendImages | Notes: Push to images Arr |
| AppendImages | HTTP Request | Updates product images via API | Code3 | ||
| Get a file | Telegram | Downloads Telegram file (image) | IfHasPhoto | UploadImage1 | |
| UploadImage1 | HTTP Request | Uploads image to hosting endpoint | Get a file | GetCategories | |
| GetCategories | HTTP Request | Retrieves WooCommerce categories | UploadImage1 | FindCatId_From_Text | |
| FindCatId_From_Text | Code | Matches category text to WooCommerce category ID | GetCategories | Create a product | |
| Create a product | WooCommerce | Creates WooCommerce product | FindCatId_From_Text | Convert to File | |
| Convert to File | Convert To File | Converts JSON data to file | Create a product | Read/Write Files from Disk | |
| Read/Write Files from Disk | Read/Write File | Saves product JSON file to disk | Convert to File | ||
| IfHasPhoto | If | Checks if Telegram post contains photo | Code | Get a file | |
| Code | Code | Processes Telegram message data | If | IfHasPhoto |
4. Reproducing the Workflow from Scratch
-
Create Telegram Trigger Node
- Type: Telegram Trigger
- Configure with Telegram credentials and enable listening to new channel posts.
- No parameters needed beyond default.
-
Add Set Node (SetFields)
- Configure fields to extract and normalize important data from Telegram post such as text content, media file IDs, captions, etc.
- Connect output from Telegram Trigger to this node.
-
Add If Node (If)
- Set condition to check for presence of media file in message (e.g.,
{{$json["message"]["photo"]}}exists). - Connect output from SetFields to this node.
- Set condition to check for presence of media file in message (e.g.,
-
Add Telegram Node (Get a file1)
- Configure to download file from Telegram using file_id extracted from message.
- Connect from If node true branch.
-
Add HTTP Request Node (UploadImage)
- Configure to upload image to external image server or WooCommerce media endpoint.
- Use POST method with appropriate headers and authentication.
- Connect from Get a file1.
-
Add Wait Node
- Configure delay to handle rate limiting or ensure upload completes (e.g., wait 2-5 seconds).
- Connect from UploadImage.
-
Add Read/Write File Node (Read/Write Files from Disk1)
- Configure to write or read JSON/image metadata to/from disk for temporary storage.
- Connect from Wait.
-
Add Extract From File Node (LastSavedJson)
- Configure to extract JSON content from saved file.
- Connect from Read/Write Files from Disk1.
-
Add WooCommerce Node (Get a product)
- Configure to retrieve product by SKU or other identifier to check if product exists.
- Connect from LastSavedJson.
-
Add Code Node (Code3)
- Implement JavaScript code to append images or update product image array.
- Connect from Get a product.
-
Add HTTP Request Node (AppendImages)
- Configure to update product images via WooCommerce or image API.
- Connect from Code3.
-
Add Telegram Node (Get a file)
- Configure to download alternate or additional images if present.
- Connect from IfHasPhoto node false branch or as per logic.
-
Add HTTP Request Node (UploadImage1)
- Configure to upload alternate images similarly.
- Connect from Get a file.
-
Add HTTP Request Node (GetCategories)
- Configure GET request to WooCommerce categories endpoint with authentication.
- Connect from UploadImage1.
-
Add Code Node (FindCatId_From_Text)
- Implement code to parse Telegram post text and map to WooCommerce category IDs.
- Connect from GetCategories.
-
Add WooCommerce Node (Create a product)
- Configure to create new product with title, description, category ID, images, price, stock, etc.
- Connect from FindCatId_From_Text.
-
Add Convert To File Node (Convert to File)
- Configure to convert product JSON data to .json file for storage.
- Connect from Create a product.
-
Add Read/Write File Node (Read/Write Files from Disk)
- Configure to save product data file to disk.
- Connect from Convert to File.
-
Add supporting conditional and code nodes for data validation, error handling, and flow control to ensure robust operation.
-
Set Credentials
- Telegram credentials with bot token and permissions.
- WooCommerce credentials (API key/secret with write access).
- Any HTTP API credentials for image hosting endpoints.
5. General Notes & Resources
| Note Content | Context or Link |
|---|---|
| Workflow facilitates fully automated e-commerce product creation directly from Telegram posts. | Use case: Social media to e-commerce. |
| Ensure WooCommerce REST API credentials have write access for product and media management. | WooCommerce API documentation. |
| Telegram bot must have access to the target channel and permission to read messages and files. | Telegram Bot API documentation. |
| Image upload endpoints must support authenticated multipart/form-data POST requests. | Image hosting API docs or WooCommerce media API. |
| Rate limiting on Telegram and WooCommerce APIs may require Wait nodes to avoid failures. | n8n documentation on Wait node usage. |
Disclaimer:
The content provided is exclusively derived from an automated workflow created with n8n, adhering strictly to applicable content policies. It contains no illegal, offensive, or protected elements. All data handled is legal and publicly accessible.