I have a issue ticket application and I want to post a message in dedicated channel when a new ticket is created. The idea is to have a basic inform message like 'new ticket' and a button leading to the ticket webpage.
But I have an issue with the slack api, I'm not able to add the button (only the text is posted). Even when I use the json of the documentation example, it doesn't work.
Note: I am able to post simple messages, no problem.
Tried to adapt the message, give an url to button in place of value
JSON:
{
"channel": "XXXXXXXXXX",
"type": "section",
"text": {
"type": "mrkdwn",
"text": "You can add a button alongside text in your message."
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Button",
"emoji": true
},
"value": "click_me_123"
}
}
The result : https://i.imgur.com/8CueU0y.png
Even the text is not handled correctly.
Your JSON does not follow the correct syntax for messages and can therefore not be displayed by Slack.
You need to include your JSON for the blocks under a property blocks
in your message definition - on the same level like channel
. Your JSON for blocks also needs to be an array.
Working example:
{
"channel": "XXXXXXXXXX",
"blocks":
[
{
"type":"section",
"text":{
"type":"mrkdwn",
"text":"You can add a button alongside text in your message."
},
"accessory":{
"type":"button",
"text":{
"type":"plain_text",
"text":"Button",
"emoji":true
},
"value":"click_me_123"
}
}
]
}
See this link for the reference documentation on "Putting blocks in messages"