This topic was automatically generated from Slack. You can find the original thread here.
how do i fix this issue TypeError
Cannot read properties of undefined (reading ‘message’) DETAILS
at Object.run (file:///tmp/__pdg__/dist/code/6a231fc9b9ecb7988e1acb52e2d2f3be8e1c5b3a459cebbd4dd462aa4c608d4c/component.mjs:6:46)
at null.executeComponent (/var/task/launch_worker.js:267:53)
at MessagePort.messageHandler (/var/task/launch_worker.js:764:28)
It looks like you’re encountering a TypeError because you’re trying to access a property (message) on an undefined object. This typically happens when you expect a variable to be an object with certain properties, but the variable is actually undefined. To fix this issue, you’ll need to ensure that the object you’re trying to access is properly defined and not undefined. Here’s a general approach to debugging this issue: 1. Check where the variable that’s causing the error is defined. Make sure that you’re assigning it correctly and that it’s in the proper scope. 2. If the variable is supposed to be set based on some input or a previous step in your Pipedream workflow, verify that the input or step is providing the expected data. 3. Add checks before accessing properties to ensure the object isn’t undefined. For example: if (myVariable && myVariable.message) { // Now you can safely use myVariable.message } 4. Add logging statements to inspect the value of the variable at different points in your code to see where it might be going wrong. If you can provide more context or code around where the message property is being accessed, I can give you more specific guidance.
@U05A7KLNALC This is what my Node.js what could i be missing im still getting TypeError
Cannot read properties of undefined (reading ‘message’) import { axios } from “@pipedream/platform”;
**if** (command === "/start") {
_// Send the first message_
**await** axios($, {
method: "POST",
url: "[https://api.telegram.org/hidden token#/sendMessage](https://api.telegram.org/hidden%20token#/sendMessage)",
data: {
chat_id: steps.trigger.event.body.message.chat.id,
text: "Welcome, Here you can find our menu, social media links and create new orders for shipping or local delivery services. Please click on the bottom left (=MENU) option to view all commands. After viewing our menu send us a message with your order! Diamond Boys Law:gem:",
},
});
} **else** **if** (command === "/link") {
_// Send the second message_
**await** axios($, {
method: "POST",
url: "[https://api.telegram.org/hidden token#/sendMessage](https://api.telegram.org/hidden%20token#/sendMessage)",
data: {
chat_id: steps.trigger.event.body.message.chat.id,
text: ":three_button_mouse: Instagram https://www.instagram.com/ccmspot?igsh=YzNpMWlnaW45djQ3c :ghost: Snapchat https://t.snapchat.com/zW6pCdm2 Follow us on all social media platforms to stay up to date with all new drops!",
},
});
}
It seems like you’re encountering a TypeError because the message property is undefined. This typically happens when the path you’re using to access the message object is incorrect, or the expected data isn’t being passed to the trigger. To help you further, I need to understand more about the structure of the event data that’s triggering this workflow. Could you please provide the payload structure of the incoming event to the trigger? Specifically, I need to know how the message object is structured within the body of the event. In the meantime, here’s a general tip: you can log the entire steps.trigger.event object to inspect its structure. Add a line like console.log(JSON.stringify(steps.trigger.event, null, 2)) at the beginning of your run method to print the structure to the logs. This can help you verify that you’re accessing the message property correctly.
it seems like you are combining logic of 2 commands into one step, which really complicated the problem.
To simplify your problem, I would recommend you to create 2 telegram new command triggers along with 2 separate workflows, then you can freely define steps for them separately
that makes complete sense and i tried it but since telegram only allows you to use 1 workflow per telegram bot i wasn’t able to do it that way… sorry im new to all of this.
Then you can create 2 workflows that use the same Telegram trigger. On each workflow, add the Filter action to stop the workflow if the command is not your desired command. Then go ahead and define other steps for your command