Table of Contents
In December last year, I realized that telegram bots are one of those bots which require a server to run. I was wondering if it is possible to run a telegram bot on the browser.
I did some research and found out that it is possible to run a telegram bot on the browser. This article will show my journey on how I made a website to run a telegram bot.
Why running in a browser? #
The main reasons are as follows:
- Users might not want to dive into how server works but want to make a telegram bot
- Users might not know how to code but want to make a telegram bot
- Users might just want a short term test for a telegram bot
Main features #
As this is just the beginning of the project, I will be focusing on a minimal subset of features.
These are the main features which I will be focusing on:
- Ability to run only on the browser tab
- Can send and receive messages from the telegram bot
- The users can edit the replies sent by the telegram bot
Delving into requirements #
Due to the predefined features, I will be making a website that does the following.
- The user can insert an API token for a telegram bot.
- The user can set a reply for a message sent by the user.
- This will in the form of a table where the user can add and delete replies.
- EG: If the user sends “Hello”, the bot will reply “Hi”
- The user can start or stop the bot.
Currently, I am still unable to decide on how to implement a good way for the user to write commands for the bot without actually writing code for the bot. If you have any suggestions, feel free to contact me and let me know.
Currently I am thinking of using Blockly where users can drag and drop blocks to program the telegram bot logic with an option to export it to code and run it on other platforms. (To be continued in another post)
Tech Stack #
For the implement of the website, I will be using the following technologies:
- Material-UI (React UI framework because I am not a UI person)
- Redux (For state management without too much cancer)
- Fetch API (For sending and receiving messages)
- Web Workers (For running the bot in the background)
The main architecture consists of 3 different parts:
- The UI for the user to control the bot.
- The Polling worker who polls the telegram bot API for messages.
- The sending worker who sends messages to the telegram bot API.
How to make a bot using the website. #
- Go to telegram
- Search for
/newbotand follow the instructions
- Copy the API key in the format
- Visit the website at https://telebot.jh123x.com/
- Paste the API key into the input box
- Set commands for the bot
- Start the bot
- PM the bot you have made, and you should be able to see the replies.
You can currently visit the website here: https://telebot.jh123x.com/
The full source code is located here
Hopefully, I will be able to make this website better in the future.