Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

reply and replyWithMarkdown doesn't work in prod #23

Open
ummahusla opened this issue Jun 19, 2019 · 7 comments
Open

reply and replyWithMarkdown doesn't work in prod #23

ummahusla opened this issue Jun 19, 2019 · 7 comments

Comments

@ummahusla
Copy link

ummahusla commented Jun 19, 2019

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
Copy link
Author

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
Copy link
Author

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

@junedl-nimblechapps
Copy link

junedl-nimblechapps commented Mar 6, 2020

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

@ummahusla ummahusla reopened this Mar 6, 2020
@BNO79
Copy link

BNO79 commented Dec 2, 2020

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
Copy link
Author

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

@BNO79
Copy link

BNO79 commented Dec 3, 2020

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
Copy link

BNO79 commented Dec 5, 2020

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants