Skip to main content

Create and manage short URLs with Telegram bot, MongoDB and Nginx redirects

Workflow preview

Workflow preview
100%
Create and manage short URLs with Telegram bot, MongoDB and Nginx redirects preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

This workflow contains community nodes that are only compatible with the self hosted version of n8n. This workflow allows you to create and manage custom short URLs directly via Telegram, with all ...

Best for

  • Miscellaneous automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.telegramtrigger, n8n-nodes-base.mongodb, n8n-nodes-base.telegram, n8n-nodes-base.stickynote, n8n-nodes-base.if, n8n-nodes-base.set, n8n-nodes-base.webhook, n8n-nodes-base.code

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Rudi Afandi.

Original n8n.io source

1.1 Workflow description

Title
Create and manage short URLs with Telegram bot, MongoDB and Nginx redirects
Workflow name
Create and manage short URLs with Telegram bot, MongoDB and Nginx redirects

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

This workflow allows you to create and manage custom short URLs directly via Telegram, with all data stored in MongoDB, and redirects handled efficiently via Nginx.

How it works

This flow provides a seamless URL shortening experience:

  • Create via Telegram: Send a long URL to your bot. It will ask if you want a custom short code.

  • Store in MongoDB: All long URLs and their corresponding short codes are securely stored in your MongoDB instance.

  • Fast Redirects: When a user accesses a short URL, Nginx forwards the request to a dedicated n8n webhook, which then quickly redirects them to the original long URL.

Set up steps

This setup is straightforward, especially if you already have a running n8n instance and a VPS.

  • Difficulty: Medium (Basic n8n/VPS knowledge required)

  • Estimated Time: 15-30 minutes

  • n8n Instance & VPS: Ensure you have n8n running on your VPS (e.g., 2 core 2GB, as you have).

  • Telegram Bot: Create a new bot via @BotFather and get your Bot Token. Add this as a Telegram credential in n8n.

  • MongoDB Database: Set up a MongoDB instance (either on your VPS or a cloud service like MongoDB Atlas). Create a database and a collection (e.g., url or short_urls). Add your MongoDB credentials in n8n.

Here's MongoDB data structure JSON:

>[ {"_id": "686a11946a48b580d72d0397", "longUrl": "https://longurl.com/abcdefghijklm/", "shortUrl": "short-code"} ]

  • Domain/Subdomain: Point a domain or subdomain (e.g., s.yourdomain.com) to your VPS IP address. This will be your short URL base.

  • Nginx/Caddy Configuration: Configure your web server (Nginx or Caddy) on the VPS to proxy requests from your short URL domain to the n8n webhook for redirects. (Detailed Nginx config is provided as sticky notes in the redirect workflow)

Workflow Setup:

  • Import both provided n8n workflows (Telegram URL Shortener Creator and URL Redirect Handler).

  • Activate both workflows.

Crucial: Set an environment variable in your n8n instance (or .env file) named SHORTENER_DOMAIN with the value of your short URL domain (e.g., https://s.yourdomain.com).

Refer to sticky notes inside the workflows for detailed node configurations and expressions.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Telegram Trigger

Type / Role
n8n-nodes-base.telegramTrigger - telegramTrigger
Config choices
Version 1.2

Block 2 - Insert shortCode

Type / Role
n8n-nodes-base.mongoDb - mongoDb
Config choices
Version 1.2

Block 3 - New link

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 4 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 5 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 6 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 7 - Exist?

Type / Role
n8n-nodes-base.mongoDb - mongoDb
Config choices
Version 1.2

Block 8 - no exist?

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 9 - exist?

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 10 - Webhook

Type / Role
n8n-nodes-base.webhook - webhook
Config choices
Version 2

Block 11 - Sticky Note7

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Is it reply?

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 13 - Reply Data

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 14 - askShortCode

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 15 - Clean Data

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 16 - askShortCode1

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 17 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 18 - Valid URL

Type / Role
n8n-nodes-base.respondToWebhook - respondToWebhook
Config choices
Version 1.4

Block 19 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 20 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 21 - take URL

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 22 - Not Valid URL?

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 23 - Not Valid URL1

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 24 - take short code

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Showing the first 24 of 29 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Create and manage short URLs with Telegram bot, MongoDB and Nginx redirects
Complexity advanced
Nodes 29
Categories Miscellaneous
Author Rudi Afandi
Published 06 Jul 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/5709/5709.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Create and manage short URLs with Telegram bot, MongoDB and Nginx redirects do?

This workflow contains community nodes that are only compatible with the self hosted version of n8n. This workflow allows you to create and manage custom short URLs directly via Telegram, with all ...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Miscellaneous use case.