First Evogram Bot
Now, we will create our first bot on Evogram. It will be as simple as possible for understanding and won't represent anything serious.
Project Setup
To get started, create a project directory in which we will develop the bot. After that, open the terminal path to the directory and install Evogram with NPM:
npm install evogram
Now, create an index.ts file, this will be the main file of the bot. In it, it is recommended to run the bot, import commands, handlers. It is not recommended to write everything in one file, but we will come to this later.
Writing the code
In the created file, write the code:
// Import the main Evogram class
import { Evogram } from 'evogram';
// Authorize the bot using the API token
const client = new Evogram("YOUR_TOKEN");
// Listening to events about new messages in the chat
client.updates.on("message", (message) => {
// Output the message to the console
console.log(message);
})
// Starting the bot with LongPoll
client.updates.polling.start();
This code launches the bot and handles the new message event. When receiving a message, it will go to the console, where we can see its contents.
Running the bot
To start the bot, enter the following command in the terminal:
npx ts-node index.ts
Here, we use ts-node for automatic building and running TypeScript. If everything went well, when you send a message to your bot in the chat, it will appear in the console.