This n8n workflow automates URL shortening and redirect management through Telegram and MongoDB. It allows users to send long URLs via Telegram, generates short codes, verifies existing links, and provides the corresponding shortened URL. Additionally, it handles URL redirects when short links are accessed, ensuring seamless user navigation.
The workflow consists of two main parts:
1. URL Shortening:
– It triggers on Telegram messages, checking if the message is a reply with a URL.
– URLs are validated and extracted; if invalid, users receive an error message.
– For valid URLs, the workflow checks whether a short link already exists in MongoDB.
– If it does not exist, a new short code is generated, saved in MongoDB, and the user is sent the new short URL.
– If the URL exists, users are notified and prompted to provide a custom short code.
– When a user replies with a custom short code, its validity and uniqueness are verified before updating or informing about conflicts.
2. URL Redirect Handling:
– When a short URL is accessed, a webhook receives the request.
– The workflow retrieves the original URL from MongoDB based on the short code.
– If found, it redirects the user to the long URL; otherwise, it displays a 404 error page.
This system is practical for Telegram bots and web services to automatically generate and manage URL shorteners, providing quick link sharing and traffic tracking in a streamlined manner.
Reviews
There are no reviews yet.