【问题标题】:Send message using telegram bot with Node.js使用带有 Node.js 的电报机器人发送消息
【发布时间】:2016-06-18 01:51:25
【问题描述】:

我正在执行一项服务,以警告我服务器上可能发生的错误,我的疑问是,在我在完成执行时发送消息之后,或者它呈现低于正常图像的方式?为了完成任务,我必须使用 ctrl + c

代码:

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]);

在cmd中我执行这段代码

node.exe bot.js 'text send'

this is image

【问题讨论】:

  • 这个错误表明你的机器人有网络钩子,它在端口 443 上没有响应。你是否配置了网络钩子选项?

标签: node.js


【解决方案1】:

似乎发生了一些错误但未捕获:

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);
        });
    }
}

【讨论】:

    猜你喜欢
    • 2017-03-19
    • 2020-12-15
    • 2017-09-01
    • 2016-10-18
    • 2023-03-22
    • 2021-01-29
    • 2016-03-11
    • 1970-01-01
    • 2019-12-31
    相关资源
    最近更新 更多