I'm getting inconsistent results from Slack API when using data with an '&' in the text.
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "AT&T",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "plain_text",
"text": "AT&T"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "AT&T"
}
}
]
}
Sent in Block Kit Builder, it works great:
AT&T Header
AT&T Section
AT&T
Though, when sending the same code to update a modal, I get different results:
{
"trigger_id": "' . $payload->trigger_id . '",
"view": {
"type": "modal",
"callback_id": "ignore",
"title": {
"type": "plain_text",
"text": "Production"
},
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "AT&T",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "plain_text",
"text": "AT&T"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "AT&T"
}
}
}
]
}
}
The result on the "plain_text" items comes out encoded!
AT&T
AT&T
AT&T
AARRGGHH - even SO properly handles it and the lines all look correct, so here's a picture...
I tried changing the header to mrkdwn, but Slack doesn't like that....
{"ok":false,"error":"invalid_arguments","response_metadata":{"messages":["[ERROR] failed to match all allowed schemas [json-pointer:\/view\/blocks\/0\/text]","[ERROR] must be a valid enum value [json-pointer:\/view\/blocks\/0\/text\/type]"]}}
I've tried reformatting the text with various functions (everything I could think of from 20+ years of doing this...) and read SO answers (https://stackoverflow.com/questions/4958475/displaying-instead-amp#:~:text=If%20you%20see%20it%20as,%3A%20%26amp%3B%20). was promising, but again that talks about modifying the text from the database, which I eliminated as a possible issue by using direct text - see next)
I've checked my data (thought it was something from the database, which is why I went with just typing the letters directly, copy/paste the "text" line to make sure no hidden characters and all are exactly the same, etc....) and the flow of everything to make sure I'm not changing anything before sending (though, since the mrkdwn line prints fine, it is obvious that isn't causing anything)
Is it something simple I'm missing here or some 'slack magic' I don't know about? (obviously I'm pretty new in the Slack API, though the client is pushing to have a pretty heavy integration over the next few weeks and I'm stuck on this stupid encoding issue, so any help is greatly appreciated!)
EDIT: The ONLY thing I have heard from Slack is from 'Richard', who signed the message as "Sr. Platform Support Agent"...
Richard (Slack)
May 15, 2023, 4:04 AM PDT
Hi there,
I was able to reproduce the problem here with ampersands and views.push. I've reported this to the development team to address though I'm afraid I don't have any kind of timeline on how long that may take. I shall be sure to update you here as soon as there's any word on it. Thanks for taking the time to bring this to our attention.
Kind regards,
Richard
Sr. Platform Support Agent
From the 'nudge' yesterday, I sent an update request back to 'Richard' and today got a message from 'Declan' (these folks have no last name?, no face - - just sounds a bit toooo "we don't want you to know who we are in case we don't want to give you an answer you won't like..." :)
Declan (Slack)
Aug 2, 2023, 12:36 AM PDT
Hey Steve,
Declan here at Slack, thanks for checking in.
Sadly, we don't have an update to share on this one just yet - sorry for the delay.
Your ticket reference for this bug #4810965
If the other users on StackOverflow would like to be updated when this bug is resolved, they can create a ticket with Slack by running the /feedback command in any channel. They can reference the above ticket so we know which bug they are referring to.
Let me know if there's anything I can do in the meantime.
Kind regards, Declan