0.5.5 • Published 2 years ago
@apidog/multibot-sdk-ts v0.5.5
Multibot SDK
Install
Telegram
Constructor config fields:
secret
- token from BotFather;apiUrl
- (for debug purposes only) forward traffic through proxies in countries with government blocking;
Usage example
Firstly, create instance of Telegram.Bot
:
import { Telegram } from '@apidog/multibot-sdk-ts';
// Create instance
const bot = new Telegram.Bot({
secret: '...', // secret key
});
Handle new messages
bot.on(Telegram.MatchType.Message, ({ message, from, chat }) => {
bot.sendMessage({
chat_id: chat.id,
text: `Hello, ${from.first_name}!`,
});
});
bot.startPolling();
Build and using keyboards
List of available keyboards:
ReplyKeyboard
;InlineKeyboard
;ForceReply
;RemoveKeyboard
.
// create keyboard
const kb = new Telegram.ReplyKeyboardBuilder();
// add row
const row = kb.addRow();
// add button to row
row.addButton(new Telegram.ReplyButton('Click me!'));
bot.sendMessage({
// ... rest parameters ...
// build keyboard
reply_markup: kb.build(),
});
Upload photo/video/audio/file
Using the example of sending a photo:
// 1. URL
const photo: string = 'https://telegram.org/img/t_logo.png';
// 2. File id
const photo: string = '123456789abcdefghi';
// 3. Local path
import * as fs from 'fs';
const photo: string = path.resolve('photo.jpg');
// 4. Buffer (for example, page = puppeteer.Page)
const photo: Buffer = await page.screenshot();
// 5. fs.ReadStream
import * as fs from 'fs';
import * as path from 'path';
const photo: fs.ReadStream = fs.createReadStream(path.resolve('photo.jpg'));
bot.sendPhoto({
// ... rest parameters ...
// passing one variable of the above
photo,
// you can specify the filename if you are passing Buffer
__filename: '',
});
0.5.5
2 years ago
0.5.4
3 years ago
0.5.3
3 years ago
0.5.2
3 years ago
0.5.1
3 years ago
0.4.0-experimental-2
3 years ago
0.4.0-experimental-1
3 years ago
0.5.0
3 years ago
0.3.0
3 years ago
0.2.0
3 years ago
0.1.0
3 years ago
0.1.2
3 years ago
0.1.1
3 years ago
0.0.8-6
3 years ago
0.0.8-5
3 years ago
0.0.8-4
3 years ago
0.0.8-3
4 years ago
0.0.8-2
4 years ago
0.0.8-1
4 years ago
0.0.8-0
4 years ago
0.0.7
4 years ago
0.0.5
4 years ago
0.0.6
4 years ago
0.0.4
4 years ago
0.0.4-0
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.1
4 years ago