mast / telegram-bot-api

First Telegram Bot API node.js library
http://mast.github.io/telegram-bot-api/
MIT License
245 stars 65 forks source link

Add stop method #63

Closed 0xCA closed 4 years ago

0xCA commented 5 years ago

Once the bot is created it runs forever and there is no way to stop it. Please add this ability.

pedroaf0 commented 4 years ago

This ability is not responsibility of this library. Whereas, the native function process.exit() is able to terminate any process regardless of what is keeping it active try to use it this way:

const telegram = require('telegram-bot-api');
const api = new telegram({
        token: ''
});
api.sendPhoto({
    chat_id,
    photo: './img.jpg',
  }).then(()=>process.exit())

More information: https://stackoverflow.com/questions/5266152/how-to-exit-in-node-js

pedroaf0 commented 4 years ago

In case you don't need to receive updates. Another even simpler way is:

var api = new telegram({
        token: '',
        updates: {
            enabled: false
        }

});

The process will end after executing all the api-calls in the script

mast commented 4 years ago

Stop functionality for getUpdates and webhook will be available in 2.0 which is under development

mast commented 4 years ago

Fixed in 2.0