Note: The latest devlog includes a video of testing the entire bot. The demo link will direct you to the bot page on my SaifURL service, which is the primary service that this bot is built upon. If you faced any problems with the link of the bot on the website, just open the Telegram app or website and go to the @saifurl_bot user, which is my bot.
Description:
It's now just a telegram bot that depends on your API key for testing. You could use this public shared API key (for testing cases only) (run /justtest on the bot to get it too):
e15ce2a23e54a4a9c24a93796feb7ad20cc334357269b0f7732ab1c526e7e9d4
However, if you want to get your own, you should go to the main site at urls.saifdev.xyz and create an account, then verify your account from the profile page, and go to the developer page and ask for your apikey
The available commands:
/start - Start the bot and register
/menu - Show main menu
/apikey - Manage your API keys
/shorturl - Manage short URLs
/urls - Alias for the shorturl command
/setdomain - Set your preferred domain
/help - Show help information
/contact - Contact information
/about - About this bot
/todo - Setup guide for new users
/justtest - Get test API key (SoM/Converge only)
/ping - Test bot responsiveness
Story behind the project:
From the beginning of the summer vacation and I wanted to learn to build bots, especially for Telegram, since I felt that would be funny and even useful for me and my built services in the future. However, there wasn't any idea or encouragement to learn to do so soon, since I am working on other projects and wanted to complete the first. Until I found the Converge YSWS program, which is at http://converge.hackclub.com. This program is a program where you submit a bot for any platform and get prizes like any YSWS program. That was like the spark that made me start this project, and I am happy now.
There are plans to create more bots for my short URL service, but I think I should complete my other projects first.
I used AI in:
I was using GitHub Copilot in VS Code. Copilot helped me with its code completion feature in saving time, and it also created the readme file for me. I was asking him if I failed in any problems, and writing commit messages, and some of the devlog descriptions. In addition, this beautiful banner
No followers yet
Once you ship this you can't edit the description of the project, but you'll be able to add more devlogs and re-ship it as you add new features!
After I created the last devlog, and thought that I had finished everything and went to make the testing video. I found a problem in updating and deleting short URLs. However, I was sure that I had tested that before, and all is working fine. After hours and hours trying to find what happened and living in the console. I was finally able to find the problem. The problem is that the database doesn't return the createdBy field in the shorturls, so reading that field to check whether the user is the owner of the shorturl by comparing their ID with the createdBy ID in the shorturls database always returns an error. How then, I was able to update and delete, I was using a super admin user in testing that made me able to edit and delete. That was a shock for me since that meant that the main website of the service wasn't working either, and I won't never recognize this problem. But thanks god, everything is working now.
I have finished the project with all of its functions and commands
That's what I have done briefly:
Automatic bot command setup: Deletes old commands and sets current command list
Update command descriptions and help text
Enhanced main menu with setup hints for users without API keys
Updated welcome message to prominently feature /todo command
Add setupBotCommands() function for automatic command management
Integrate command setup into bot initialization process
Clean up unused imports and fix linting issues
Remove duplicate command setting logic
Update systemd-compatible environment variable format
/todo - Setup guide for new users
/justtest - Get test API key (SoM/Converge only)
and more, and the project is now ready for production.
I have solved the bugs in setting the API key functions, added a check API key existence function, and a shorturls existing function in the core api to make the process of validation better. I also created the shorturls functions, getting, creating, and deleting, and I will work on completing them in the coming hours.
- Added shorturl.services.js to handle user interactions for creating, viewing, updating, and deleting short URLs.
What I have done, too:
- Integrated API utility functions for short URL operations in shorturl.js.
- Created api.utils.js for Axios instance configuration.
- Developed apikey.js to check API key existence.
- Enhanced crypto.utils.js for better encryption key validation.
- Added domain preference management for users.
In this devlog, I have completed the functionality of the API key management. Now, the users could set, update, delete, and view their API keys. I also implemented a contact command. I also created the bot page and the contact form page on the main website, mainly to manage the contact if there is any problems are found by the users in the bot, and it could be used by the main site users. I also make the /start command create a user in the database, and /apikey show an inline keyboard where each button creates a callback to handle functions. The set and update API keys function only updates the API key of the user without affecting the other information.
This time, I have understood a lot of concepts, and things have become clear. Now I have created a MongoDB database with a mongoose schema. Created the crypto functions to encrypt and decrypt. I have also understood a core concept in bot development, which is the difference between polling and webhooks. The polling is a way where the bot asks the service or platform if there is any message it should answer. This process is repeated every period of time and doesn't require a running server, only a running script. The webhook is another technique where the platform, in my case Telegram, sends the message to the bot whenever the users send it. However, that needs a running public server with an address for Telegram to send the messages to. The webhook technique is better for enterprises but harder to set up. At the end, I have set the /apikey command with set and update functions within an inline keyboard that sends a callback for running the functions, currently completing the other functions.
First time creating a Telegram bot. Most of the time is spent on choosing the best library or framework for building the website. I have tried setting up a project with NestJS, but found that things will be more complicated than I need. Since I aim to make it as simple as possible and depend on the API keys from my main service, SaifURLs, and that will avoid me from creating a complete authentication for users, just let them set the API key, and they can work as they want. My service, SaifURLs, already provides API keys for users if needed after they sign up, and then they can get the key from the developer page. Okay, after trying NestJS, I have tried ExpressJS with Telegram main API but wanted more easier tool. Until I found a library called node-telegram-bot-api, it was the simplest way to create the bot, and I am using it now.