DEV Community

Cover image for An Ambivert’s Guide to Azure Functions
Chloe Condon 🎀 for Microsoft Azure

Posted on • Updated on • Originally published at Medium

An Ambivert’s Guide to Azure Functions

The following blog post will walk you through how to use Azure Functions, Twilio, and a Flic Button to create an app to trigger calls/texts to your phone. If you're looking for a quick summary and overview on Azure Functions, I recommend starting here with our documentation, or taking 4 minutes to read in more detail how to create your first Azure Function, so you have some context on how to use functions within Azure.

If you’d like to skip straight to the code, scroll down to the Let’s get to the code!​ section below.

Happy learning!

-Chloe

Hello everyone, my name is Chloe, and I’m an ambivert 👋

ron swanson gif

As a former actress (and current developer advocate), people often assume I’m an extrovert. The big secret is… I’m not! I’m actually an introverted extrovert (also known as an ambivert). Day-to-day, that means I have no problem being on stage and giving a talk at a conference, socializing with attendees, doing a couple on-camera interviews, and sticking around for the schmoozing at a happy hour… in fact, I love it! But afterwards I will escape to my hotel room and watch TV under a blanket for the proceeding 3 hours because I have to “recharge.”​

This tweet is a great example of that

So, here’s the definition of ambivert:​

A person whose personality has a balance of extrovert and introvert features.​

The best way (not so eloquent way) to describe my ambivert features would be that I equally love and hate being around other humans (only half kidding!).​ I love to socialize- conferences, meet-ups, and coffee chats are right up my alley (in fact, it’s a big part of my job!)…. but only half of the time. I have to recharge afterwards, or even schedule a couple nights at home to counter my social interaction. I’m likely very chatty at a dinner, but opt out of the evening karaoke (and trust me- ya girl LOVES karaoke).​​

So, what I’m trying to say is, if you ever see me sticking around at a conference happy hour, I’ve either had espresso later in the afternoon, I’m jetlagged, or I’m secretly dying on the inside.​

double yikesyikes

What I’m feeling internally vs. showing externally

Remember… I have a theatre degree. I’m very good at convincing people I’m not internally screaming inside 😐. I see my extroverted-ness almost like a button I can turn on and off depending on the situation… which is a great segue into the device I’ll be using to showcase how I built this.

Learning and creating ways to navigate my ambivert-ness “in the wild” at conferences, meet-ups, and meetings has been an interesting process!​​ Today, in this post, I’d like to show you one of those hacks I’ve created for myself… and hopefully, if you’re an introvert (or ambivert, or a human/robot looking to build cool things) you can try this demo yourself and code your way out of awkward or undesirable social situations!​

simpsons gif

When deciding to take on this project, I considered several different devices to build my project with.​​ At first, I pictured it as a wearable.​ I reached out to Sara Chipps and Jennifer Wadella to see if Jewelbots’ capabilities would work for my use case. Unfortunately, while very fashionable and fun, the range of the devices is limited (but if you have a young girl in your life- get them one of these. Very cool, fun way to learn programming!). I also considered FitBit as an option, but had concerns over folks thinking I was triggering my functions through it right in front of them. I needed something that was small, subtle and able to fit in my pocket.

Flic Button

So, the winner is… a Flic Button! What’s a Flic Button? Great question! It’s a small button (about the size of a quarter) that acts as a Bluetooth Remote for iOS and Android. You can program these buttons to do anything from turning on Smart lights in your home, controlling music, taking photos, sending texts, making calls, posting tweets, calling Ubers, etc.

flic butttons

Flic has many pre-built integrations and apps you can use within their app, ranging from sending a tweet to triggering a MP3 to play a laugh track (I may or may not have set up this specific example to bug my boyfriend in our apartment for when I tell bad jokes). Suz Hinton sent me a Flic Button for our mentorship sessions a few months back for an Azure exercise, and once I learned how to connect it to an Azure Function, I knew I had to build something fun with it.​ While the Flic Button does include a pre-built “fake call” feature in it’s app, it doesn’t actually create a call (you use a screenshot of a call, and it plays a ringtone sound). This is why using the Twilio API was necessary for this project, and how this blog post was born.

Azure Functions

