telegram-free v2.0.5
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 - (
ConfigurationInterfaceor string) The configuration variables. Ifconfigis a string, then it should be the absolute path of the json configuration file (example inconfig.json). Ifconfigis an object, it should implementsConfigurationInterface. Default:config.jsonof 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.
 - freemobile - (_Array\) Free mobile configuration. The 
FreeMobileclass will send messages to all specified users. 
Interface TelegramConfigurationInterface
- bottoken - (_string) Token of the telegram bot.
 - groupid - (_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.