Slack blocks with automated payload

Describe the problem/error/question

I’m struggling to correctly assemble dynamic payload for blocks.
I think my code node does it well but output is considered to be 3 rows by n8n, wrapping it causes issues with calling it.
Using stringily helped me solved slack JSON issues but displayed post is incorrect.

What is the error message (if any)?

various

Please share your workflow

example output from code node that is considered 3 rows

[
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": "There are *2* events today."
    }
  },
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": ">*<https://www.google.com/calendar/eventxx|Noah AL>* \n>`Wed Mar 27 2024` - `Wed Mar 27 2024`"
    }
  },
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": ">*<https://www.google.com/calendar/eventxx|Sending FL24 agreements>* \n>`Wed Mar 27 2024` - `Wed Mar 27 2024`"
    }
  }
]

It loads correctly in the builder

Information on your n8n setup

  • n8n version: 1.33.1
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system: n8n cloud

hello @Mateusz_Bijakowski

you can do it by adding the Aggregate node to combine the Code output into one item

Or you can return the blocks as one item directly in the Code node

Yes, I was using Aggregate before, any reference for it inside of slack node fails.

eg your {{ JSON.stringify($json.blocks) }} returns Unexpected token u in JSON at position 0
what is that “blocks for btw”?

{{ JSON.stringify($json.data) }} returns Slack error response: "no_text"

{{ JSON.stringify($json.data[0]) }} works but posts to slack miss formatted message of {"type":"mrkdwn","text":"There are 8 events today."}

To add insult to injury, if I ignore Slack node and do it manually it works perfectly on the first try.

1 Like

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