Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/apidogru/multibot-sdk-ts
Telegram and VK bot SDK for TypeScript
https://github.com/apidogru/multibot-sdk-ts
telegram telegram-bot
Last synced: 29 days ago
JSON representation
Telegram and VK bot SDK for TypeScript
- Host: GitHub
- URL: https://github.com/apidogru/multibot-sdk-ts
- Owner: APIdogRU
- License: gpl-3.0
- Created: 2020-03-24T22:30:06.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T07:52:54.000Z (over 1 year ago)
- Last Synced: 2024-10-10T04:38:37.703Z (30 days ago)
- Topics: telegram, telegram-bot
- Language: TypeScript
- Homepage:
- Size: 1.35 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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`:
```typescript
import { Telegram } from '@apidog/multibot-sdk-ts';// Create instance
const bot = new Telegram.Bot({
secret: '...', // secret key
});
```#### Handle new messages
```typescript
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`.```typescript
// 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:
```typescript
// 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: '',
});
```