[SOLVED] Bot send to 2 times message

Hello thanks to you, I developed Stake Telegram Bot. Thank you very much. However Telegram Bot send message 2 times to the group. How can I resolve this bug. ( I use railway app )

require("dotenv").config();
const express = require("express");
const TelegramBot = require("node-telegram-bot-api");
const app = express();
const port = process.env.PORT || 3000;

const TELEGRAM_BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN;

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

app.use(express.json());

app.post("/webhook", async (req, res) => {
  const webhook = req.body;

  for (const erc20Transfer of webhook.erc20Transfers) {
    const fromAddress = `${erc20Transfer.from.slice(
      0,
      8
    )}...${erc20Transfer.from.slice(38)}`;
    const tokenItem = `${erc20Transfer.valueWithDecimals} ${erc20Transfer.tokenName}`;
    let subtitle = `NEW STAKE ALERT 🚨🚨`;
    let locktime = `🔒 Lock Time:`;
    let locktimevalue = `30 Days | Early Unstake Fee 25%`;
    let stake = `Staked Amount:`;
    let fromAdd = `Staker Address:`;
    let powered = `🤖🏛 Powered by @AIBNKCoin`;
    
    const chatId = -1001987231854;

    var replyText = subtitle.bold() + "\n" + "\n" +"💰" + " " + fromAdd.bold() + "\n" +  fromAddress + "\n" + "\n" + "💵" + " " + stake.bold() + "\n" + tokenItem + "\n" + "\n" + locktime.bold() + "\n" + locktimevalue + "\n" + "\n" + powered;

    var option = {
    "parse_mode": "HTML",
    };

    bot.sendMessage(chatId, replyText, option);
  }

  return res.status(200).json();
});

app.listen(port, () => {
  console.log(`Listening for AIBANK STAKE Transfers`);
});```

Hi @aibank

You will receive two webhooks for each block that contains the events you are interested in.

The first webhook will come as soon as the block is mined and have confirmed:false. This means that the block is still running the risk of being dropped due to a reorganization of the blockchain.

The second webhook will come once enough blocks have been mined after the block containing your events and have confirmed:true. This number of blocks is also called number of confirmations.

The table with the number of comfirmation required for Moralis to consider a block confirmed can be found here: supported-chains

Thank you sir. I fixed

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.