What is the best way to incorporate an if-then structure in Pipedream for bi-directional Slack to WhatsApp integration?

This topic was automatically generated from Slack. You can find the original thread here.

Hey guys, I’m new to Pipedream and trying to determine the best/proper way to do something here.

I’m trying to create a bi-directional integration from Slack to WhatsApp using ultramsg. It uses webhook for receiving WA messages and the ultramsg integration for sending WA messages. I have it working for one group/channel but am having trouble determining the proper way to integrate multiple groups. ultramsg forwards all incoming messages to a single webhook which fires a single trigger; how can I incorporate an if-then structure (or filter, custom code, etc.) in the action step so that I can send the message to different Slack channels depending on the webhook data body (i.e. who the message is from)?

Check out the filter actions here (or search for “Filter” in the step selector when adding a new step) https://pipedream.com/apps/filter#popular-filter-actions

Those let you define specific criteria for your workflow to check, and continue or end execution based on those criteria

If those aren’t quite right you can also handle some of the filtering logic in a code step

I see filter but it looks like only continue or end execution. I want to have basically a switch-case for webhook from data to decide which slack channel to send to. Do I have to write custom code or can this be achieved with filter and send_message_private_channel?

i.e. Based on trigger data, do only one of several actions. Needs to be in a single workflow because ultramsg sends everything to one webhook

Yea okay I gotcha. Sounds like a code step to handle the switch-case after the webhook trigger, and before the Slack Send Message action.

If it makes anything easier, you could also do the filtering / switch-case logic in a code step, then kick off a separate workflow to handle separate logic, if that’s necesssary

That’s a solid idea if needed but sounds like bloat to maintain each slack channel in its own workflow. I think best solution (if possible) is to have a code step that looks up the appropriate Slack channel based on the incoming webhook and then dynamically populate send_message_private_channel.Channel

is that possible?

Yep totally. Will the Slack channel name/ID be returned directly in the webhook response? Or will you have to look that up elsewhere, based on some identified coming from the webhook?

It will have to be looked up, I think a hardcoded table in the code step is sufficient for now

Sounds good. And FYI if it makes sense you can also create a Data Store to provide that lookup table.

This is great, thanks! Looking into using data stores now but I would want to associate one to one string-string records. Is data store only KV pairs and if I wanted to look up a key from a query with a value then I’d have to loop?

I don’t totally follow — can you elaborate on your question? You can store any JSON-serializable data as a value for a Data Store record, so a single record could be an array of KVs if you want, or you can structure it as many records with a single KV pair each record.