Telegram Bot API
Examples
Single bot
import { Bot } from '@veluga/telegram';
const bot = new Bot({ secret: '123:abc' });
bot.on('message', message => {
await bot.client.sendMessage({
chat_id: message.chat.id,
text: 'Hello, world!',
});
await bot.client.sendSticker({
chat_id: message.chat.id,
sticker_id: '123456abcdef',
});
await bot.client.sendPhoto({
chat_id: message.chat.id,
photo: 'https://example.com/photo.jpg',
photo: '/tmp/photo.jpg',
photo: fs.createReadStream('/tmp/photo.jpg'),
});
await bot.sendMessageUniversal(message, 'text', {
text: 'Hello',
});
await bot.sendMessageUniversal(message, 'photo', {
caption: 'Hello',
photo: 'https://example.com/photo.jpg',
});
});
With state manager
import { Bot, StateManager } from '@veluga/telegram';
const bot = new Bot({ secret: '123:abc' });
const stateManager = new StateManager<TState>();
interface IStateEntry {
step: 'entry';
}
interface IState
bot.use(stateManager);
bot.startPolling();