【问题标题】:Telegram Bot - JS - Bot stops working after a whileTelegram Bot - JS - Bot 在一段时间后停止工作
【发布时间】:2021-03-26 08:56:13
【问题描述】:

开发者!我使用 JS 语言为 Telegram 创建了一个简单的机器人,在输入“/教程”时会加载一个 txt 列表。

我将此机器人部署到 Heroku 以便它上线。

问题是机器人工作了一段时间然后停止工作,我不知道为什么。

有人遇到过这个问题吗?

//Correction message error on console
process.env.NTBA_FIX_319 = 1;

var express = require('express');

var app = express();

app.set('port', (process.env.PORT || 5000));

const TelegramBot = require('node-telegram-bot-api')

const TOKEN = 'myToken'

const bot = new TelegramBot(TOKEN, { polling: true })

bot.on('message', (msg) => {

  const chatId = msg.chat.id;
  const text = msg.text;

  //read list txt
  var fs = require('fs');
  try {
    var data = fs.readFileSync('lista.txt', 'utf8');
  } catch (e) {
    console.log('Error:', e.stack);
  }

  //send message

  if (text.includes('/tutoriais')) {
    bot.sendMessage(chatId, `Olá, ${msg.chat.first_name}! ????\nLista de Tutoriais`)
    bot.sendMessage(chatId, data);
  }
});

【问题讨论】:

    标签: node.js heroku telegram telegram-bot


    【解决方案1】:

    我在 python 文件中添加了一个 webhook,它最终工作正常

    https://github.com/victoraugusto6/bot-Telegram-JS-Heroku

    【讨论】:

      猜你喜欢
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      • 1970-01-01
      • 2017-05-13
      • 2018-03-17
      相关资源
      最近更新 更多