I've got a simple auto reply that I activate while on my motorcycle, but I'd like to take it a step further. I'd like to have it so that if the same person texts me multiple times, it will only auto reply to them once every 5 minutes. I would've sworn I saw that functionality built in somewhere, but I cannot find it if it does exist. I think it would be possible to do this from scratch somehow, but the catch would be what if two (or more) different people texts me all within that same 5 minute window, I'd obviously want each of them to get that initial auto reply.
Is this built in somewhere, or is there a simple elegant solution I'm missing?
SMS auto reply limit by timeframe?
Moderator: Martin
Re: SMS auto reply limit by timeframe?
Hi,
There's no built-in function that directly solves this problem.
You would have to build a flow that uses a global map to store the last time you have sent an SMS to a particular number. (see the help text of Script functions newMap(), newDate()).
Let me know if you have worked with scripts before otherwise I can try to build an example flow when time permits.
Regards,
Martin
There's no built-in function that directly solves this problem.
You would have to build a flow that uses a global map to store the last time you have sent an SMS to a particular number. (see the help text of Script functions newMap(), newDate()).
Let me know if you have worked with scripts before otherwise I can try to build an example flow when time permits.
Regards,
Martin
Re: SMS auto reply limit by timeframe?
I've made several scripts before, but simplistic in nature. I've definitely never used the map function. I just looked over it, and I not very sure how I would apply that to keeping record of when I send my first autoreply.
Re: SMS auto reply limit by timeframe?
This flow template should achieve what you are looking for: SMS auto reply limit by timeframe. The flow will be imported into group __test.
The first two actions are only used to simulate a received SMS so you don't have to send SMS to yourself.
The important script is executed in condition Expression. The condition uses a global map to check when the flow sent the last SMS to a particular sender. The map uses the SMS sender as the key and stores the time of the last sent SMS as the value (time is the number of milliseconds since 1970):
The condition Expression is true when the last statement of the script evaluates to true, so you can send the SMS in the action on the true-branch of the condition.
An additional action Script is executed after the SMS has been sent to remember the current time in the global map:
It would also be possible to integrate this second script directly into the condition Expression but I think it's easier to understand the flow with two separate scripts.
Regards,
Martin
The first two actions are only used to simulate a received SMS so you don't have to send SMS to yourself.
The important script is executed in condition Expression. The condition uses a global map to check when the flow sent the last SMS to a particular sender. The map uses the SMS sender as the key and stores the time of the last sent SMS as the value (time is the number of milliseconds since 1970):
Code: Select all
// check if the map already exists, create when missing
if (global_recent_sms_map==null)
{
global_recent_sms_map=newMap();
}
// look up when the last SMS was sent to the sms_sender
// use 0 when no SMS has been sent at all when the sender is not in the map yet (0 represents 1/1/1970)
last_time = getMapValue(global_recent_sms_map, sms_sender, 0);
// check if the last SMS was sent more than 20 seconds ago (could be changed to 5*60*1000 for 5 minutes)
last_time < getDate()-20*1000;
An additional action Script is executed after the SMS has been sent to remember the current time in the global map:
Code: Select all
addMapEntry(global_recent_sms_map, sms_sender, getDate())
Regards,
Martin
Re: SMS auto reply limit by timeframe?
Honestly, I appreciate the walkthrough explanation more than the actual flow itself! I had an idea of how I could achieve this, but your solution is so much simpler and more elegant.
Thank you so much!
Thank you so much!