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:

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:

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:

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.

It’s just like riding a bike

 
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

Let’s get physical

 

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