Selling 5,000+ Boxes of Girl Scout Cookies with a bit of Twilio Magic

March 15, 2019
Written by


Selling Girl Scout cookies can be challenging, especially if the goal is to sell 5,000 boxes in 50 days! Why would one want to do such a thing? Well, first of all, selling Girl Scout cookies teaches girls life skills such as goal setting, decision making, money management, people skills, business ethics, and so much more. Secondly, the Girl Scouts of San Gorgonio council offers some amazing incentives. In addition to the many prizes like a robot, 3D printer, iPad, and a one week trip to Canada at 4,000 boxes sold (and much more). The prize for selling 5,000 boxes in 2019 is a two week trip to China and Japan, including an entire day at Shanghai Disney! Going to Japan has been a bucket list item for my ambitious daughter, Audrey, to travel to since preschool. So, game on!

Out of 12,386 registered Girl Scouts in our region, generally only around ten sell over 5,000 boxes. There are many strategies and tactics needed to reach such a high goal. Some tactics recommended to us by our Girl Scout council was to use your own personal social media page to promote the sale, create business cards to pass out liberally, and to directly contact friends and family for support. Our goal was to make it as easy as possible for friends, family, and supporters to either buy cookies or donate cookie boxes to the military or local charities with low friction and at scale. Enter Twilio SendGrid!

In this post, I will describe how Twilio helped us with managing the mind-boggling amount of communications between our wonderful customers and us. I’ll take you on our personal Twilio quest, where we purchase a Twilio number, use TwilioQuest to get a jump start and then implement our logic using the Twilio REST API, Studio and Functions. Along the way, I’ll explain the thought process for using each of the various Twilio tools. I hope this inspires you to go out and build something awesome. If you do, please share it with us!

Setting up a Phone Number

To get started we chose a phone number with a local area code for $1 a month (you can get started for free here) and then used TwilioQuest (the Getting Started mission) to quickly get familiar with how Twilio works.

Handling Incoming SMS and Calls

The first proof of concept was to create a simple TwiML bin where when an incoming call arrives, we respond with instructions on how to text us for orders or donations. Or, when we receive an incoming text, we respond with instruction on how to order or donate.

TwiML for processing incoming voice messages:

<?xml version="1.0" encoding="UTF-8"?>
<Say voice="woman" language="en-En">Thank you for supporting Audrey, your local girl scout! Please make your cookie order by texting this number with the word cookies if you would like to purchase girl scout cookies or text this number with the word donate to contribute boxes to deployed military overseas or a local charity. We will deliver locally for free.</Say>

TwiML for processing incoming SMS messages:

<?xml version="1.0" encoding="UTF-8"?>
            You may place your local, Moreno Valley/Riverside, CA and surrounding areas, order and we will deliver for free (payment due upon delivery): [link-redacted]. Not local to the Inland Empire, California? No problem! Please place your order here to have your cookies shipped or you may donate boxes to deployed military overseas here: [link-redacted]

At that point, the biggest issue was how to quickly respond to incoming messages while we were out and about. For this, we created a quick Pythonista script that allowed us to respond to incoming messages via API call when we saw them come in on the Console. Pythonista allows you to run Python code on your iPhone.

import requests
from requests.auth import HTTPBasicAuth
to_number = 'outgoing_number'
from_number = 'your_twilio_number'
message = 'Thank for your order, we will deliver after our cookie booth sale at around 6pm.'
account_sid = 'your_account_sid'
auth_token = 'your_auth_token'
auth = HTTPBasicAuth(account_sid, auth_token)
url = '{}/Messages'.format(account_sid)
values = {  
    	'To' : to_number,
    	'From' : from_number,
    	'Body' : message,
response =, data = values, auth = auth)

Improving SMS Responses

However, we quickly found that we needed to discriminate between cookie orders, donations, and general communications. Sending a large generic text was not ideal. Enter Twilio Studio.

With Twilio Studio we were able to create a workflow that handled each case: 1. donations, 2. cookie purchases and 3. general messages. For cases one and two, the flow is straight forward. If you text cookies to our number you get instructions on how to order cookies and if you text donate to our number you get instructions on how to donate. If you send a generic message, it gets forwarded to my personal cell phone number along with the “from” phone number and the body of the SMS message. Now I can reply to those messages without our valuable supporters receiving that long generic message each time.

Screenshot 2019-03-15 10.01.30.png

Keeping My Wife in the Loop using Email

I also wanted to keep my wife in the loop without overwhelming her phone with SMS messages. In that case … Enter Twilio Functions and a bit of Twilio SendGrid email magic.

exports.handler = function(context, event, callback) {
    const sgMail = require('@sendgrid/mail');
    const msgBody = 'We just received a donation from ' + String(event.donation_from);
    const msg = {
        to: '',
        from: '',
        subject: 'Audrey just received a donation!',
        text: msgBody,
        html: '<strong>' + msgBody + '</strong>',

With this Twilio Function, we take an incoming SMS and convert it to an email that gets sent to my wife. In this case, we are only tracking donations, but you can easily pass variables down in the Twilio Studio workflow by clicking config tab on the Run Function Widget and then clicking  the Config tab and adding Function Parameters, such as the body of an SMS (for example, {{trigger.message.Body}} ), and then accessing those Function Parameters using the event object in the function.

Screenshot 2019-03-15 10.29.35.png

First Success

As of this writing, we are 2 full days away from the end of our sale and Audrey is on track to reach her goal. She sacrificed every single day after school and every weekend for 48 days to do it. On top that, she was able to learn about programmable SMS, Voice and email with the outstanding TwilioQuest program.

And as sweet side effect of creating this app, I was able to earn a coveted Twilio track jacket, right after CEO of Twilio SendGrid, Sameer earned his. This, was unexpected and a highlight of my career. What’s not to love about getting rewards for hacking with your daughter and achieving massive goals?


What’s Next

I’m excited to help others earn their Twilio track jackets and help developers of all levels realize their ideas with Twilio tools. To that effect, I hope you will join me at SIGNAL this August 6 & 7th to learn all about the amazing capabilities of Twilio. In the meantime, be sure to give TwilioQuest a spin, you will not regret it!

There is so much more to be done to improve the workflows I have just described and many new use cases to implement (for example, handling failure cases, accepting donations with Stripe Pay over the phone and managing customers with Twilio Flex to be more efficient with follow-ups and thank yous, etc.). So by next year, I’ll have an updated post with new improvements. Please let me know if you have any interesting use cases you would like me to write about.

Until then, happy hacking!

Elmer Thomas is a Senior Developer Experience Engineer on Twilio's Developer Experience Team. His mission is to help improve the developer experience at Twilio, both internally and externally. Via all sorts of hackery, of course. Follow his exploits on Twitter and GitHub.