I'm not a coder, so bear with me. I trying to create a flow that pulls info from an API call, checks to see if a sms message has come in in the last 5 min, and then moves it on down the flow.
I have the function working well enough, but I have tried all day to figure out how to get it to iterate through the array.
If the array entry's date does deem to be less than 5 min ago, at minimum I need payload.sms[XX].message and payload.sms[XX].contact.
I don't have a foreach function working well enough, so I won't bother sharing it.
Hard coded Index Function that works:
var Data = msg.payload.sms[0].date;
var NRtime = msg.time;
//Take Date and move to epoch
var myDate = new Date(msg.payload.sms[0].date);
var sms_time = myDate.getTime();
msg.sms_time = sms_time;
//How many minutes ago?
//2min = 120000
//5min = 300000
var Xminago = NRtime - 300000;
//check to see if sms is between times
if (sms_time > Xminago && sms_time < NRtime) {
msg.check="TRUE";
return [msg, null];
} else {
msg.check="FALSE";
var msg1 = {payload: "Time is outside these values"};
return [null, msg1];
}
Payload being fed to function:
{"status":"success",
"sms":
[{"id":"59229728",
"date":"2022-08-04 07:41:02",
"type":"1",
"did":"XXXXXXXXXX",
"contact":"XXXXXXXXXX",
"message":"8/4/2022 7:40 AM Testing continues",
"col_media1":"",
"col_media2":"",
"col_media3":"",
"media":[]
},
{"id":"59230486",
"date":"2022-08-04 08:23:15",
"type":"1",
"did":"XXXXXXXXXX",
"contact":"XXXXXXXXXX",
"message":"8/4/2022 Checking index",
"col_media1":"",
"col_media2":"",
"col_media3":"",
"media":[]
}
]
}