DynamoDB and Botkit

emojination_64I recently built (on top of the Botkit framework) and launched a Slack chat based game, emojination. I started out running emojination on Heroku. It was cheap and fast to get up and running there. Heroku does some really nice things for developers that shields the complexity of Amazon’s AWS. However, once I had emojination running well enough on Heroku, I wanted to learn AWS better. I knew about some of the services at a high level and used some of them on projects operationally, but I had never built anything on top of them myself.

I could run everything on “native” Amazon AWS services except Redis, which I was using for Botkit’s storage. While Amazon has a Redis based service, it is meant for caching. I could run Redis on EC2, either running the setup myself or using a 3rd party that makes it simpler to setup and maintain. While those options were reasonable, I wanted to see if I could make use of Amazon’s DynamoDB, since it’s a perfect match for the job (a key/value store), doesn’t require ops overhead on my part, and comes with some AWS free tier incentives. Yep, lock me up in the trunk and throw away the key.

The only problem was that there wasn’t a Botkit storage module for DynamoDB. There was one for Redis, MongoDB, Firebase, etc. but no DynamoDB. Seeing as I have near zero Node.js skils, I thought, “how hard can it be to create the DynamoDB Botkit storage module?” Not too hard, as it turns out, except for the part where I need to still figure out how to get the tests passing where promises are involved. The bulk of my time was spent figuring out how DynamoDB worked and what the options were in regards to npm DynamoDB modules. I ended up using the Dynasty module, which has a nice promise based approach. I found a few surprises along the way working with DynamoDB, but everything is running smoothly now, with emojination using it for both read and write operations.

The end result is there is now a botkit-storage-dynamodb module available for all who are interested in using DynamoDB with their Botkit based bot. A small contribution that has helped me learn quite a bit in a short period of time. ❤️

One little problem setting up Cloudflare SSL via cPanel for a site

I’m not going to give a full tutorial on how to setup Cloudflare SSL for a web site using cPanel for its hosting management. There are better resources for that. However, I did run into an issue that took me a while to track down and I wanted to capture that here in hopes that it saves someone else some time.

I had everything setup on the Cloudflare side and added the keys to cPanel for my domain but received the following error:

The system did not find the Certificate Authority Bundle that matches this certificate

There was a spot in the cPanel SSL setup page for adding the CA Bundle but my Google searches weren’t returning what I needed. Somewhere along the way I finally ran into my answer, which can be found at this Cloudflare support page. Once I added the Cloudflare root certificate from that support page, my site was enabled to serve up pages via HTTPS.

Note: I setup another domain for SSL via this same setup and didn’t have to enter the Cloudflare root certificate again.

Calling a Slack Web API method from a slash command app

I’m currently trying to build a little Slack app. The (Botkit based) app is a “slash command” that also needs access to the team and user info Slack web API methods.

I ran into a problem where I needed an access token that Botkit stores in its users object store. The issue is that when I need to use the access token to call the Slack web API methods, I need to find that token. I wanted to lookup that access token via the team_id that is passed in through the slash command message, but I couldn’t if the token is in the users object store, with the install user’s ID as the key.

Here is an example of what I had in the Botkit users and teams object stores after a user installed my app:

botkit:store:teams
{"id":"T1DDTABCD","createdBy":"U1DDKABCD","url":"https://someslackteam.slack.com/","name":"slack-team-name"}

botkit:store:users
{"id":"U1DDKABCD","access_token":"xoxp-49999999999-49999999999-59999999999-7e05d2266c","scopes":["identify","commands"],"team_id":"T1DDTABCD","user":"johndoe"}

When my app gets a message, it doesn’t have access to the install user’s ID, but it does have the team ID. I needed to pass in that “access_token” for the web API calls like this:

var token = ''; //Need the access token
var options = {
  user: message.user,
  token: token
}

bot.api.users.info(options, function (err, response) {
            var user = response.user;
            var username = user.name;
});

My workaround was to get the access_token from the install user during the install process and store it with the team. This is what that code looks like:

controller.setupWebserver(process.env.PORT, function(err, webserver) {

  controller.createWebhookEndpoints(controller.webserver);

  // Used for app install url/login
  controller.createOauthEndpoints(controller.webserver, function(err, req, res) {
    if (err) {
      res.status(500).send('ERROR: ' + err);
    } else {

      // Need to store the user access_token with the team for easy access later
      var teamID = req.identity.team_id;
      var userID = req.identity.user_id;
      controller.storage.users.get(userID, function(err, user) {
          var token = user.access_token;
          if (err) {
              console.error('users get err: ' + err);
          }
          controller.storage.teams.get(teamID, function (err, team) {
              if (err) {
                  console.error('teams get error: ' + err);
              }
              team.access_token = token;
              controller.storage.teams.save(team, function(err) {
                  if (err) {
                      console.error('teams save err: ' + err);
                  }
              });
          });
      });
      res.send(templates.appInstallSuccess);
    }
  });
});

