
Learn to build a Telegram bot using Node.js, Cloudflare Workers, and the D1 SQL database to automate tasks, provide 24/7 support, and analyze data.
Obtain and copy your Telegram bot token by navigating to the basic tutorial, creating a new bot command, selecting a bot name, and saving the token for development.
Sign into Cloudflare, access the workers and pages area, choose the hello world template, name the worker Udemy worker, deploy, and view the list of workers in the Cloudflare dashboard.
Add the telegram bot token to a worker environment by configuring variables and secrets, selecting API key, and deploying the change.
Set up the Telegram bot webhook by completing the URL with the bot API token and worker URL, then paste the URL in domains and routes and press enter.
Create a Cloudflare worker to receive Telegram messages via POST, parse the JSON payload, and reply through the Telegram bot API using the chat ID and text.
Open your Telegram bot via the provided link, start the chat, and send an emoji to see the bot reply, confirming the first interaction.
Create a D1 SQL database, then bind it to your Cloudflare worker by configuring settings, bindings, and an env variable named db, and deploy to connect and persist data.
Connect your database to the worker, open storage and databases, select D1, and create a users table with id (integer primary key), first name (text), username (text), and createdat (text).
Implement a sendMessage utility in the worker to simplify Telegram messaging by building the Telegram API URL and performing a fetch with the API key and text, then deploy.
Handle the start command in a Telegram chatbot built with Node.js and Cloudflare by creating or welcoming users, storing id, name, username, and creation date, then guiding through deployment.
Test the /start command to create a Telegram user and verify the database stores the Telegram user ID, first name, username, and creation date, then welcome back the user.
Create a reasons table in the database for the Telegram chatbot project, defining columns user ID (integer), list (string), and Createdat (string), then create and verify the table.
Handle the /grateful command by checking today's record (date without time) for the user, add a reasons entry to the reasons table if none, and reply with success or failure.
Test the Telegram bot by issuing the /grateful command in the Telegram application, then verify a new entity with user id, list of things, and creation date in the database.
Add the edit command to update a Telegram bot's record for a specific date. It checks for an existing record, updates it, and reports success or failure.
Learn how to use the Telegram bot's /edit command to update a database record by date, adding items like 'job' to the list and handling missing records.
Implement the /history command by querying the database for the user's records in the last three days by default, formatting results, or returning a no-records message, then deploy.
Test the /history command in a Telegram bot built with Node.js and Cloudflare, verify date filtering by default three days and one-day scopes, ensuring correct ordering of recent entities.
Add a /commands command to display all bot commands using parse mode messages in HTML or markdown v2. Loop through them and send each one, then deploy and test.
Type the slash commands and send to view four commands (103–106), each in its own message with an italic list and code-formatted parameters, ready to click or tap.
Handle unknown commands by replying with a clear message and guiding users to slash commands to list available bot commands; deploy and verify the command list to improve user interaction.
Learn to add input validation and error handling for the /grateful command in a Telegram chatbot, including checks for the correct command and non-empty input, with user-facing feedback.
Implement input validation for the /edit command by checking command, validating date with a regex, and ensuring the reasons list is not empty, then return the correct format message early.
Validate the /history command by parsing an optional days parameter as a number, ensuring it is an integer between 0 and 31, and return error messages or history data.
Keep going after this course by building an MVP, testing ideas, and seeking feedback to gauge worth, while the instructor remains available 24/7 for questions.
Modern and beginner-friendly course that will give you a good understanding of:
Chatbot Development
Serverless Architecture
SQL
Here you will build your own chatbot using JavaScript (Nodejs) and host it for free on Cloudflare (free tier). This is an excellent opportunity to expand your knowledge of chatbots and have one running 24/7 for anyone who wants to interact with it.
We start the course by configuring the environment in Cloudflare, followed by adding commands and testing them. The steps are simple and straightforward, so you will not have to spend a lot of time trying to understand how to make things work. By the end of the course, you will have hands-on experience building a Telegram chatbot + 1 chatbot added to the arsenal of things you have built in your career.
Bots are small applications that run entirely within the Telegram app. Users interact with bots through flexible interfaces that can support any kind of task or service. There are a lot of things that bots can do, and here are a few of them:
Replace Entire Websites
Manage Your Business
Receive Payments
Create Custom Tools
Integrate with Services and Devices
Host Games
Build Social Networks
Monetize Your Service
Promote Your Project
Anything Else!