<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ethan Tang</title>
    <description>The latest articles on Forem by Ethan Tang (@etang01).</description>
    <link>https://forem.com/etang01</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F435863%2F81df3ece-203b-4e79-adcf-f5498200797a.png</url>
      <title>Forem: Ethan Tang</title>
      <link>https://forem.com/etang01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/etang01"/>
    <language>en</language>
    <item>
      <title>Azure Alarms</title>
      <dc:creator>Ethan Tang</dc:creator>
      <pubDate>Wed, 22 Jul 2020 02:44:52 +0000</pubDate>
      <link>https://forem.com/etang01/azure-alarms-51ha</link>
      <guid>https://forem.com/etang01/azure-alarms-51ha</guid>
      <description>&lt;p&gt;I'm a very forgetful person, especially when I'm out having fun. I love hiking and biking, but my allergies make life miserable so I need to take my meds every 24 hours when I head out. To fix this problem, I can just set a notification, but when I'm doing something else, it's easy to miss the slight buzz and tone from my phone.&lt;/p&gt;

&lt;p&gt;With Azure and Twilio, this problem can be simply remedied. We'll use Azure to set up a timer to trigger other code to run and integrate Twilio, so we can send a text message or call to ourselves to make sure we notice the reminder.&lt;/p&gt;

&lt;p&gt;It will take a little bit of Javascript to make everything work, but it's pretty straightforward and we'll go over everything together. Firstly, we need to set up 2 accounts, &lt;a href="https://azure.microsoft.com/en-us/free/search/?&amp;amp;ef_id=Cj0KCQjwn7j2BRDrARIsAHJkxmwz0tcFx8fTgoL7jogctsTPYrzEntPYcIpEu0QV_YRDbPFyv7oNrOoaAvspEALw_wcB:G:s&amp;amp;OCID=AID2000128_SEM_Cj0KCQjwn7j2BRDrARIsAHJkxmwz0tcFx8fTgoL7jogctsTPYrzEntPYcIpEu0QV_YRDbPFyv7oNrOoaAvspEALw_wcB:G:s&amp;amp;gclid=Cj0KCQjwn7j2BRDrARIsAHJkxmwz0tcFx8fTgoL7jogctsTPYrzEntPYcIpEu0QV_YRDbPFyv7oNrOoaAvspEALw_wcB"&gt;Microsoft Azure&lt;/a&gt; and &lt;a href="https://www.twilio.com/try-twilio"&gt;Twilio&lt;/a&gt;. Azure has a 12 month free trial, and Twilio has a free trial as well with some credits to experiment with the features.&lt;/p&gt;

&lt;p&gt;Step 1: Create Timer Function&lt;br&gt;
Let's pop open Azure and click to create a new resource, get started, then select "Function App". After that, fill in all the info about your function. Make sure you select "JavaScript" for the runtime stack option.&lt;/p&gt;

&lt;p&gt;Now that we've done all that, we can go ahead and click "Create" and deploy the function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9re2ncvI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9ias1hk2pu1rsubvivel.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9re2ncvI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9ias1hk2pu1rsubvivel.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8WVCBnyR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kbag1l9kk8c14pcuzmi2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8WVCBnyR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kbag1l9kk8c14pcuzmi2.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's select the "In-Portal" development environment for simplicity, but you can use VS Code instead if you want. Under the "More Templates" option, we'll be choosing a Timer Trigger because we want the timer to trigger our function in Twilio.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hNhNfARb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ws27wnw2cr0a1r7ipps8.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hNhNfARb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ws27wnw2cr0a1r7ipps8.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When filling out the time, remember that it's in UTC, and the numbers are '{sec}{min}{hr}{day}{month}{day of week}'&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s0uTby8N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3838wxge16ommedx6u1x.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s0uTby8N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3838wxge16ommedx6u1x.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it for now. The Azure timer function is all set up. Let's integrate Twilio, so we can get a notification.&lt;/p&gt;

&lt;p&gt;Step 2: Setting up Twilio Credentials&lt;br&gt;
Firstly, let's make sure we have Twilio installed. We'll go to the left panel of our app menu in Azure and select console. Then type:&lt;/p&gt;

&lt;p&gt;​npm install Twilio&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gab86lsa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/srlbntx0bog2lr5nmzxg.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gab86lsa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/srlbntx0bog2lr5nmzxg.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's go over to our Twilio account and purchase a phone number. The free Twilio trial comes with some balance so we can purchase a phone number and send calls and texts using that balance.&lt;/p&gt;

&lt;p&gt;Back over in Azure, let's go to the same left panel as we did earlier and go into the Configuration tab. There let's create 4 new application settings for your TWILIO_SID, TWILIO_TOKEN, SENDER_NUMBER, RECIPIENT_NUMBER. Those are all values that we need in our code later, but for security, we save those values under their corresponding name in the application settings instead of directly writing it into our code so other people can't see those credentials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LxybAC3m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cksijqfgay9xurc8do8m.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LxybAC3m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cksijqfgay9xurc8do8m.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 3: Sending a SMS&lt;br&gt;
And now, the code. Let's go back to that left menu, select "Functions" and click on the timer trigger we made earlier. There will be a "Code + Test", and we'll be editing index.js.&lt;/p&gt;

&lt;p&gt;​Here's a look at the code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IpqQm10V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o368d56z5vxi7kiif2om.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IpqQm10V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o368d56z5vxi7kiif2om.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's do a quick rundown of the code. If the timer is past due, write that in the log, then create and send a message from SENDER_NUMBER to RECIPIENT_NUMBER. If everything works perfectly, log a success, else log the error.&lt;/p&gt;

&lt;p&gt;Step 4: Making a Call&lt;br&gt;
The code to make a call isn't that different from sending a text, but we will have to make some changes.&lt;/p&gt;

&lt;p&gt;One of the things that we'll have to do is make a TwiML Bin in Twilio.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jfKAT4AS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g8hmxkbam8xbq1jy1mtd.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jfKAT4AS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g8hmxkbam8xbq1jy1mtd.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fVVu7d0Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4h63tc5z61v2962gr34i.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fVVu7d0Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4h63tc5z61v2962gr34i.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In that TwiML Bin, let's write some code so the program knows what to say during the call, and copy the URL for the bin and save it as an Application Setting with all our other Twilio credentials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YCBhWBWu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/z1hfi3dxh50jj4j6c7yt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YCBhWBWu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/z1hfi3dxh50jj4j6c7yt.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;​Now we can go back and change the code like so:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9S-Jwdti--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wsea87gmuh7qsts3hzpc.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9S-Jwdti--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wsea87gmuh7qsts3hzpc.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 5: Testing and We're Done!&lt;br&gt;
With this, we're all done with the code and should test it. Just click the "test" button up top, and when the time you set on the timer rolls around, it will go off and either send a text or call depending on which one you chose to implement.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IIv3g8AW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gm7c7i3qeo46v7pq0x4n.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IIv3g8AW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gm7c7i3qeo46v7pq0x4n.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If everything works, we're done! We've made an automated text or call that is sent at the time we set to remind us to do something we need to do by using Azure, Twilio, and a bit of JavaScript. You can customize the code to do whatever you want. You can use it as a wakeup call if you want something more than a simple alarm, or you can spam a friend with texts (probably shouldn't do that one...). Have fun with it! The sky's the limit. Now if you'll excuse me, I'm going to hit the trails.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>azure</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
