简体   繁体   中英

Send message using telegram bot with Node.js

I'm doing a service to warn me of possible errors that can occur on my server , my doubt is , after I send a message as I finalize the execution or the way it is presenting the image below normal? For to complete the task I have to take a ctrl + c

code:

var util = require('util');

var TelegramBot = require('node-telegram-bot-api');

var token = '237907874:AAG8hK1lPWi1WRlqQT2';

var bot = new TelegramBot(token, {polling: true});

var millisecondsToWait = 5000;

robot = {
    "alert": function teste(message) {
        var toId = '-103822200';
        var resp = util.format('alerta: %s', message);
        bot.sendMessage(toId, resp);
    }
}

robot.alert(process.argv[2]);

in cmd i execute this code

node.exe bot.js 'text send'

this is image

Looks like some error occurs but not captured:

var robot = { // Don't forget about var :)
    "alert": function teste(message) {
        var toId = '-103822200';
        var resp = util.format('alerta: %s', message);
        bot.sendMessage(toId, resp)
        .catch(function(error){ // Catch possible error
            console.error(error);
        });
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM