telegraf / micro-bot

:robot: Zero-configuration Telegram bot runner
MIT License
182 stars 29 forks source link

reply and replyWithMarkdown doesn't work in prod #23

Open ummahusla opened 5 years ago

ummahusla commented 5 years ago

I have quite an unusual bot behaviour. I have a simple bot which was scaffolded with create-bot/micro-bot. It listens for a few commands and does some API calls. It was working fine, and yesterday, but since this morning it stopped responding on the prod servers (now).

yarn dev work perfectly, everything as expected. When pushed to prod; bot doesn't respond to any reply or replyWithMarkdown. Yet I can see all console.log statements, logs in the now dashboard, database being updated, but still, no bot replies.

I'm genuinely confused, did someone came across this issue?

Some code examples:

{
  "version": 1
}
// Register "/start" command
bot.start(ctx => {
  const currentUsername = ctx.update.message.from.username;
  const chatId = ctx.update.message.chat.id;
  const formattedChatId = chatId.toString();

  let activeUsernames;

  if (currentUsername && formattedChatId) {
    // Query to target the correct document in the chats collection
    const chatInstance = db.collection("chats").doc(formattedChatId);

    // Read document data
    chatInstance
      .get()
      .then(doc => {
        if (!doc.exists) {
          // No such document with this formattedChatId
          // so we create a new chat record in db
          // and pass a currentUsername

          services.createNewChatRecord(chatInstance, currentUsername);
        } else {
          activeUsernames = doc.data().usernames;

          if (!activeUsernames.includes(currentUsername)) {
            // currentUsername is not included in the active username list
            // so we update the current record in db
            // and pass already activeUsernames list and currentUsername.

            services.updateUsernamesRecord(
              chatInstance,
              activeUsernames,
              currentUsername
            );
          }
        }
      })
      .then(() => {
        ctx.replyWithMarkdown(messages.INIT_START_COMMAND);
      })
      .catch(err => {
        ctx.replyWithMarkdown(messages.ERROR_MESSAGE);

        console.log("Error getting data", err);
      });
  }
});
ummahusla commented 5 years ago

Deployed the same bot to heroku, it has absolutely the same behaviour there. All api calls are made correctly, yet nothing in the reply.

ummahusla commented 5 years ago

I don't know what is the issue with now/heroku; yet pushing the same code to digitalocean worked 🤷‍♂

junedl-nimblechapps commented 4 years ago

Facing the same issue everything is working fine in development but when code is pushed on heroku I see webhook being called with request logs and commands are also executing (can see the logs) but doesn't see any reply in bot chat

BNO79 commented 3 years ago

I don't know what is the issue with now/heroku; yet pushing the same code to digitalocean worked 🤷‍♂

I had the same problem, after many test i saw that if you put an extra "ctx.reply('dummy')" before your real "ctx.reply" you'll see the last one printed! It's look like a bug..

ummahusla commented 3 years ago

Yeah, I gave up on this one last year tbh, it's a bug for sure.

BNO79 commented 3 years ago

Yeah, I gave up on this one last year tbh, it's a bug for sure.

Ok, have you use another module instad of "micro-bot" to bypass the problem?

BNO79 commented 3 years ago

I solve the problem removing "micro-bot" and configuring my "index.js" to use Telegraf (i've remove"Procfile" and è configure "pakage.json" with.. "start": "node index.js")