SMS auto reply limit by timeframe?

Post your questions and help other users.

Moderator: Martin

Post Reply
Ghlave
Posts: 28
Joined: 06 Aug 2013 18:06

SMS auto reply limit by timeframe?

Post by Ghlave » 10 Aug 2014 20:41

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?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: SMS auto reply limit by timeframe?

Post by Martin » 12 Aug 2014 16:09

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

Ghlave
Posts: 28
Joined: 06 Aug 2013 18:06

Re: SMS auto reply limit by timeframe?

Post by Ghlave » 12 Aug 2014 17:05

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.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: SMS auto reply limit by timeframe?

Post by Martin » 13 Aug 2014 17:02

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):

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;
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:

Code: Select all

addMapEntry(global_recent_sms_map, sms_sender, getDate())
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

Ghlave
Posts: 28
Joined: 06 Aug 2013 18:06

Re: SMS auto reply limit by timeframe?

Post by Ghlave » 15 Aug 2014 01:50

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!

Post Reply