Debug Node don't show output

Hi, im trying to build a simple flow:

  • An AWS Lambda Function that just return a value
  • An input node that on trigger execute a Function Node that use AWS SDK in Js to simply invoke my function and save the message in msg.payload
  • A Debug Node that should show the message, but slimply show "UNDEFINED"

As you can see in the Function node I save the message in the msg.payload but the Debug Node don't show it, but trying to console.log it I can read the result in the console without problem? Why I'm having this problem?

[
    {
        "id": "f6f2187d.f17ca8",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "e72d8d71.b49a8",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 730,
        "y": 200,
        "wires": []
    },
    {
        "id": "7690d6ae.421348",
        "type": "inject",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "prova",
        "payloadType": "msg",
        "x": 320,
        "y": 200,
        "wires": [
            [
                "ffac1725.c59cd8"
            ]
        ]
    },
    {
        "id": "ffac1725.c59cd8",
        "type": "function",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "func": "var out;\nvar lambda = new AWS.Lambda({\n  apiVersion: '2015-03-31',\n  endpoint: 'http://172.18.0.4:4566',\n  sslEnabled: false,\n  region: 'us-east-2',\n  accessKeyId: 'test',\n  secretAccessKey: 'test'\n});\n\nvar params = {\n  FunctionName: 'FindTarga', /* required */\n};\n\nlambda.invoke(params, function(err, data) {\n  if (err) {\n      console.log(err, err.stack); \n      msg.payload=err;\n      \n  } // an error occurred\n  else     {\n      out = data.Payload.toString(\"utf-8\");\n      //console.log(out);\n      msg.payload = out;\n      console.log(msg.payload);\n  }// successful response\n});\nreturn msg;",
        "outputs": 2,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [
            {
                "var": "AWS",
                "module": "aws-sdk"
            }
        ],
        "x": 540,
        "y": 200,
        "wires": [
            [
                "e72d8d71.b49a8"
            ],
            []
        ]
    }
]

I rather suspect that some part of your function node is an async call. Therefore the function continues to the end before the async call has finished.

If so, you need to remove the return msg from the end of the function node and instead embed a node.send(msg) into the async function call.

Thanks it worked well, but now Im trying to send this payload to a Telegram Bot.
Using an Input Node with Msg payload as string, a function for handle telegram message
and telegram node works well, but trying to pass the payload of the previous function it doesn't send anything.

image

Make sure you understand what you are sending to Telegram. It only permits quite limited output. Text-only by default. Limited formatting if you chose one of the formatted output types.

I generally use an MQTT topic as a root and have a single flow that checks and outputs to my bots. Makes it easy to ensure that the formatting and settings are correct.

How did you make ensure that the formatting and settings are correct?
What Im sending is a utf-8, this should be good or not?

The function node before the Telegram output node does that. The change nodes add the correct chat id.

They change what is possible from time-to-time so this code might be slightly out-of-date now but it may give you some hints:

let contentType = msg.contentType || 'message'
let mode = msg.mode || 'MarkdownV2' //'Markdown' // 'html'
let content = ''

// Make topic into a pseudo heading (Bold, Underline)
if (msg.topic)   content += `__*${msg.topic.replace(/_/g, ' ')}*__\n`

// Allow complex payload, convert to Markdown
let sp
if (msg.payload) {
    sp = msg.payload
    
    // If payload is an array, assume an array of strings, otherwise try to turn into a string
    if (!Array.isArray(sp)) {
        // Try toString first
        try {
            sp = sp.toString()
        } catch (e) {}
        // Check if it is now `[object Object]`, if it is, try to JSON stringify it instead
        if ( sp === '[object Object]' ) {
            try {
                sp = JSON.stringify(msg.payload)
                // TODO: Maybe newline on comma and [ or { ? Maybe also make json props into bold or italic?
            } catch (e) {
                node.warn(`Cannot convert input payload to a string. ${e.message}`)
                return
            }
        }
        
        // If payload is a string, split on `<br>`
        if (typeof sp === 'string') sp = sp.split('<br>')
    }
    
    // If payload is an array, each element is a new line
    if (Array.isArray(sp)) content += sp.join('\n')
    else if (typeof sp === 'string') content += sp  // belt and braces
}

