Hello,
i am trying to send block kit response in slack by using custom variables generated by AI.
This is the flow :
This is the Block Kit Builder JSON Code :
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":inbox_tray: New message"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
// Response from gemini Agent
"text": "{{18.result}}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Open on Gmail."
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Click Me",
"emoji": true
},
"value": "click_me_123",
// Email Link
"url": "{{1.messageLink}}",
"action_id": "button-action"
}
}
]
}
The error :
1 Like
If I had to guess, you’re getting this error because {{18.result}} or {{1.messageLink}} is an empty string or has quotation marks in it. JSON can be sensitive and sometimes including an empty string, null, or a text string that has “” in it can throw errors.
1 Like
No that’s the make mapping variables. But how can i remove thoses errors coming from ‘’‘’ ? Please
This part is likely the error.
Most of the time, you cannot directly map variables containing text content into another JSON string without escaping them, as the variable might contain characters that have a special meaning in JSON.
Special characters in strings needs to be specified (escaped) as a “literal” character (instead of a special metacharacter), otherwise they make the whole JSON invalid when you map the variable value when creating another JSON string.
You can escape string variables by passing the text into the JSON “Transform to JSON” module —
Transforms any object to JSON.
Then, you can map the output of the “Transform to JSON” module into your JSON string. (Do note that when using the “Transform to JSON” module, the output should already contain the double quotes " "
around your text, so when you map this output into your JSON, you should not need to wrap another pair of double quotes around it.)
Alternatively, you can use the built-in function replace
to replace those special characters with their escaped versions, as discussed here.
For more information on escaping JSON strings, see: Understanding JSON Escape: A Comprehensive Guide
Hope this helps! Let me know if there are any further questions or issues.
— @samliew
2 Likes