Transforming JSON Output to Payload for Slack App
I have a pipeline that outputs a json file that I would like to reformat into a payload for a Slack webhook app. It’s for an outlist and the json output list a person’s fullName with startDate and endDate and duration for the absence. The payload would have a header and footer that the data needs to be between.
{
“absenceType”: “Vacation”,
“endDate”: “Fri, 19 May”,
“startDate”: “Fri, 19 May”,
“fullName”: “Kimberly Smith”,
“duration”: 7
},
{
“absenceType”: “Vacation”,
“endDate”: “Mon, 22 May”,
“startDate”: “Tue, 23 May”,
“fullName”: “Kimberly Smith”,
“duration”: 14
},
{
“absenceType”: “Vacation”,
“endDate”: “Fri, 26 May”,
“startDate”: “Fri, 26 May”,
“fullName”: “Kimberly Smith”,
“duration”: 7
},
I want data like the above to be transformed into a payload to look like the following which includes the header and footer that I mentioned. Please note how multiple day absences have different text than single day absences and although this sample data only shows one person one persons absences, there will be multiple people:
{
“channel”: “#snl-out-list”,
“blocks”: [
{
“type”: “section”,
“text”: {
“type”: “mrkdwn”,
“text”: “Absences within the next 7 days:”
}
},
{
“type”: “section”,
“text”: {
“type”: “mrkdwn”,
“text”: “ :palm_tree: Kimberly Smith*”
}
},
{
“type”: “section”,
“fields”: [
{
“type”: “mrkdwn”,
“text”: “• Fri, 19 May:7 hours:Vacation”
}
]
},
{
“type”: “section”,
“fields”: [
{
“type”: “mrkdwn”,
“text”: “• Mon, 22 May to Tues, 23 May:14 hours*:Vacation”
}
]
}
{
“type”: “section”,
“fields”: [
{
“type”: “mrkdwn”,
“text”: “• Fri, 26 May:7 hours:Vacation”
}
]
}
],
“username”: “My Bot”
}
Hey @swright
I was able to generate the expected o/p but what to do with the first two elements, I could’ve hardcoded it but I didn’t cause I think you are getting that data dynamically from somewhere.
I’ve attached the sample pipeline with the expression in it.Test_Expression_2023_06_05.slp (5.6 KB)
I hope this helps 🙂
Cheers