Getting an expression from the data

Hello everyone! I was trying to do something for improved workflow re-usability but haven’t found the appropriate way to do so.

Basically, my workflow runs various queries on a search engine which returns IP addresses. Those IPs then get processed and enriched via other services, the details don’t matter too much At the end, I send myself a notification on Slack.

Now the thing is, depending on the query, the notification should be different. Some queries look for potentially vulnerable machines, others look for attack servers, etc. But at the end, in my Slack block, I can only input one Message Text value for everything that arrives.
I tried adding a string for each IP which would be the message, but doing so it seems I can’t use expressions anymore. For instance, let’s say I want the message corresponding to one query to be the expression:

Potentially vulnerable host: `{{ $json.ip }}` (Location: {{ $json.location.country }}). pDNS: {{ $json.records.A.map(item => `\`${item.value}\``).join(", "); }}

If I store this value in $json.message (for instance) and try to use {{ $json.message }}, it will print the verbatim of my expression. I would like to do something like {{ {{ $json.message }} }} but that doesn’t seem to be valid.

Is there another way to achieve this, other than creating a workflow per query type?

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Hey @JusticeRage,

Welcome to the community :cake:

What about using $evaluateExpression(), This lets you pass in a string that we will evaluate as an expression which might do the job for you.

Thanks a lot! This is exactly what I was looking for!

1 Like

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