That happens once during install and adds the access token to the teams record:

botkit:store:teams
{"id":"T1DDTABCD","createdBy":"U1DDKABCD","url":"https://someslackteam.slack.com/","name":"slack-team-name", "access_token":"xoxp-49999999999-49999999999-59999999999-7e05d2266c"}

botkit:store:users
{"id":"U1DDKABCD","access_token":"xoxp-49999999999-49999999999-59999999999-7e05d2266c","scopes":["identify","commands"],"team_id":"T1DDTABCD","user":"johndoe"}

I could then call the Slack web API like this:

controller.storage.teams.get(message.team_id, function(err, team) {
        var token = team.access_token;
        var options = {
            user: message.user,
            token: token
        }
        // Call users.info Slack web API to look up user info
        bot.api.users.info(options, function (err, response) {
            var user = response.user;
            var username = user.name;
});

Notice I’m calling the teams storage and passing in the message.team_id to look up the team for the user who submitted the command.

The one thing I was never told

  1. Throwing up blood
  2. Sometimes I sit and think, and sometimes I just sit
  3. Lawyer up
  4. With (more than) a little help from my friends
  5. Let’s get physical
  6. It’s just like riding a bike
  7. The one thing I was never told

 
During the last 2+ years, since being hit by a driver of an SUV while I was riding my bicycle, I was advised on a lot of things – a lot of important things. There was lots of medical and dental advice, and I’m thankful for it. There was quite a bit of legal advice, and I’m thankful for that too. But there was some advice I never received: You need to account for the mental and emotional toll.

I spent so much of my time focused on the “next step” in my recovery that I neglected the mental and emotional side of the equation. I felt “OK” – or so I thought. All attention was paid to the physical and legal components of recovery, and meanwhile, I was pushing forward on near empty without realizing it. I never saw a counselor. I never talked to anyone who asked me questions that would press me a bit beyond, “how’s your body healing?” The doctors I saw never advised me to talk to anyone or to at least be aware of some potential pitfalls beyond the physical. I’m starting to realize that all that trauma, all that stress that comes with recovering from such an event over many months, and all that pressure I put on myself to “get back to normal ASAP” has caught up to me.

I don’t write this to lay blame on anyone. I’m writing this for those who may come across this post as they struggle through their own recovery. Go talk to a counselor. Go talk to someone who will ask questions that friends and family aren’t likely to ask because they don’t even know to ask them. Acknowledge the struggle is beyond what you feel physically, the endless appointments, the non-stop focus on getting back to “normal”. You likely won’t even realize you need to talk to someone, but you do.


I’m capturing my journey towards recovery after being hit by an SUV while riding my bicycle on February 8th, 2014. I’ve learned quite a bit along the way and want to share those lessons. I’m not a doctor, lawyer, or any other sort of expert in this area. Any insights I provide along the way should be taken as my insights to my particular situation. In other words, seek professional counsel if you find yourself in similar circumstances. See more here.

It’s just like riding a bike

  1. Throwing up blood
  2. Sometimes I sit and think, and sometimes I just sit
  3. Lawyer up
  4. With (more than) a little help from my friends
  5. Let’s get physical
  6. It’s just like riding a bike
  7. The one thing I was never told

 
The most popular (and annoying) question I was asked shortly after being hit by an SUV while riding my bicycle was whether I was going to ride my bike again. My wife was asked that question too – a lot. I think she hated the question more than I did. My response was often made with a sly smile and then something not so clever like, “If you were in a car crash, would you drive again?” I wanted to ride again ASAP. My wife was slightly less enthusiastic. She’s the one who got the call that I had been hit by an SUV. She’s the one who saw me battered and bloodied in the ER. She’s the one who had to deal with picking up the pieces for months afterwards. I didn’t care what anyone else thought about me riding again except my wife. If she really (REALLY) didn’t want me to ride again, I would stop. We talked about it and eventually came to the agreement that I would ride, even though she wasn’t going to ever love the idea. To this day, I text her before every ride, letting her know where I’m riding and about how long I think it’ll take. If she’s away from the house, then I also text her when I get back. If I don’t send those text messages – I’m in trouble – big trouble.

I don’t remember a thing about getting hit. Doctors have told me it’s best that I don’t remember, otherwise I’d likely experience PTSD symptoms of some sort. I didn’t have any fear of riding with traffic. What I did have hesitation about was riding in quieter neighborhoods with lots of side streets entering from my right, similar to the place where I got hit. My first time back on the saddle was Thursday, April 17, 2014 – a commute to and from work. My body didn’t feel too good, but mentally and emotionally it was great to be back out there. I didn’t ride a lot in those early days. My physical therapist said it was fine to ride (he was also a fellow cyclist), but to not over do it. He said being in that riding position was going to be a bit painful for a while. He was right. My neck bothered me the most, but my shoulders and left wrist also didn’t feel too good early on either. I eased back into riding. I was happy to be able to ride at all, especially only a little over two months after being hit.

Continue reading “It’s just like riding a bike”

Let’s get physical

  1. Throwing up blood
  2. Sometimes I sit and think, and sometimes I just sit
  3. Lawyer up
  4. With (more than) a little help from my friends
  5. Let’s get physical
  6. It’s just like riding a bike
  7. The one thing I was never told

 

I had to wait to start physical therapy until the cast on my left wrist came off. That took a little over six weeks. I needed physical therapy mainly for my wrist, my left (fractured) clavicle, and right separated shoulder. My neck went along for the ride, though it probably gave me the most problems through the year (2014) I got hit. It didn’t feel “normal” until the end of 2014, maybe the start of 2015. Looking back, I should’ve pushed hard on the doctors to do something about my neck. Lesson learned.

Physical therapy (PT) was a pretty foreign concept for me. I remember spending a brief amount of time in high school getting my knees looked at due to tendonitis, but there wasn’t much “physical” there aside from some ultra sound sessions. In total, I did about eight weeks of PT, with each week including three 1.5 hour session days. Each early morning session started the same: heat, ultra sound on my wrist and both shoulders, and then stretches with the physical therapist. From there I would head over to the fitness area of the facility and do the equivalent of riding a bike with my hands. I’d crank away with my arms for ten minutes before starting any exercises. I felt like a real pro.

Continue reading “Let’s get physical”

With (more than) a little help from my friends

  1. Throwing up blood
  2. Sometimes I sit and think, and sometimes I just sit
  3. Lawyer up
  4. With (more than) a little help from my friends
  5. Let’s get physical
  6. It’s just like riding a bike
  7. The one thing I was never told

I like to think that I’m in control of much more than I am. Getting hit by that SUV while riding my bike and having to recover from that has been a harsh reminder of how little control I have. It’s also been a reminder of how thankful I am to have people in my life who care about and for me. Below are just some of the people who helped me during a great time of need.

My wife has probably suffered through this more than me. She had to see me shortly after I got hit, covered in blood, laying on an hospital ER bed, looking like a zombie. She was the one who drove me to endless doctor and dentist appointments. While most people didn’t see me much for a month after being hit, my wife saw me everyday and did her best to get me anything she could to help me. She had to answer the endless questions about how I was doing, what the status of “our case” was, etc. After a while, it all wears you down. Through it all, my wife, Kelly, was there for me and continues to be there for me, even as I know I wreck her nerves by continuing to ride my bicycle. I love her very much.

The king of hurt
Special thanks to my daughter who gave me the title of “The king of hurt” during the early days of my recovery.

There were numerous people from Zappos who went above and beyond to help me and my family during our time of need. There were Rachel and Susan who took our kids out for the day to have some fun. There were numerous people who provided meals. Others provided cards and other gifts to help cheer me up. A number of people stepped up and filled in to handle my absence at work. There is one person who stands out most of all, Mr. Ken. Yes, Mr. Ken. His name comes after he told some of us a story where he was on vacation and all the hotel staff called him, “Mr. Ken.” The name stuck. Mr. Ken came to the hospital and got the honor of watching me puke blood into a bucket. He visited later on when (honestly), I didn’t feel like seeing anyone, but was really happy to see him. He checked in on me, got my computer for me, kept me in the loop on stuff going on at work. He made sure I knew that if I needed anything, anything at all, he was there for me. Many thanks to Mr. Ken for all his support and help along the way.

Last, but not least, I need to thank those from our church, Spring Meadows Presbyterian, who provided meals, prayer and some practical advice along the way. While I didn’t eat much during that time, my family did and every meal that was provided was one less thing my wife had to deal with.

I had a lot of help along the way. I am truly thankful.


I’m capturing my journey towards recovery after being hit by an SUV while riding my bicycle on February 8th, 2014. I’ve learned quite a bit along the way and want to share those lessons. I’m not a doctor, lawyer, or any other sort of expert in this area. Any insights I provide along the way should be taken as my insights to my particular situation. In other words, seek professional counsel if you find yourself in similar circumstances. See more here.

Lawyer up

  1. Throwing up blood
  2. Sometimes I sit and think, and sometimes I just sit
  3. Lawyer up
  4. With (more than) a little help from my friends
  5. Let’s get physical
  6. It’s just like riding a bike
  7. The one thing I was never told

 Spoiler alert – My case is all settled. That is why I’ve been able to publish these posts. It took from February 8, 2014 (when I was hit) until November 24, 2015 for the last paper to be signed and check to be cut. With that out of the way, be prepared for a lot of words on this topic.

It’s inevitable. It’s days after you’ve been hit by a vehicle while riding your bicycle and you’re feeling terrible. The days pass and the talk turns to, “When are you getting a lawyer?” My first response to that question was, “I’m not sure I want or need one.” I then began talking to people with more experience (some) with these sorts of things than I had (none) and it became apparent to me that I wanted to get a lawyer.

lwyrup

I didn’t want to have to deal with figuring out how to negotiate with insurance company lawyers (who do this for a living) while also spending months recovering. I also didn’t want my wife to deal with that stress on top of an already stressful time for her. The driver’s insurance company was already calling and wanting to settle. Even with no expertise, I knew it was laughable to talk about a settlement when so little was known about the full extent of my injuries. I spoke with a (corporate) lawyer for advice on getting a personal injury lawyer to represent me and his main advice came in the form of questions, “Do you think you can get at least a third more with a lawyer involved? And do you think he’ll do that with a lot less headaches for you?” The questions were valid. First, you need reasons to think you’ll get at least a third more in the settlement with the lawyer than without. If you don’t, you could be in trouble. I hear about people getting a lawyer for a relatively minor car crash. The lawyer does a good job, but doesn’t get a third more than what the individual would’ve gotten on her own. In some cases, this can mean the individual pays out-of-pocket for some of the expense of the crash. For example, the total costs of a crash are $5,000 – property, personal injury, etc. The lawyer ends up getting a settlement for $6,000. After the lawyer takes his cut, the individual has $3,960 from the payout. The only way a lawyer even begins to make sense in that case is if the settlements is for at least $7,600.

Continue reading “Lawyer up”

Sometimes I sit and think, and sometimes I just sit

  1. Throwing up blood
  2. Sometimes I sit and think, and sometimes I just sit
  3. Lawyer up
  4. With (more than) a little help from my friends
  5. Let’s get physical
  6. It’s just like riding a bike
  7. The one thing I was never told

 

What I looked like several days after being hit by an SUV while riding my bicycle

I vaguely recall gingerly walking from the garage to our upstairs family room the day after I was hit by an SUV while riding my bicycle. My body was so bruised from the waist up, it hurt to move – at all. Since my left clavicle was fractured and my right shoulder was separated (though I didn’t realize it at the time), I could only lay down on my back without crying out in pain. I parked myself on the couch recliner and tried not to think of how bad everything hurt.

Since my mouth was in a state of disrepair, it hurt to eat. I was taking pain medication that generally made my stomach match the pain I felt through the rest of my upper body. I gave up on the pain meds. I tried to eat, but my appetite was lost because of the pain from eating. I lost about 15 pounds the first month.

I went to see the doctor about my wrist. He put a cast on it and told me to come back in a month. I saw my dentist and then an oral surgeon to determine how bad my mouth really was. I could tell by the looks on their faces that it wasn’t good. The oral surgeon found the fracture in my upper jaw. He and the dentist wanted to let my teeth settle for another week or two in order to see if the remaining top front teeth would survive. I was warned then that no matter what the plan of action was, it would take a while to heal and have everything back to “normal”. I had no idea how accurate those warnings were at the time.

The most painful event I remember during the first week was trying to change my shirt. Lifting my arms anywhere close to above my shoulders hurt so bad that it brought tears to my eyes. I was determined to change my own shirt. I eventually got my shirt off, but not without a frightening popping noise from one of my shoulders and a yelp followed by more tears. Regardless, I stood there proud that I did the seemingly impossible – taking off my own shirt. It was then that I determined I would wear a consistent uniform of tank tops and full zip hoodies for the foreseeable future. I expect this to become a fashion trend in Silicon Valley any day now.

The days drifted into one another. I was waiting. Waiting for my body to heal. Waiting to see how bad the damage to my mouth really was. Waiting for the day when I could walk without feeling every step sending jolts through my chest, to my shoulders, piercing my neck.

The first week was a haze. I had no expectation of when I would feel better. I only knew how awful I felt. I think it’s important to capture that here as a reminder to myself and for others who might be going through a similar situation. No big lesson other than it hurts and there’s not much you can do about it other than to be patient as you lay there hoping the pain goes away. It does – eventually.

The title of this post comes shamelessly from Courtney Barnett’s pretty fantastic album of the same title.


 

I’m capturing my journey towards recovery after being hit by an SUV while riding my bicycle on February 8th, 2014. I’ve learned quite a bit along the way and want to share those lessons. I’m not a doctor, lawyer, or any other sort of expert in this area. Any insights I provide along the way should be taken as my insights to my particular situation. In other words, seek professional counsel if you find yourself in similar circumstances. See more here.