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

nodejs-tg-bot-api

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodejs-tg-bot-api

Nodejs tools for using Telegram Bot Api with only one peer dependency (axios)

  • 0.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

🤖 nodejs-tg-bot-api

⚠️ Not all api methods are implemented now, I am adding them as they are applied on my project

Features

  • One dependency (axios)
  • Some handy services for formatting text and send buttons

Installation

npm i nodejs-tg-bot-api

Usage

import { TelegramApi, Button, Md } from "nodejs-tg-bot-api";

const api = new TelegramApi('YOUR_TELEGRAM_BOT_TOKEN');

(async function main() {
    try {
        const botInfo = await api.getMe();
        const allUpdates = await api.getUpdates();
        const lastUpdate = await api.getLastUpdate(); // same as getUpdates({ limit: 1, offset: -1 })

        if (!lastUpdate) {
            console.log('Have not updates...');
            return process.exit(1);
        }

        await api.sendMessage({
            chat_id: TelegramApi.getSenderChatId(lastUpdate),
            text: Md.lines(
                Md.bold('Bold text'),
                Md.url('https://ya.ru', 'Some text link'),
                Md.url('https://google.com'), // link without text
                Md.spacer(3), // just empty lines
                Md.spoiler('Danger spoiler'), // hidden message
            ),
        });

        await api.sendMessage({
            chat_id: TelegramApi.getSenderChatId(lastUpdate),
            text: 'Some text with buttons',
            reply_markup: {
                inline_keyboard: [
                    [ Button.withCallback('Some button with callback data', { test: 123 }) ], // Buttons row
                  ],
                keyboard: [
                    [ Button.contact('🤙🏻 Send Contact'), Button.justText('Text button'), Button.justText('2')  ], // Buttons row
                    [ Button.location('Location button') ], // Buttons row
                ]
            }
        });
        
    } catch (error) {
        console.error('Some error', error);
    }
})();

Keywords

FAQs

Package last updated on 12 Dec 2022

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