micro-bot icon indicating copy to clipboard operation
micro-bot copied to clipboard

reply and replyWithMarkdown doesn't work in prod

Open ummahusla opened this issue 5 years ago • 7 comments

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:

  • now.json
{
  "version": 1
}
  • package.json(i'm using secrets to store bot token, and it worked very well yesterday)
"scripts": {
  "dev": "supervisor -x micro-bot index.js",
  "start": "micro-bot",
  "lint": "eslint .",
  "now-start": "micro-bot -d ${NOW_URL}",
  "now-deploy": "now -e BOT_TOKEN=@token_bot --public"
}
  • index.js
// 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 avatar Jun 19 '19 16:06 ummahusla

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 avatar Jun 20 '19 07:06 ummahusla

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

ummahusla avatar Jun 21 '19 12:06 ummahusla

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

junedl-nimblechapps avatar Mar 06 '20 06:03 junedl-nimblechapps

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..

BNO79 avatar Dec 02 '20 20:12 BNO79

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

ummahusla avatar Dec 03 '20 10:12 ummahusla

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 avatar Dec 03 '20 10:12 BNO79

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")

BNO79 avatar Dec 05 '20 22:12 BNO79