New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@veluga/telegram

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@veluga/telegram

Library for Telegram Bot API

  • 0.3.2
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

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();

FAQs

Package last updated on 04 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc