How I solved Jessica’s NYC Parking Problem with Twitter, Twilio and NO CODE
Tags: azure, serverless, tutorial, beginners
Published: 2019-04-19 13:49:41

---
title: How I solved Jessica’s NYC Parking Problem with Twitter, Twilio and NO CODE
published: true
description: Using the Twitter and Twilio APIs with no code via Azure Logic Apps!
tags: azure,serverless,tutorial,beginners
canonical_url: http://timheuer.com/blog/archive/2019/04/19/how-i-solved-jessicas-nyc-parking-problem-with-twitter-twilio-and-azure.aspx
cover_image: https://thepracticaldev.s3.amazonaws.com/i/49nunjzuz5oe1la5yrp1.png
---
<p>I’ve been reading a lot of great content on <a href="https://dev.to">dev.to</a> lately (seriously you should go check it out and follow some tags…great community there) and came across this great headline “<a href="https://dev.to/twitterdev/how-i-solved-my-nyc-parking-problem-with-python-the-search-tweets-api-and-twilio-1chp">How I Solved My NYC Parking Problem With Python, the Search Tweets API and Twilio</a>” by <a href="https://twitter.com/jessicagarson">Jessica Garson</a>, a Developer Advocate at Twitter.&nbsp; Jessica was trying to solve a problem that NYC folks have when trying to determine when to move their street-side parked cars each night due to ‘alternate&nbsp; side regulations’ which determine when certain sides of roads can be used or the regulations won’t be enforced due to holidays, events, whatever. </p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="New York City parking sign" src="https://storage2.timheuer.com/parkingsign.png"></p><p> She delved into using Python, the Twitter Search APIs and Twilio to tie these all together.&nbsp; Fun problem to solve and results in a text to Jessica whether she needs to worry about moving her car or not.&nbsp; Immediately after reading it I though of the game show Name That Tune.</p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Picture of Name That Tune game show" src="https://storage2.timheuer.com/name-that-tune.jpg"></p><p>The premise of the game show is that contestants battle it out to who can identify a song based on the fewest amount of notes in a song.&nbsp; So of course, it is 100% applicable to code, right?&nbsp; Anyhow I thought to myself <em>Self, I can solve this problem in less effort and with NO code!</em></p><p>Immediately I went to work using <a href="https://azure.microsoft.com/services/logic-apps/?WT.mc_id=docs-blog-timheuer">Azure Logic Apps</a>.&nbsp; Azure Logic Apps are a means to…well, let’s let the marketing people tell us what they are:</p><blockquote><p><em>Azure Logic Apps simplifies how you build automated scalable workflows that integrate apps and data across cloud services and on-premises systems.</em>&nbsp;</p></blockquote><p>Lots of buzzwords there but basically it’s workflow/orchestration platform that allows you to use ‘connectors’ between various inputs and outputs.&nbsp; Logic Apps can be developed using code, but most are easily developed using no code and using the graphical connector tools.&nbsp; If you’ve ever used/heard of <a href="https://flow.microsoft.com/en-us/">Microsoft Office Flow</a> this is powered by Azure Logic Apps underneath!&nbsp; So immediately after reading the article I went to work.&nbsp; I knew that Azure already had pre-build connectors for Twitter and Twilio and that I should be able to do this easily.&nbsp; <a href="https://docs.microsoft.com/azure/connectors/apis-list?WT.mc_id=docs-blog-timheuer">Connectors</a> are pre-defined pieces of logic that help get access to events, data, and actions across other apps and platforms, in our case Twitter and Twilio!</p><p>Jessica’s problem was fairly simple: Watch when the @NYCASP account tweets and if it indicates rules are ‘suspended’ then alert her with a text message.&nbsp; Now this relies on @NYCASP account being consistent in their tweets and it turns out they are VERY consistent in them, so it’s easy to search for the simple terms as Jessica did.&nbsp; So let’s do the same.&nbsp; </p><p><img width="414" height="768" title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of Twitter account for NYCASP" src="https://storage2.timheuer.com/tweets.jpg"></p><p>To get started I needed an <a href="https://azure.microsoft.com/free/?WT.mc_id=freetrial-blog-timheuer">Azure account which is free to get started</a> and there are a ton of services free that you can use forever.&nbsp; I also still needed a Twilio account like Jessica notes so you still need that to get your Twilio credentials…be sure you have that.&nbsp; With both of these in hand, let’s log in to the Azure Portal….we won’t even need any tools other than a browser to complete this app!</p><p>In the portal you’ll create a new resource in Azure…search for Logic App and it will show up:</p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of Azure portal" src="https://storage2.timheuer.com/createlogicapp.png"></p><p>You’ll need to provide a name, choose a resource group plan and a geographic location where you want this to live.&nbsp; If you’ve never created any Azure resources before, a resource group is a container for certain compute resources to leverage.&nbsp; For this, I recommend creating an App Service resource group and using a free plan that comes with your free trial account.&nbsp; Then you can use this resource group for your Logic App.&nbsp; Once you have that created navigate to that resource and you will see a page that welcomes you with a tutorial video and some options for pre-configured templates.&nbsp; Thankfully one of the starting options is “When a new tweet is posted” so let’s use that one to help us get started as it will default add the <a href="https://docs.microsoft.com/connectors/twitter/?WT.mc_id=docs-blog-timheuer">Twitter connector</a>!</p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of Azure Portal Logic App creation" src="https://storage2.timheuer.com/newtweetposted.png"></p><p>This dumps us into the Logic App designer, a graphical interface that helps us do the connections.&nbsp; You’ll immediately see the first ‘trigger’ which is our Twitter one and it wants you to sign in to be able to use the functionality (think of this as authorizing use of the API).&nbsp; Once you sign in click continue and you’ll get the options.&nbsp; Now basically we want to look for when a new tweet is posted by @NYCASP on a time interval.&nbsp; Their account is pretty consistent so I chose every four hours and used the ‘from:@NYCASP’ query language as the search text.</p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of Twitter connector" src="https://storage2.timheuer.com/newtweetconfig.png"></p><p>That’s it for Twitter.&nbsp; No code successfully so far!&nbsp; So now every 4 hours this will check for a new tweet from that account.&nbsp; Now let’s do something with it!&nbsp; In Jessica’s scenario we need to look at the tweet and act upon it only if a specific condition was met.&nbsp; So let’s use that little “+” symbol on the designer and add a new action.&nbsp; Search for 'Condition’ and you will see ‘Control’ come up as an option…select that, then you will see the Condition connector…choose that.&nbsp; The condition connector gives us a simple decision tree: what is the condition, what do you want to do if true, what do you want to do if false:</p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of Condition action connector" src="https://storage2.timheuer.com/conditionblank.png"></p><p>In the condition area where it says ‘Choose a value’ when you click in to there, data from the previous trigger will be made available to you and you can see all the details it exposes!&nbsp; We will scroll and look for Tweet text and select that.&nbsp; Change the oeprator to ‘contains’ and type in ‘suspended’ as the value.&nbsp; It should look like this:</p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of Condition action connector" src="https://storage2.timheuer.com/conditionsuspended.png"></p><p>Now we know that the tweet is telling us something about suspending…but Jessica wants to know if she has to move her car for tomorrow.&nbsp; Let’s add another condition to now check to see if it contains ‘tomorrow’ in the text.&nbsp; We follow the same steps in creating a new condition trigger and connecting it.&nbsp; </p><blockquote><p>At this point we have a nested condition.&nbsp; Could we have put them in the same one?&nbsp; Probably, but I’m just following similarly Jessica’s flow.&nbsp; </p></blockquote><p>It should look like this:</p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of Condition Action connector" src="https://storage2.timheuer.com/2ndcondition.png"></p><p>Now we know if both of those are true we need to send a text message.&nbsp; Click the ‘Add an action’ button in the True condition and search for Twilio and select the ‘Send a Text Message’ action.&nbsp; This will add the provided <a href="https://docs.microsoft.com/connectors/twilio/?WT.mc_id=docs-blog-timheuer">Twilio connector</a> which provides this functionality (and more).&nbsp; Similarly like twitter you will see it and after selecting have to authenticate to your account to get the credentials.</p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of Twilio search for connector" src="https://storage2.timheuer.com/twiliosearch.png"></p><p>After doing that you now simply enter the details of your text message.&nbsp; For Twilio the From number must be your account SMS number unless you have premium services that enables you to do something more.&nbsp; If you try to get fancy without premium services from them, this will fail.&nbsp; Don’t get fancy…we’re just moving cars across the street remember?&nbsp; Enter the text you want to send and to the phone number you want to send it to…done!</p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of Twilio connector" src="https://storage2.timheuer.com/twilioconfig.jpg"></p><p>Now on the false conditions we do still have to tell the Logic App what to do.&nbsp; In these cases, unless you want to do more, again add an action and choose System, then look for ‘Terminate’ – it’s a simple action that basically just stops the flow and can log a message.&nbsp; I configured mine like this on BOTH false conditions:</p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of Terminate action connector" src="https://storage2.timheuer.com/faslecondition.png"></p><p>That’s it, I’m done.&nbsp; No code.&nbsp; This took me longer to write this post then it did to actually do the Logic App the first time.&nbsp; Now I waited.&nbsp; And waited.&nbsp; And waited.&nbsp; I completed the logic app right after reading Jessica’s article and wanted to ‘naturally’ test this with the real deal tweets.&nbsp; But no parking regulations were suspended.&nbsp; My logs looked like this:</p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of Azure log files" src="https://storage2.timheuer.com/logs.png"></p><p>UNTIL A FEW DAYS AGO!&nbsp; My phone buzzed, I looked down and BOOM:</p><p><img width="640" height="431" title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of SMS text message stating 'NYC Alt Parking Suspended Tomorrow'" src="https://storage2.timheuer.com/sms.jpg"></p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Animated GIF image of people happily dancing" src="https://media.giphy.com/media/BlVnrxJgTGsUw/giphy.gif"></p><p>I wonder if Jessica got a text message too!&nbsp; I was so happy and I don’t even live in NYC or have to worry about moving my car to a different side of the street!&nbsp; The logs of Logic Apps are pretty cool as well and also graphically follow your flow and show you input/output state along the way:</p><p><img title="" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="Screenshot of Logic App log" src="https://storage2.timheuer.com/successlog2.png"></p><p>So with no code and only a few steps to authenticate to Twitter and Twilio, I was able to use only a browser and complete the same task.&nbsp; Did I win Name That Tune?&nbsp; Who cares…doing software isn’t a competition, it’s fun and we get to use the tools and technology we feel most productive with.&nbsp; For me, this was just a gut reaction to see if could be done as easily as I thought and indeed it could.&nbsp; So yeah I won :-D.</p><p>Check out more about the pieces I used to put this together and get your custom logic apps working:</p><ul><li><a href="https://azure.microsoft.com/free/?WT.mc_id=freetrial-blog-timheuer">Azure Account</a> – get one free</li><li><a href="https://docs.microsoft.com/azure/logic-apps/?WT.mc_id=docs-blog-timheuer">Azure Logic Apps</a> (docs/tutorials)</li><li><a href="https://docs.microsoft.com/connectors/twitter/?WT.mc_id=docs-blog-timheuer">Twitter connector</a></li><li><a href="https://docs.microsoft.com/connectors/twilio/?WT.mc_id=docs-blog-timheuer">Twilio connector</a></li><li><a href="https://azure.microsoft.com/services/app-service/?WT.mc_id=docs-blog-timheuer">Azure App Service</a> (for the resource group)</li><li><a href="https://docs.microsoft.com/connectors/?WT.mc_id=docs-blog-timheuer">Over ~200 built-in connectors provided for Logic Apps</a>!</li></ul><p>Hope this helps!</p><p><br/><br/></p><p>(this article <a href="http://timheuer.com/blog/archive/2019/04/19/how-i-solved-jessicas-nyc-parking-problem-with-twitter-twilio-and-azure.aspx">cross-posted from timheuer.com</a>)</p>