HomeApps and SoftwareHow to create a telegram bot

How to create a telegram bot

How to create a telegram bot. One of the most popular instant messaging apps is Telegram, which is renowned for allowing users to communicate with bots individually or in groups.

Some of these bots are quite helpful, while others are made purely for amusement.

Without worrying about any code, we will learn how to create a telegram bot using these steps.

1. Install Node.js first

In order to execute the bot on our PC, we will require this (or for the ones a little bit nerdier on a Raspberry).
Let’s download it from this location then: https://nodejs.org/en/download/

2. Download the project

You can get all the material for the project needed to configure and run the code by using this download link from Github here

3. Utilize BotFather to create a BOT.

We must contact BotFather in order to get an official Telegram code, also known as an API token, in order to build a bot: https://t.me/botfather

The supreme bot is called BotFather. Use it to manage your current bots and create new bot accounts.

Simply enter the command /newbot and adhere to BotFather’s instructions:

Botfather Botfather

The entire project is available on GitHub; note that I’m not using the word “code” to avoid frightening anyone:

Disabling the bot’s privacy so that it can be used in group conversations is another crucial step that we should take right away.

Simply choose your bot and tap or click on disable after sending the command /setprivacy to Botfather.

Bot father configure

4. Set up your token.

If you haven’t already, unzip the project into a folder, rename the file.envExample to.env (see later if you’re using Windows), and update the following line to add your API token from BotFather:

TELEGRAM_TOKEN=”<YOUR_TOKEN_HERE>”

When using Windows:
If you’re having problems renaming the file, enter the start menu and type “cmd,” then choose “Command Prompt,” and follow the steps shown in the following image:
Create your responses

cmd configuration

5. Configure your answers

It’s time to get artistic now.
Let’s take a look at the file answers.json by opening it.

The structure of this “object,” which is a concatenation of the triggers and the responses to each trigger, makes it clear where all the answers are kept.

You can have a lot more responses; this is just an example with three options.

Let’s examine its structure:

[
    {
        "triggers": [
            "night",
            "good night"
        ],
        "replies": [
            {
                "reply": "To you...",
                "type": "text"
            },
            {
                "reply": "It's time",
                "type": "text"
            },
            {
                "reply": "Where are you going? The night is still young!",
                "type": "text"
            }
        ]
    },
    {
        "triggers": [
            "good morning",
            "morning"
        ],
        "replies": [
            {
                "reply": "./media/audio/sun_in_the_sky.mp3",
                "type": "audio"
            },
            {
                "reply": "./media/audio/new_dawn_new_day.mp3",
                "type": "audio"
            }
        ]
    },
    {
        "triggers": [
            "haha",
            "hahaha",
            "ahah",
            "ahahaha"
        ],
        "replies": [
            {
                "reply": "./media/images/kid_laughing_meme.jpg",
                "type": "image"
            }
        ]
    },
    {
        "triggers": [
            "party"
        ],
        "replies": [
            {
                "reply": "./media/images/party_girl.gif",
                "type": "image"
            }
        ]
    },
    {
        "triggers": [
            "hello",
            "hi"
        ],
        "replies": [
            {
                "reply": "Hi, how's it going?",
                "type": "response"
            },
            {
                "reply": "Hey! What's up?",
                "type": "response"
            }
        ]
    },
    {
        "triggers": [
            "link"
        ],
        "replies": [
            {
                "reply": "There you go: <a href=\"https://www.mignanoa.com/\">inline URL</a>",
                "type": "text"
            }
        ]
    }
]

Answer triggers are created by concatenating strings, while the response triggers are created by concatenating “sub-ojects.”
Each and every response has

which is intended to be sent as the message type: It indicates the response’s kind, which can be “text,” “audio,” “picture,” or “response.”
According to the kind, the reply should have a relevant value: if the type is music or image, the reply’s value must be a valid path to a file on your computer, even if it is strongly advised to place these types of media inside the folder “media.”

The file extensions “.jpg,” “.gif,” and “.mp3” are currently being tested for media.

Edit: Type “response” was added in October 2021; when used, the bot will quote the message it is responding to. In HTML format, hyperlinks may also be inserted.

6. Dependencies on downloads

To download all the dependencies required by the bot, use the following command into a Command Prompt (within the project folder):

npm install

Run cmd

7. Launch the bot.

Now that everything is set up, we can finally launch our bot, which means we are almost finished. Run the following commands in the same console we used to install all the dependencies:

Wegotrend
Wegotrendhttps://www.wegotrend.com
Wegotrend is the BEST website for streaming and music download, gadgets and technology reviews, movies, and shopping for amazing products. We offer a variety of services to make your songs and other advertisements popular. We have a strong team of experts and a huge monthly audience. Follow the founder
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Patoranking – After party

BNXN fka Buju – Traboski

Taylor Swift – Lavender Haze

Happy Thanksgiving Day