Echo Dot (3rd Gen) - Smart speaker with Alexa - Charcoal

Use your voice to play a song, artist, or genre through Amazon Music, Apple Music, Spotify, Pandora, and others. With compatible Echo devices in different rooms, you can fill your whole home with music.

Buy Now

Wireless Rechargeable Battery Powered WiFi Camera.

Wireless Rechargeable Battery Powered WiFi Camera is home security camera system lets you listen in and talk back through the built in speaker and microphone that work directly through your iPhone or Android Mic.

Buy Now

How to create a Telegram BOT step by step typing no code

0
330


Simple autoresponder to entertain your friends

Antonio Mignano
Photo by Christian Wiediger on Unsplash

Telegram is one of the most used program for instant messaging and it is known for the possibility to have bots that interact with user privately or within groups.

Some of these bots are very usefuel and some of them are just meant to be fun.

In this tutorial we are going to create our own bot without worring about any code.

We will need this in order to run the bot on our computer (or for the ones a little bit nerdier on a Raspberry).
So, let’s download it from here:
https://nodejs.org/en/download/

This is the link from GitHub where to download all the material needed to configure and run the bot: Download

The whole project (let me call it this way, I don’t want to use the word “code” to not scare anyone) is on GitHub:

In order to create a bot we need to obtain an official code from Telegram (called API token), and for that we have to contact BotFather: https://t.me/botfather

BotFather is the one bot to rule them all. Use it to create new bot accounts and manage your existing bots.

Just type the command /newbot and follow the istructions given by BotFather:

Another important step we better do now is to disable the privacy of the bot to allow it inside group chats.

Simply send the command /setprivacy to Botfather, select your bot and click/tap on disable.

If you haven’t done it yet unzip the project inside a folder then rename .envExample to .env (see later if you’re on Windows) and edit the following line, inserting your API token given by BotFather:

TELEGRAM_TOKEN=”<YOUR_TOKEN_HERE>”

If you are on Windows:
You may have trouble renaming the file, simply open the start menu and type “cmd” then open the “Command Prompt” and do as this image:

Now it’s time to be creative.
Open the file answers.json and let’s give a look at it.

Here’s where all the answers are stored, it’s easy to see the structure, a concatenation of these “objects” that contain the triggers and the replies to each of those triggers.

Of course this is just an example with 3 answers, you can have a lot more.

Let’s analyze how it is composed:

  • triggers: concatenation of strings that trigger that answer
  • replies: concatenation of a “sub-ojects”

Each one of the replies has

  • reply: which is what is meant to be sent as message
  • type: it specify the type of the reply, can be “text”, “audio” or “image”

Depending on the type, the reply should have a meaningful value: in case the type is equal to audio or image the value of reply must be a valid path to a file on your computer even if it is highly suggested to put these kind of media inside the folder “media”.

As for now the extentions tested for media are “.jpg”, “.gif” and “.mp3”.

On a Command Prompt type the following command (inside the folder of the project) in order to download all the dependecies needed by the bot:

npm install

We are almost done, now that everything is set up with can finally start our bot. In the same console we used to install all the dependencies we have to run:

npm start

And this is the result

You may notice that in the console there are some [INFO] messages, those help you keep track of who is using your bot, the same information are stored inside a file you’ll find in the project folder called debug.log.

The bot can be stopped and rerun without any problem
In case you want to run it on a headless machine, like a Raspberry, you may want to find a way to have it not interfering with other application, read my other article about Unix Screen:



Read More

LEAVE A REPLY

Please enter your comment!
Please enter your name here