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

bot-tg

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bot-tg

A bot for Telegram Bot's API

  • 1.0.21
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

A package for Telegram's bot API

Table of contents

  • Examples
  • Guides
  • New

Examples

Here is an example to use this package:

const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
	token: '<YOUR_BOT_TOKEN_HERE>',
	commands: [{
		id: 'hello',
		description: 'click here!',
		call: function(userId) {
			this.sendMessage(userId, 'World!');
		}
	}]
});

To get any kind of information from user you should do like that:

const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
    token: '<YOUR_BOT_TOKEN_HERE>',
    commands: [{
        id: 'set',
        description: 'set something',
        title: 'Send me something:',        
        done: function(userId, result) {
            this.sendMessage(userId, `Result is: ${result}`);
        }
    }]
});

To make a command hidden when calling the help (or start) command:

const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
    token: '<YOUR_BOT_TOKEN_HERE>',
    commands: [{
        id: 'set',
        description: 'set something',
        title: 'Send me something:',        
        done: function(userId, result) {
            this.sendMessage(userId, `Result is: ${result}`);
        }
    }, {
        id: 'action',
        description: 'admin action',
        call: function(userId) {
            this.sendMessage(userId, 'Hello, admin!');
        }
    }]
});

Guides

To make some command hidden from list when calling the help (or start) command use hidden: true property:

const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
    token: '<YOUR_BOT_TOKEN_HERE>',
    commands: [{
        id: 'set',
        description: 'set something',
        title: 'Send me something:',        
        done: function(userId, result) {
            this.sendMessage(userId, `Result is: ${result}`);
        }
    }, {
        id: 'action',
        description: 'admin action',
        hidden: true,
        call: function(userId) {
            this.sendMessage(userId, 'Hello, admin!');
        }
    }]
});

To enable logging use:

const bot = new TelegramBot({
    token: '<YOUR_BOT_TOKEN_HERE>',
    logging: true
    ...
});

New

  • When there are no matches with commands list identified at bot's initialization, bot's instance emits a message:
const TelegramBot = require("bot-tg");
const bot = new TelegramBot({
    token: '<YOUR_BOT_TOKEN_HERE>',
    commands: [{
        id: 'set',
        description: 'set something',
        title: 'Send me something:',        
        done: function(userId, result) {
            this.sendMessage(userId, `Result is: ${result}`);
        }
    }]
});

bot.on('message', update => {
    console.log(update);
});

Keywords

FAQs

Package last updated on 24 May 2019

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