Telegram Bot Deletes Contract Address

My workflow runs smoothly before but after a week it’s not working. However if I “test” run the bot is responding to my request.

Here’s my trigger:
Event Data: Full HTTP request
HTTP Response: Return HTTP 200 Ok

Here’s my code:

import { axios } from "@pipedream/platform";

export default defineComponent({
//This is configurable in Pipedream panel
  props: {
    telegramBotToken: {
      type: "string",
      label: "Telegram Bot Token",
      description: "Your Telegram Bot API token",
    },
    chatId: {
      type: "string",
      label: "Chat ID",
      description: "The ID of the chat to monitor for contract addresses",
    },
    adminUsername: {
      type: "string",
      label: "Admin Username",
      description: "The username of the admin to tag",
    },
  },
  async run({ steps, $ }) {
    const regex = /0x[a-fA-F0-9]{40}/g; //set of strings that matches the ETH pattern
    const message = steps.trigger.event.body?.message?.text || "";
    const contractAddresses = message.match(regex);

    if (contractAddresses && contractAddresses.length > 0) {
      const warningMessage = "⚠️Warning: Contract address detected. Please do not post any contract address. \n \n Tagging Admin(s):"; //warning messages
      const sendMessageUrl = `https://api.telegram.org/bot${this.telegramBotToken}/sendMessage`;
      const deleteMessageUrl = `https://api.telegram.org/bot${this.telegramBotToken}/deleteMessage`;

      await axios($, {
        method: "POST",
        url: sendMessageUrl,
        data: {
          chat_id: this.chatId,
          text: `${warningMessage}\n\n@${this.adminUsername}`,
        },
      });

      for (const address of contractAddresses) {
        const deleteMessageId = steps.trigger.event.body.message.message_id;

        await axios($, {
          method: "POST",
          url: deleteMessageUrl,
          data: {
            chat_id: this.chatId,
            message_id: deleteMessageId,
          },
        }).catch((error) => {
          console.error(`Failed to delete message with ID ${deleteMessageId}:`, error.response.data);
        });
      }
    }
  },
});

Hi @joseph.jumilla,

I’m sorry to hear that your workflow is not working as expected. Since you mentioned that the test run works fine, it’s possible that there might be an issue with the incoming HTTP requests or the data being sent to the workflow.

To help you debug the issue, you can add some console.log() statements in your code to log the incoming data and any other relevant information. For example, you can add the following lines at the beginning of the run method:

console.log("Trigger event:", steps.trigger.event);
console.log("Message:", message);

This will log the incoming event data and the message extracted from it. You can then check the logs in the Pipedream UI to see if there’s anything unusual or unexpected in the data.

If you’re still having trouble, please visit https://pipedream.com/support for more support options.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.