You will not forget to take your Medicines anymore: A Daily Call Reminder

Shubham Sood
The Startup
Published in
6 min readJun 4, 2020

--

Photo by National Cancer Institute on Unsplash

In today’s hectic lifestyle, people generally tend to forget when to take their medicines. So I made a Medicine Reminder that reminds you to take your Medication via Voice Call Message.

In this article, I will guide you to make a reminder that will call you automatically to take your medicine at your preferable time.

So for receiving a call on your mobile number, we will use the Twilio Python Package, and for scheduling calls, as a reminder, we will use APScheduler. For automating the calling process, we will put our code on the Heroku Cloud Platform.

The flow of the process is:

· Setting up Twilio

· Python Script for receiving a call from Twilio

· Scheduling our Python code

· Putting our code on Heroku for automation

Setting up Twilio

Create a free account on twilio.com by confirming your email address and phone number.

After signing-in to your Twilio account, create a project with your preferable name.

Now, you have to take a mobile number from Twilio so that you can receive the reminder call from that number. Steps to get the phone number from Twilio:-

  1. Go on All Products & Services on the upper-left corner of Twilio homepage.

2. Then click on the Phone Numbers tab.

3. After that, click on Get your first Twilio phone number so that you can get a phone number from which you will receive a call. You will get the phone number for free.

Now go to Twilio Console and get your ACCOUNT SID and AUTH TOKEN that you need in the coding process.

And also, add your phone number on Twilio on which you want to receive the reminder call. For that again, go on the Phone Numbers tab and click on Verified Caller IDs to add the recipient’s phone number.

The Python Script for receiving a call from Twilio

You check out my Github repository of this project here.

First of all, create a Project directory and add the following file named as script.py ,schedule.py , requirements.txt and a Procfile(without a file extension) into Project directory. I will tell you the use of each file and what it contains as we move further.

For receiving a call from Twilio, you have to do the following -:

  1. Install the Twilio dependency on your machine by writing pip install twilio in the command prompt.
  2. Now go to Twilio Console, get your account_sid and auth_token so that Twilio can verify you.
  3. Then you have to write the following code in script.py for receiving the call from Twilio:-
from twilio.rest import Clientaccount_sid = 'AC68dd6fb818a70751f9f8a5af3'   #Replace with your account_sid'auth_token = '0d9c4274fea8fc95aXXXXXXXX'    #Replace with your auth_token'client = Client(account_sid, auth_token)def callmsg():    
call = client.calls.create(
from_='+17146604658', #Replace with the phone number that you got from Twilio
twiml='<Response><Say>Reminder to take your Pill at 7:17 P.M.</Say></Response>',
to='+918285XXXXXX' #Phone number that you add on Twilio
)
print(call.sid)

Before moving on the further run script.py to see that if you are getting a call from Twilio with the response that you have provided.

Scheduling our Python code

Now we will need Python’s library — Advanced Python Scheduler (APScheduler) that lets you schedule your Python code to be executed at your preferable time. Do the following steps for scheduling the calling process-:

  1. Install the APScheduler dependency on your machine by writing pip install apscheduler in the command prompt.
  2. Then you have to write the following code in schedule.py for scheduling the call:-
from datetime import datetime
import pytz
from apscheduler.schedulers.blocking import BlockingScheduler#importing the callmsg function from script.py that you have madefrom script import callmsgist = pytz.timezone('Asia/Kolkata')sched = BlockingScheduler()# Schedule the python script to be called everyday from monday to friday at 7:17 P.M. You change the time as per your need.sched.add_job(callmsg, 'cron', day_of_week='mon-fri', hour=19, minute=17, timezone=ist)sched.start()

Before moving on to the automation process run the schedule.py to confirm that you are getting the call at the scheduled time you have entered in schedule.py

Putting our code on Heroku for automation

Now we are ready with getting a call through Twilio and scheduling it with APScheduler, but we have to make it an automated process so that we did not need to run the python script again and again. For automating the call processing, we will use the Heroku platform.

Heroku is a Cloud Application Platform service that enables developers to build, run, and operate applications entirely in the cloud.

Create a Heroku’s free developer account.

After logging-in to the Heroku dashboard, Click on NewCreate a new app and give a name to your application. Here I gave a callreminder name to my Heroku Application.

You require Heroku CLI (Command Line Interface) from which you can create and manage your Heroku apps directly from the command terminal. And Heroku CLI requires Git, the popular version control system. If you don’t already have Git installed, complete the following before installing the CLI:

After you set up Git, you have to download and install Heroku CLI

Now, for server-side implementation, we need to do two things-:

  1. To list the external dependencies, in our case, we have two dependencies Twilio and APScheduler. You have to write the current version of Twilio and APScheduler that you installed in requirements.txt
twilio==6.41.0
APScheduler==3.6.3

2. We need a Procfile. A Procfile is a file that will tell the Heroku to run this project according to a specific schedule. Write the following line of code in Procfile

clock: python schedule.py

Now we just left with deploying our project on Heroku. For that, open your command prompt and go to your Project directory destination and then follow the following steps:-

  • If you haven’t already, log in to your Heroku account and follow the prompts to create a new SSH public key.
>>    heroku login
  • Initialize a Git repository
>>    git init
>> heroku git:remote -a callreminder
  • Deploy your application
>>    git add .
>> git commit -am “make it better”
>> git push heroku master

The final step is to make your Medicine Reminder run at just one time, and it reminds you daily by calling. For that, go to the Resources tab at your Heroku’s App Page there, you can see Free Dynos.

Under Free Dynos, you can see clock python schedule.py make it run by edit tab and switch the slider ON and Confirm the clock.

That’s it. If you have done everything right, then you can get the Reminder Call to take your pills at your number as per your schedule without even running the code frequently.

You can notice that I got a call from Twilio Number at 7:17 P.M.

If you don’t want to get Reminder Call anymore, you can go to Resources → Free Dynos and can see clock python schedule.py and switch the slider OFF and Confirm to stop.

--

--

Shubham Sood
The Startup

A Computer Science student with an interest in Machine Learning. My Linkedin profile: https://www.linkedin.com/in/shubhamsood1406/