Skip to content

Telegram Bot API for Node.js and browsers.

License

Notifications You must be signed in to change notification settings

modern-dev/tgbotjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Bot API for Node.js and browsers.

Build Status codecov npm NPM

TgBotJs - is a Promise-based Telegram Bot API wrapper for Node.ks and browsers.

$ npm install --save @modern-dev/tgbotjs

📋 Usage

import { Bot } from '@modern-dev/tgbotjs';
import { User } from '@modern-dev/tgbotjs/types';

const token = 'your_bot_token';
const bot = new Bot(token);
const me: User = await bot.getMe();

console.log(me.firstName);

A list of all the methods is available here.

The methods with up to 3 input params have the next signature:

setChatTitle = (chatId: ChatId, title: string): Promise<boolean>
getChat = (chatId: ChatId): Promise<Chat>
getChatAdministrators = (chatId: ChatId): Promise<Array<ChatMember>>

For example:

const ok = await bot.setChatTitle('@M3MSY', 'Best memes from all over the internet.');

The methods with 4+ input params accept a single object with all the required params as key-value pairs:

getUpdates = (params: GetUpdatesParams): Promise<Array<Update>>
sendMessage = (params: SendMessageParams): Promise<Message>
sendPhoto = (params: SendPhotoParams): Promise<Message>

For example:

const params = {
  chatId: '@M3MSY',
  text: 'Welcome there!',
  disableNotification: true,
  replyToMessageId: 12345678
};
const msg = await bot.sendMessage(params);

Uploading media.

TgBotJs accepts Blob, File, ReadStream or Buffer as media upload options.

For example:

const photo = fs.createReadStream('/photos/chat_picture.jpg');
const ok = await bot.setChatPhoto('@M3MSY', photo);

📗 License

Licensed under the MIT license.

Copyright (c) 2020 Bohdan Shtepan


modern-dev.com  ·  GitHub @virtyaluk  ·  Twitter @virtyaluk

About

Telegram Bot API for Node.js and browsers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published