This topic was automatically generated from Slack. You can find the original thread here.
Hey, I am working on something but kinda stuck. Here’s what I’m trying to do:
I have 2 flows, a “fetching” flow and a “processing” flow.
FETCHING FLOW
• the fetching flow creates a REST API Get call and it can return anything between 1 and n results.
• the next step is a node.js bit that gets all these results and processes them. sending them all 1 by 1 to a url. That URL is basically an endpoint of my next workflow.
PROCESSING FLOW
• this next flow begins when it’s called by the previous one.
• this just received the HTTP Request and is meant to get all the results to pass along.
• I am then using a whatsapp template to send a text using a template
• I configure everything just fine except I need to also enter my “Recipient Phone Number” which would come from my previous step but instead of taking each result as I was aiming for it’s just taking the last one so the rest although they are received, are unused.
So, my question is what am I missing to get it to work through the entire received list?
Hi, I think your question is a great case for Pipedream bot to help. I’ll pass your question to the Pipedream bot now. Please feel free to ask it any question
Hey, I am working on something but kinda stuck. Here’s what I’m trying to do:
I have 2 flows, a “fetching” flow and a “processing” flow.
FETCHING FLOW
• the fetching flow creates a REST API Get call and it can return anything between 1 and n results.
• the next step is a node.js bit that gets all these results and processes them. sending them all 1 by 1 to a url. That URL is basically an endpoint of my next workflow.
PROCESSING FLOW
• this next flow begins when it’s called by the previous one.
• this just received the HTTP Request and is meant to get all the results to pass along.
• I am then using a whatsapp template to send a text using a template
• I configure everything just fine except I need to also enter my “Recipient Phone Number” which would come from my previous step but instead of taking each result as I was aiming for it’s just taking the last one so the rest although they are received, are unused.
So, my question is what am I missing to get it to work through the entire received list?
It seems like you need to iterate through the results in your processing flow and send the WhatsApp message for each recipient phone number. You can achieve this by using a loop in your processing flow’s code step. Here’s an example of how you can modify your processing flow: ```
// Assuming the results are received as an array of objects with a phoneNumber property const results = steps.trigger.event.results; for (const result of results) { const recipientPhoneNumber = result.phoneNumber; // Use the recipientPhoneNumber to send the WhatsApp message using the template // Add your WhatsApp template sending code here, using recipientPhoneNumber }
Yes, you’re correct. In order to iterate through the results and send a WhatsApp message for each recipient phone number, you’ll need to use the actual code instead of the WhatsApp template. You can use the Twilio API for sending WhatsApp messages. Here’s an example of how you can modify your processing flow to achieve this: First, add the Twilio package import at the top of your code: import { axios } from "@pipedream/platform"; import twilio from "twilio"; Then, in your processing flow, you can use the Twilio API to send WhatsApp messages: ```
// Assuming the results are received as an array of objects with a phoneNumber property const results = steps.trigger.event.results; // Initialize the Twilio client with your account SID and auth token const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN); for (const result of results) { const recipientPhoneNumber = result.phoneNumber; // Use the recipientPhoneNumber to send the WhatsApp message using the Twilio API await client.messages.create({ body: “Your message text here”, // Replace with your message text from: “whatsapp:+1234567890”, // Replace with your Twilio WhatsApp number to: whatsapp:${recipientPhoneNumber}, }); }