Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apidog/multibot-sdk-ts

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apidog/multibot-sdk-ts

Telegram and VK bot SDK for TypeScript

  • 0.4.0-experimental-1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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: '',
});

Keywords

FAQs

Package last updated on 20 Jun 2021

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