// If content contains `.` - mode must be Markdown, not MarkdownV2!
if (mode === 'MarkdownV2') {
    if ( /[.{]/.test(content) ) mode = 'Markdown'
}

msg.payload = { 
    "chatId": msg.chatId,
    "content": content,
    "type": contentType,
    "options": { 
        "parse_mode": mode,
    },
}
return msg;

/**
 * Markdown V2 Styles - https://core.telegram.org/bots/api#markdownv2-style
 * 
 * *bold \*text*
 * _italic \*text_
 * __underline__
 * ~strikethrough~
 * *bold _italic bold ~italic bold strikethrough~ __underline italic bold___ bold*
 * [inline URL](http://www.example.com/)
 * [inline mention of a user](tg://user?id=123456789)
 * `inline fixed-width code`
 * ```
 * pre-formatted fixed-width code block
 * ```
 * ```python
 * pre-formatted fixed-width code block written in the Python programming language
 * ```
 * 
 */

But I don’t understand, the string is correctly formatted in UTF8 by my function before saving it into msg.payload so what I need to do? The msg.payload should be good

Sorry, without seeing an example of the output text, I can't say what the issue might be.

Executing the function node without set up the formatting part for Telegram, the Debug Node show the string as result:
Screenshot_2

Trying to build the object to send correctly the message adding this in my Function Node

    "chatId":167585253,
    "sentMessageId":46,
    "type":"message",
    "content":out 
};

the debug node show correctly the object created for sending message to telegram node:
Screenshot_1

But telegram node doesn't send anything. If you need other proof im here, thanks for supporting me :sweat: :sweat:

P.S I'll put current flow in the next post

Here it the current flow

Alessio, please open the function node and copy it's contents and paste it into a reply.

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

1 Like

Here is the full Function. It simply call an AWS Lambda Serverless Function that return a string. I take the result from data, convert it into a UTF8 string and create the object for Telegram.

var out;
var lambda = new AWS.Lambda({
  apiVersion: '2015-03-31',
  endpoint: 'http://172.18.0.4:4566',
  sslEnabled: false,
  region: 'us-east-2',
  accessKeyId: 'test',
  secretAccessKey: 'test'
});

var params = {
  FunctionName: 'FindTarga', /* required */
};

lambda.invoke(params, function(err, data) {
  if (err) {
      console.log(err, err.stack); 
      msg.payload=err;
      
  } // an error occurred
  else     {
      out = data.Payload.toString("utf-8");
      //console.log(out);
      //msg.payload = out;
      console.log(msg.payload);
      msg.payload = {
    "chatId":167585253,
    "sentMessageId":46,
    "type":"message",
    "content":out
    
};
      node.send(msg);
  }// successful response
});

What options do you have set in the debug node?
if nothing is set in the debug side panel then I'm guessing that you debug window unchecked. and node status (32 characters) checked. you can have them both checked.

also name the debug node so you can make sure it is the one you are looking at in the debug log.

1 Like

Debug Node is good, I have checked debug window and node status. I have only this debug node currently in this workflow. Why I can see correctly the debug, but not send the message to telegram?

In the Telegram Sender node, have you tried checking the Send errors to second output box and attaching a debug node to it to see if anything shows. You could also add a catch node (targeting the Telegram Sender node) connected to a debug node too see what it will show.

Nope, no error at all. Tried in both ways you said, it show no errors
I don't know what to do :sleepy:

Try taking out the brackets

Why do you have two outputs in the function node? You are only sending one output msg.
Have you read about multiple outputs in a function node in the documentation?

1 Like

Yes.. this simply was the problem. I through that I needed one output for each node that had to recieve the message. Thanks a lot for the help

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