Socket
Book a DemoInstallSign in
Socket

telegram-free

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telegram-free

Sends message by Telegram API and SMS by the free-mobile API

2.0.5
latest
npmnpm
Version published
Weekly downloads
8
Maintainers
1
Weekly downloads
 
Created
Source

Telegram - Free Mobile

This library has been developed for specific needs. It combines communication with Telegram and the free mobile API.

Configuration

  • Install the library
npm install --save telegram-free
  • Define the configuration variables
  • Using a json file (example in config.json)
let communicationApi = new TelegramFreeMobile("/home/user/config.json");
  • Using an object
let config = {
    free_mobile: [
        {
            user: 123,
            password: "xxxxx"
        }
    ],
    telegram: {
        group_id: 123456,
        bot_token: "xxxxxxxxxx"
    }
};

let communicationApi = new TelegramFreeMobile(config);

Usage

Free Mobile

Send a message

let free = communicationApi.freeMobile;
free.sendMessage("Hello World!")
    .then(()=> {
        console.log("Sent to all specified users!");
    })
    .catch((err: Error | null) => {
        console.log("Error...", err);
    });

Telegram

Send a message

let telegram = communicationApi.telegram;
telegram.sendMessage("Hello World!")
.then((message) => {
    console.log("Message sent!");
});

Send a message with a picture

let telegram = communicationApi.telegram;
telegram.sendMessageWithPicture("Hello World!", "/home/user/image.png")
.then((message) => {
    console.log("Photo sent!");
});

Launch Telegram Bot and set OnMessageListener

let telegram = communicationApi.telegram;
telegram.launchTelegramServer()
    .setOnMessageListener((message) => {
        console.log("Message received:", message);
    });

API

Class TelegramFreeMobile

TelegramFreeMobile([config])

  • config - (ConfigurationInterface or string) The configuration variables. If config is a string, then it should be the absolute path of the json configuration file (example in config.json). If config is an object, it should implements ConfigurationInterface. Default: config.json of this current directory.

telegram(): Telegram

Returns an instance of Telegram.

freeMobile(): FreeMobile

Returns an instance of FreeMobile.

configuration(): Configuration

Returns an instance of Configuration.

Class Telegram

sendMessage(content): Promise<TelegramBot.Message>

  • content - (string) Message to be sent.

sendMessageWithPicture(content, picture): Promise<TelegramBot.Message>

  • content - (string) Message to be sent.
  • picture - (string) Absolute path or public URL of the picture to be sent.

sendMessageWithVideo(content, video): Promise<TelegramBotDefinition.Message>

  • content - (string) Message to be sent.
  • video - (string) Absolute path or public URL of the video to be sent.

launchTelegramServer(): Telegram

Launches the telegram bot server. Required to use listeners.

setOnMessageListener(onMessageReceived): void

  • onMessageReceived - ((message: TelegramBot.Message) => void) Callback called each time a message is received.

bot: TelegramBot

Returns an instance of TelegramBot from node-telegram-bot-api library.

Class FreeMobile

sendMessage(content): Promise<void[]>

  • content - (string) Message to be sent.

Interface ConfigurationInterface

  • telegram - (TelegramConfigurationInterface) Telegram group configuration. The bot will listen for messages into the group specified.
  • free_mobile - (Array<FreeMobileConfigurationInterface>) Free mobile configuration. The FreeMobile class will send messages to all specified users.

Interface TelegramConfigurationInterface

  • bot_token - (string) Token of the telegram bot.
  • group_id - (number) Group ID. The bot will listen for messages into the group specified.

Interface FreeMobileConfigurationInterface

  • user - (number) Account number of the free mobile user.
  • password - (string) Token of the free mobile user.

Keywords

Telegram

FAQs

Package last updated on 08 Apr 2020

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.