<?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>DEV Community: Brett Evanson</title>
    <description>The latest articles on DEV Community by Brett Evanson (@brettev).</description>
    <link>https://dev.to/brettev</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%2F335865%2F4cbee125-9ee3-4fd2-b9a9-964cec313c67.jpg</url>
      <title>DEV Community: Brett Evanson</title>
      <link>https://dev.to/brettev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brettev"/>
    <language>en</language>
    <item>
      <title>Daily Covid Case Counts by Text using Twilio Functions</title>
      <dc:creator>Brett Evanson</dc:creator>
      <pubDate>Mon, 10 Aug 2020 16:53:05 +0000</pubDate>
      <link>https://dev.to/twilio/daily-covid-case-counts-by-text-using-twilio-functions-ahm</link>
      <guid>https://dev.to/twilio/daily-covid-case-counts-by-text-using-twilio-functions-ahm</guid>
      <description>&lt;p&gt;My wife is pretty concerned with Covid. She's technically high risk, so we've been super careful. One thing that means is she is on top of the case counts in our area. To help her keep tabs on this I wanted something that would easily get daily case counts whenever I wanted. I figured I could find an API where I could pull case counts from, then hook a Twilio phone number up to that so I could text in a zip code and use Twilio Functions to process it, hit the API, and pull back case counts.&lt;/p&gt;

&lt;p&gt;So that's what I'm going to walk through today. I'll share code snippets and screenshots of everything along the way.&lt;/p&gt;

&lt;p&gt;Step 1 - If you don't have a Twilio account already, let's get an account set up. If you want $10 to get started and play around, use this link to sign up: &lt;a href="https://www.twilio.com/referral/6M48j2"&gt;https://www.twilio.com/referral/6M48j2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 2 - Buy a phone number. Once you have an account created, go to this link: &lt;br&gt;
&lt;a href="https://www.twilio.com/console/phone-numbers/incoming"&gt;https://www.twilio.com/console/phone-numbers/incoming&lt;/a&gt; &lt;br&gt;
and then click the red and white plus sign to get a new phone number. Don't worry about setting up the number, we'll do that after we set up the Function.&lt;/p&gt;

&lt;p&gt;Step 3 - The Twilio Function. To create a Twilio function go here:&lt;br&gt;
&lt;a href="https://www.twilio.com/console/functions/manage"&gt;https://www.twilio.com/console/functions/manage&lt;/a&gt;&lt;br&gt;
and click on the red circle with the plus sign to add a new one.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--46LsBaAA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/6p5f6jd8ehdpzx3khdon.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--46LsBaAA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/6p5f6jd8ehdpzx3khdon.png" alt="Alt Text" width="362" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Paste the code in below. I'll break it down into chunks and explain what it's doing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const https = require('https');
exports.handler = function(context, event, callback) {

    let url = "https://localcoviddata.com/covid19/v1/cases/newYorkTimes?zipCode=" + event.Body + "&amp;amp;daysInPast=4";

    https.get(url, (res) =&amp;gt; {
        newstring = "";

        res.on('data', (d) =&amp;gt; {
            var obj = JSON.parse(d);


            obj.counties.forEach(county =&amp;gt; {
                newstring = newstring + "County: " + county.countyName + "\r\n";
                county.historicData.forEach(data =&amp;gt; {
                    newstring = newstring + data.date + ": " + data.positiveCt + "\r\n";
                });
            newstring = newstring + "\r\n";
        })
        let twiml = new Twilio.twiml.MessagingResponse();
        twiml.message("Last 4 days Numbers: \r\n" + newstring);
        callback(null, twiml);
      });

    }).on('error', (e) =&amp;gt; {
      console.error(e);
    });
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are using localcoviddata.com's New York Times API. This takes a zip code and gives us the county data associated with that zip. Some zip codes span multiple counties, so we had to account for that in our loops through the response. The API returns a JSON object we parse into the "obj" variable. Loop through that object's "counties" attribute. This lets us print out the county name, and into the &lt;code&gt;historicData&lt;/code&gt; attribute for the last 4 days counts.&lt;br&gt;
So it would look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;County: Salt Lake County
2020-08-02: 19408
2020-08-01: 19323
2020-07-31: 19086
2020-07-30: 18847

County: Utah County
2020-08-02: 7949
2020-08-01: 7808
2020-07-31: 7688
2020-07-30: 7584
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take that string and pass it to the &lt;code&gt;twiml.message&lt;/code&gt; function and return that in callback. This makes the Function kick back the correct response to Twilio.&lt;/p&gt;

&lt;p&gt;Step 4 - The last step to building this is to connect the Function to the phone number you bought in step 2. On the phone number's settings page, set it to the Twilio Function where it says "A Message Comes In"&lt;/p&gt;

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

&lt;p&gt;Finally, you can test it by sending a text message containing a zip code to your Twilio number and get current case counts for your area.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0U__cD-9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/2ufukjgdlx4o5llm6vgj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0U__cD-9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/2ufukjgdlx4o5llm6vgj.jpg" alt="Alt Text" width="800" height="562"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>twilio</category>
    </item>
    <item>
      <title>Meme Competition - Judges and Contributors</title>
      <dc:creator>Brett Evanson</dc:creator>
      <pubDate>Fri, 14 Feb 2020 20:30:40 +0000</pubDate>
      <link>https://dev.to/brettev/meme-competition-judges-and-contributors-2ek7</link>
      <guid>https://dev.to/brettev/meme-competition-judges-and-contributors-2ek7</guid>
      <description>&lt;p&gt;I was playing around with a way to find out what the funniest memes are, and who the funniest meme contributors are. Also trying to find a way to distribute everything via Twilio SMS. Makes it easy for anyone to join in the fun.&lt;/p&gt;

&lt;p&gt;Text "Judge" to 385-217-9272 To sign up as a meme judge.&lt;/p&gt;

&lt;p&gt;Sign up as a contributor on thememecity.com&lt;/p&gt;

&lt;p&gt;Visit thememecity.com to see the best memes, and who the best contributors are!&lt;/p&gt;

&lt;p&gt;Please give me any feedback :) yes I know it's not pretty :\&lt;/p&gt;

&lt;p&gt;--Brett&lt;/p&gt;

</description>
      <category>twilio</category>
      <category>sms</category>
      <category>memes</category>
      <category>sideprojects</category>
    </item>
  </channel>
</rss>
