gl.telegram-bot
v1.9.9
Published
Telegram bot API for easy access on typescript/javascript
Readme
Table of Contents
Must have
Before you get start make sure you already have a telegram bot
How to create a telegram bot
- Access BotFather: Open the Telegram app and search for "@BotFather"
- Start a conversation: Click "Start" to begin interacting with BotFather.
- Create a new bot: Send the command "/newbot".
- Provide details: Enter a name for your bot and a unique username that must end with "bot".
- Receive your token: Once created, BotFather will provide you with your bot's access token, which is necessary to interact with your bot using code.
Get started
Installation
Using npm:
$ npm install gl.telegram-botCreating instance of bot
You can use this bot instance to call its bot actions
import TelegramBot from "gl.telegram-bot";
const botInstance = new TelegramBot('1234567:ASJHR24-93145uASJHF-ASDIRFJ3158');Bot Actions
sendMessage
tip: to get channel the channel id you can enter the following url on your browser
https://api.telegram.org/bot$BOT_TOKEN/getUpdates \if your token is something like this: 123456-78910
you should add bot as prefix and the ouput should be like this: bot123456-78910
This action sends a message to an individual group
// send to 1 group id
botInstance.sendMessage('test message', '-100123456789');
// send to multiple groups
botInstance.sendMessage('test message', ['-100123456789', '-100987654321']);getUpdates
@return_type - object;
It gets the recent updates on your bot
const updates = await botInstance.getUpdates();
// this is
console.log(updates);getGroupIDs
@return_type - number[];
Basically, it uses getUpdates and then get all its channel id's
const groupIDs = await botInstance.getGroupIDs();
// this is
console.log(updates);