Skip to main content

Introduction

What are bots?

A Telegram bot is a special user account automated by a program that does not have a phone number / password, but has an authorization token, and which has some functionality that is not available to ordinary users, such as text and inline keyboards, HTML markup, sending invoices, etc. Also, bots have tighter limits how often they send messages, the size of uploaded files, and more.

If you already know how to create bots, skip to the Getting Started section!

How Telegram Bots API works

Before you begin creating your bot, make yourself familiar with what Telegram bots can and cannot do. Check out the official Introduction for Developers by Telegram

Bots interact with Telegram via HTTP requests. Every time your bot sends or receives messages, HTTP requests go back and forth between the Telegram servers and your server / computer.

Here is a (simplified) diagram of how the setup will look in the end when Alice contacts your bot:

What Opengram does for You

At its core, Opengram implements all of this communication for you, so you can simply type sendMessage in your code and a message will be sent. In addition, there are a variety of other helpful things to make it simpler to create your bot.

Before you begin...

Alright, making a bot is cool and all, but there are some prerequisites to it. To create a bot with Opengram, you should have a fairly decent grasp of JavaScript itself. While you can make a bot with very little JavaScript and programming knowledge, trying to do so without understanding the language first will only hinder you. You may get stuck on many uncomplicated issues, struggle with solutions to incredibly easy problems, and all-in-all end up frustrated. Sounds pretty annoying.

If you don't know JavaScript but would like to learn about it, here are a few links to help get you started:

Take your pick, learn some JavaScript, and once you feel like you're confident enough to make a bot, come back and get started!

Prerequisites for Node.js

In order to run the bot.js file, you have to have Node.js installed.

In summary, this is what you have to do for Node.js:

  • Create a source file bot.js, e.g. using your favorite IDE or code editor
  • Run bot.js using Node.js from your terminal.

Every time you modify your code in bot.js, you need to restart the Node.js process. Hit Ctrl+C in your terminal to stop the process. This will stop your bot. Then, you need to repeat last step

Did you know...

You can start bot with utils like nodemon, that restarts your bot automatic when code changed, it's very usable in development