If you’re unfamiliar, Azure Functions is a serverless compute service that enables you to run code on-demand without having to explicitly provision or manage infrastructure. Not only can you can use Azure Functions to run a script or piece of code in response to a variety of events, but it also lets you execute your code in a serverless environment without having to first create a VM or publish a web application.​

You can trigger the execution of Azure Functions in a variety of ways. Here are 5 common ones​:

☝🏻HTTP (which is what I’ll be talking about today)​

✌🏻 Timers (example: every day at 11am, execute this function, that starts + checks the temperature of my sous vide)

👌🏻 You can create a function triggered when data is added to or changed in Azure Cosmos DB​

🖖🏻 You can create a function triggered when files are uploaded to or updated in Azure Blob storage

🖐🏻 You can create a function that is triggered when messages are submitted to an Azure Storage queue

And many more! For a complete list, tutorials, documentation, and additional details of the capabilities of Azure Functions, start with the Azure Functions Documentation.

twilio logo and docs mascot

If you haven’t played much with serverless/Azure Functions, I recommend starting with reading this Azure Functions Overview and completing this Create Serverless Logic with Azure Functions module to get a better idea of how all of these pieces fit together before diving into programming your Flic Button. The Microsoft docs are a great place to get free resources and lessons on how to get started!

Speaking of great documentation/getting started, I also used Twilio to create this. Twilio allows software developers to programmatically make and receive phone calls, send and receive text messages, and perform other communication functions using its web service APIs.​ Their walk-through/demo code has a special Rick Astley Easter Egg that I will show you in a bit since I kept it in my demo 🙃

Alright- let’s review our goals!

Goal:

Use Azure Functions to create a button that will save me from awkward social interactions by…​

-Texting my friends an SOS message to save me​

-Triggering a call from my “boyfriend”*

I’ll get into those quotes in a second. I promise my boyfriend is real.​

diagram of app

Let’s get to the code!​

​For the sake of easy to understand visuals/screenshots I used the Azure portal to create this. You can also use VS Code, the Azure CLI, etc.​ With Azure Functions you are given the the ability to code and test Functions locally on your machine without having to deploy to the cloud every single time you want to test (a huge time saver!).

To create an Azure function, you can just start from the Get Started menu and select (surprise!) Function App.

Create Resource

screenshot 1

screenshot 2

Then you’ll need to fill in some basic info about your function here. Including the app name, the Azure subscription you’d like to use, a resource group (I’m creating a new one in this case), the Operating System you’d like to use, the hosting plan (I’m using consumption), the location I’d like to use (I’m in California, so West US 2 is usually my default), the runtime stack I’d like to use (I’m using JavaScript in this case), and I have the option to create new storage or use existing. I created a new one in this case.​​

Once I have all these filled out, I can go ahead and deploy! Wait about a minute or two, then watch for the Deployment succeeded message.​

Woo! If you followed those steps, we have our resource! We’ll just select “Go to resource” to view your new Function App.​ Now we’ll add a new function.

screenshot 3

For this example, I’m selecting In-portal.

screenshot 4

And I have selected Webhook + API

It typically takes about a minute to deploy and then we’ll have a fresh new Azure Function waiting to be called. The default code is a simple hello world app, where if you paste the function URL into your browser’s address bar. Add the query string value &name= to the end of this URL and press the Enter key on your keyboard to execute the request. You should see the response returned by the function displayed in the browser.​

screenshot 5

Cool! So, we see this works now. Let’s get to the fun part…

Let’s Create a Fake Boyfriend

My boyfriend Ty Smith works full-time as an Android Developer at Uber, and is an Android GDG and GDE, and also travels for conferences as well. Needless to say, he’s a busy guy and I didn’t want my app to call him, because maybe he’d be in a meeting/at dinner/playing the new Resident Evil game, and I wouldn’t want to disturb him (also, testing this would have been a bit of a nightmare- example can be seen in this Twitter thread).

help frog

Frog puppet reenactment of me trying to test this with Ty.

​So, everyone, please meet my new fake boyfriend Twilio Smith- he’s a Twilio # that I purchased (with a Texas area code 🌵🤠).​

twiloi screenshot

After reviewing the Twilio API docs, I was able to get up and running pretty quickly with some sample code (shout-out to Twilio for the excellent documentation!).​

