DEV Community

dhamolahedonist
dhamolahedonist

Posted on

CHATBOT Built with Nodejs and Telegram as the user interface

This chatbot was created with Node.js and is intended to have conversations with users. Users must provide particular input in order for it to function.

Prerequisites

You will be required to have Node JS and npm before starting. Make sure you already have them installed. If not you can find them here: https://nodejs.org. Additional tools like Mongodb and Render(for deployment), were utilized. If you'd want more specific instructions on how to use these tools, please refer to their documentation.

Image description

Packages and Tools

To get started you will need to Register a Bot Account

You'll need a Telegram user account before you can create a Telegram bot. Head over to https://telegram.org/ and create an account if you don't already have one.

When you've signed in to Telegram, search for "BotFather" (a bot for managing all other Telegram bots) and start a new chat with it. Follow the steps below to register a new bot with the BotFather:

Image description

The BotFather will respond with a message containing an access token for your newly created bot. This access token will allow our application to access the Telegram API and tell our bot what to do when receiving different messages from users.

To confirm that your bot was created successfully, search for the bot's username. You should be able to see it and start a conversation with it, although it won't respond as we haven't written the bot's logic yet.

Refer to the readme file to set up the development environment https://github.com/dhamolahedonist/Jumia-Food-Telegram-Bot

The application makes use of a number of packages, including Mongoose and Telegraf. Please refer to the documentation provided with these packages for specific usage instructions.

Telegraf as a library was adopted to be able to develop our own app using javascript.refer to the documentation https://telegraf.js.org/#features

Mongoose is the preferred ORM to communicate with the database because we are using MongoDB

Folder Structure

Controller

  1. The stepsControllers.js file handles all the responses based on the user input
  2. The userControllers.js file look for the user; if none was found, a new user is created and the step the user is currently on is updated.
  3. Both the stepsControllers and the userControllers file are complied in the webhookController.js file which is now compiled in the index.js file

db.js

All user and blog data is kept in the mongdb database, which is connected to using db.js.

.env.example

environment variable offers all the configuration-related data needed.

index.js

All of the application's files are combined into one file called index.js.

Deployement on Render.

Refer to the documentation on how to deploy on ##Render
https://render.com/docs

Top comments (0)