Parsing fields from steps.trigger.event.body.payload

Hey Team, I’m building a newsfeed app which retrieves a feed, pushes it to a Slack channel inside blocks containing a button with an action_id. Another workflow listens on the action_id and I want to use the content of the payload provided in the next steps of the second workflow.

How to I parse the separate fields e.g. bot_message","text?

Thanks so much :pray:

{"body":{"payload":"{\"type\":\"block_actions\",\"user\":{\"id\":\"U0611U1M58X\",\"username\":\"ktagg_00d7r000004wc1i\",\"name\":\"ktagg_00d7r000004wc1i\",\"team_id\":\"T063LSKQY2V\"},\"api_app_id\":\"A064J4G6WF3\",\"token\":\"sKM0bMYGV9z5tVdbEi3eB0L5\",\"container\":{\"type\":\"message\",\"message_ts\":\"1699169736.171759\",\"channel_id\":\"C06471ZRXM2\",\"is_ephemeral\":false},\"trigger_id\":\"6143662644693.6122903848097.f60dc849be8ee112b146f7640f1feae6\",\"team\":{\"id\":\"T063LSKQY2V\",\"domain\":\"jm-e-trading\",\"enterprise_id\":\"E053264GQRL\",\"enterprise_name\":\"Slack Demo 4196\"},\"enterprise\":{\"id\":\"E053264GQRL\",\"name\":\"Slack Demo 4196\"},\"is_enterprise_install\":false,\"channel\":{\"id\":\"C06471ZRXM2\",\"name\":\"trader-newsfeeds\"},\"message\":{\"type\":\"message\",\"subtype\":\"bot_message\",\"text\":\"Instant access to global stock markets amd finance news also including funds, crypto and more along with comprehensive sentiment analysis. Synopsys: Stands To Benefit From AI Demand (NASDAQ:SNPS) Synopsys’ Q2 results exceeded expectations, with strong growth expected in 2H of the year driven by EDA and IP. Find out why SNPS stock is a Hold. Feed Image Read <https://static.seekingalpha.com/cdn/s3/uploads/getty_images/1468266144/image_1468266144.jpg?io=getty-c-w1536https://seekingalpha.com/article/4647696-synopsys-stands-to-benefit-from-ai-demand|more> Raise Case button\",\"ts\":\"1699169736.171759\",\"bot_id\":\"B0647UEMAE8\",\"blocks\":[{\"type\":\"section\",\"block_id\":\"OZbeO\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"Instant access to global stock markets amd finance news also including funds, crypto and more along with comprehensive sentiment analysis.\",\"verbatim\":false}},{\"type\":\"section\",\"block_id\":\"rroCJ\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"Synopsys: Stands To Benefit From AI Demand (NASDAQ:SNPS)\",\"verbatim\":false}},{\"type\":\"section\",\"block_id\":\"+BeAU\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"Synopsys’ Q2 results exceeded expectations, with strong growth expected in 2H of the year driven by EDA and IP. Find out why SNPS stock is a Hold.\",\"verbatim\":false},\"accessory\":{\"type\":\"image\",\"image_url\":\"https://static.seekingalpha.com/cdn/s3/uploads/getty_images/1468266144/image_1468266144.jpg?io=getty-c-w1536\",\"alt_text\":\"Feed Image\"}},{\"type\":\"section\",\"block_id\":\"d+E6C\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"Read <https://static.seekingalpha.com/cdn/s3/uploads/getty_images/1468266144/image_1468266144.jpg?io=getty-c-w1536https://seekingalpha.com/article/4647696-synopsys-stands-to-benefit-from-ai-demand|more>\",\"verbatim\":false}},{\"type\":\"actions\",\"block_id\":\"xYugH\",\"elements\":[{\"type\":\"button\",\"action_id\":\"raise_case_0\",\"text\":{\"type\":\"plain_text\",\"text\":\"Raise Case\",\"emoji\":true},\"value\":\"click_me_123\"}]}]},\"state\":{\"values\":{}},\"response_url\":\"https://hooks.slack.com/actions/T063LSKQY2V/6169581295552/dQZknhb4wxHWDTPhyaUD68g7\",\"actions\":[{\"action_id\":\"raise_case_0\",\"block_id\":\"xYugH\",\"text\":{\"type\":\"plain_text\",\"text\":\"Raise Case\",\"emoji\":true},\"value\":\"click_me_123\",\"type\":\"button\",\"action_ts\":\"1699170033.930088\"}]}"},"client_ip":"34.239.157.217","headers":{"accept":"application/json,*/*","accept-encoding":"gzip,deflate","content-length":"4062","content-type":"application/x-www-form-urlencoded","host":"eov9l9n5w1phcfd.m.pipedream.net","user-agent":"Slackbot 1.0 (+https://api.slack.com/robots)","x-slack-request-timestamp":"1699170033","x-slack-signature":"v0=beec1a3a79c3693a0768c59dc7281118ba91e7a4c2d47944ffd66e6fcbc381af"},"method":"POST","path":"/","query":{},"url":"https://eov9l9n5w1phcfd.m.pipedream.net/"}

Hi @jbudding777,

To parse the payload and access the separate fields like “bot_message” and “text”, you can first parse the payload using JSON.parse(). Then, you can access the desired fields using the parsed object. Here’s an example:

const payload = JSON.parse(steps.trigger.event.body.payload);
const messageType = payload.message.type;
const messageText = payload.message.text;

console.log("Message Type:", messageType);
console.log("Message Text:", messageText);

This code will parse the payload and extract the “type” and “text” fields from the “message” object. You can use these variables in the next steps of your workflow.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.

I tried that but I get

“steps is not defined”

It’s working - Thanks for the guidance!