0.3.2 • Published 9 months ago
@veluga/telegram v0.3.2
Telegram Bot API
Examples
Single bot
import { Bot } from '@veluga/telegram';
const bot = new Bot({ secret: '123:abc' });
bot.on('message', message => {
// Send message manually
await bot.client.sendMessage({
chat_id: message.chat.id,
text: 'Hello, world!',
});
// Send sticker
await bot.client.sendSticker({
chat_id: message.chat.id,
sticker_id: '123456abcdef',
});
// Send photo
await bot.client.sendPhoto({
chat_id: message.chat.id,
// by URL
photo: 'https://example.com/photo.jpg',
// by path on device
photo: '/tmp/photo.jpg',
// by stream
photo: fs.createReadStream('/tmp/photo.jpg'),
});
// Universal function for reply:
// text
await bot.sendMessageUniversal(message, 'text', {
text: 'Hello',
});
// photo
await bot.sendMessageUniversal(message, 'photo', {
caption: 'Hello',
photo: 'https://example.com/photo.jpg',
});
});
With state manager
import { Bot, StateManager } from '@veluga/telegram';
// Create bot client
const bot = new Bot({ secret: '123:abc' });
// Create state manager with possible states (TState)
const stateManager = new StateManager<TState>();
/**
*
* entry -> list -> item
* ^ |
* +-------+
*/
// Describe all possible states, all states will contain 'step' property
interface IStateEntry {
step: 'entry';
}
interface IState
bot.use(stateManager);
bot.startPolling();
0.3.2
9 months ago
0.3.0
1 year ago
0.3.1
1 year ago
0.2.1
1 year ago
0.2.0
1 year ago
0.1.1-alpha.0
1 year ago
0.1.2
1 year ago
0.0.0-alpha.1
3 years ago
0.0.0-alpha.2
3 years ago
0.0.0-alpha.0
3 years ago