I have 2 Azure functions I needed to create and call. One for the call, and one for the texts. Please note: it’s okay to hardcode your Twilio credentials when getting started, but you should use environment variables to keep them secret before deploying to production. Check out Frank Boucher’s video on How to use Environment Variables in Azure Functions for a great 5 minute tutorial!

👉 Sample message trigger index.js

You’ll probably notice that this function sends a text to me vs to friends/coworkers at a conference. For the sake of this demo, I’ve made it so the code texts me so I can show this off in-person when I demo this on stage (plus, you’ll annoy less folks with test texts while debugging… again, you can learn more about that in this Twitter thread 😬🤦‍♀️). But obviously, you’d replace these numbers with the numbers of your friends you wish to alert.

👉 Sample call trigger index.js Gist

The code for our phone call trigger is pretty similar except we’re making a call, not a text. You’ll also notice that I’m linking to something here.​.. let’s take a look at what that link is hosting.

👉 Sample call trigger index.js Gist

As I mentioned earlier, one of the reasons I decided to use Twilio was to be able to have a real call come in on my phone. Twilio also gives us the capability to use TwiML to compose voice messages, as well as do things such as, oh, I don’t know… play an MP3 of Rick Astley perhaps? Obviously, you can record your own voice message MP3 (I’ve included several samples of my own voice as your cousin/partner/friend in the repo). You can take a look at Microsoft’s documentation on how to use Twilio for voice and SMS capabilities from Azure if you’d like to dive deeper into TwiML, or have more questions about configuring your Application to use Twilio libraries.

flic screenshot

Now we can incorporate our Flic Button. Here’s what the Flic app looks like (above). For the sake of time, I won’t walk through every step, but essentially you just add the URL of the Azure Function and click save. Flic’s app is very straightforward, and will require a simple copy/paste of the https link we created with our 2 Azure Functions.

Last, but certainly not least, I needed to add my fake boyfriend to my contacts (complete with an image) so it would look more legitimate when a call came through. Otherwise this would show up in my phone as an unknown #. So…. shall we go ahead and test it out?​​

contact screenshott

My “very real” fake boyfriend

As I mentioned before, I wanted to configure one of my Functions to text other people (for it’s actual use case), but I can’t really demonstrate/test that well on my own. So with this demo, my fake boyfriend is going to be texting me.

So, that’s the app! As you can see, it’s pretty easy to get up and running with Azure Functions! If you’d like more instructions on how to deploy to Azure, check out the GitHub repo here. There are so many easy ways to deploy to Azure, and you can read about them in more detail in our docs.

Using simple Azure Functions just like this can open the door for a plethora of automation in your applications or even your personal life. Anything from a button for your children to press when they get home from school (to alert the bus dropped them off safely), even starting a tea kettle in the morning so your tea is ready to go while you’re groggily getting ready for work, or creating a function to check a database in your app on a timed schedule. This particular Twilio demo was created just for fun, but think about how using Azure Functions in your applications or everyday tasks could automate things for you!

So, what’s next for this project?​ Well, I’d love to add a couple more features​- please check out the repo on Github if you’re interested in contributing your own features and ideas! Here are a couple that folks have suggested on Twitter:

Create a fake PagerDuty Alert (for those who don’t feel comfortable with the fake significant other option)
Add several more versions/MP3s of voice (in place of the TwiML + music)
Build my own very realistic fake boyfriend or gal pal robot and have the button trigger them walking over to save me (jk… 🙃)

family matters gif

If you’ve read this far- congrats! You’ve successfully learned how to get yourself out of awkward social situations using technology. If you’d like to dive deeper into any of these topics, here are some great places to get started:

Azure Functions Documentation — a great starting point for beginners which includes 5 minute Quickstarts​ to create functions that execute based on events created via:

💻 HTTP (what I used for this blog)

Timers​ (if you wanted a timed/fixed notification/call/alert/etc.)

☁️ Create Serverless Logic with Azure Functions​ module (takes about 36 mins to complete, and will walk you through each step in a sandbox mode!)

👉 Execute an Azure Function with Triggers (1 hour 20 mins to complete w/ sandbox as well)

Chain Azure Functions Together Using Input and Output Bindings (1 hour 10 mins to complete w/ sandbox as well)

Have any questions? Comment below, or shoot me a message on Twitter!

chloe thumbs up

Happy Ambiverting! (GIF courtesy of Sentry.io)

Top comments (0)