Jasper is a great platform to develop voice-controlled applications. It has excellent developer documentation that makes it easy to create your own modules. Jasper is pretty cool so I decided to start programming some modules myself.
The first is called Hermes. This module will allow you to send SMS messages to your friends and family through the Twilio API. Let’s get started:
If you haven’t already, register an account with Twilio and install the Python module:
Then add your Twilio information in your profile.yml
1 2 3
Create a new file titled
We will need to import two modules for this project:
First we need to define the words that will activate Hermes:
We then need to define an
isValid() method that will allow Jasper to launch our module. Jasper will be looking for the words specified in the list above. We do this by using regular expressions:
Here, Jasper is looking for the phrase “send text message” in our command.
Once our command is deemed valid, we need a way to handle it and take action:
handle() method we will need to do a few things:
- Grab your Twilio keys
- Ask you who you want to send a message to and grab their number
- Retrieve your Twilio number
- Send the text message
In order to use Twilio, your Account SID and Auth Token must be available to Jasper. We will retrieve them and initialize the Twilio client:
1 2 3 4
Next, we need to decide who to send it to. We will use a contacts list in your
profile.yml to store phone numbers. Due to inaccuracies with STT engines, you can only send messages to numbers in your contacts. This way we avoid issues with Jasper correctly hearing the number you want to send to. We will use a simple dictionary for the contacts list. The key will be the person’s name and the value will be the phone number as a string
Let’s start your contacts list with your Mom’s and your Dad’s numbers. Open your
profile.yml and add the following:
Just replace the numbers with their actual numbers. Be sure to include the country code prefix in the number (if you are in the US it it +1).
Jasper will ask who you want to send a message to and then get their number from your contacts list:
1 2 3 4 5 6 7 8 9
The method for retrieving the contact’s number:
We then must get your Twilio number from your profile.yml:
Add it to the
1 2 3 4 5 6 7 8 9 10 11
Finally we send the text message:
1 2 3 4 5 6 7 8
We then add it to our
1 2 3 4 5 6 7 8 9 10 11 12 13
This method is where all of the action happens. Jasper will ask you what you would like to say in your text message. We then use the Twilio client to create a message using the contact’s phone number, your phone number, and then the message that you specify. The message will then be sent through the Twilio API to your contact’s number. Jasper will then verbally confirm that the text message was sent. It’s really that easy! No more excuses to not send “Happy Birthday” wishes to your friends and family.
To use Hermes with Jasper, add it to your modules folder:
This was my first module developed for Jasper. It turns out that it’s super easy to write modules for it. It took me under two hours to write Hermes. I’m pretty excited to explore it further especially in the home automation domain.
If you haven’t already, head on over to Github and check it out.