How to build a logic in which I can send only 1000 sms per day and the limit reset in 24 hrs

267 Views Asked by At

I implemented MessageBird WhatsApp Integration. but my problem is how to build a logic where I can calculate the remaining sms limit and reset it after 24hrs.

  1. total limit is 1000 per day in 24 hrs

  2. if I send 500 sms at 2 pm and the remaining 500 at 5 pm, so next day at 2 pm I will get 500 limits and the remaining 500 at 5pm.

can someone help me to build this logic so that the API can send the accurate remaing limit for sending sms for that time period.

1

There are 1 best solutions below

2
On

It's really hard to answer to your question without further details about your project's architecture.

Assuming you have means to persist and query your data, you could simply store an entity for each message sent by a user along with a created_at timestamp, eg.:

+-----+------------+---------+
| id  | created_at | user_id |
+-----+------------+---------+
|   1 |        ... |      25 |
|   2 |        ... |      25 |
+-----+------------+---------+

Then you could easily query this data and verify the 1000 message limit against the total count of records found for the given user_id and created_at >= now() - 24h