Chameleon: the Swift Slack bot — Persistence with Redis

Giving Chameleon a Redis brain!

Note: This article/series is deprecated, There has been a lot of changes in the Chameleon framework. I will produce a new set of articles soon.. sorry for not completing this series.


Last time we went through setting up your first Swift Slack bot and deploying on Heroku. This leaves our bot with only memory based storage. Which means that if our bot ever shuts down we will lose any data we had. Luckily Chameleon comes with support for Redis, we just need to hook everything up!

Installing Redis on Heroku

Heroku provides a Redis add-on with a free tier, this will become the storage our bot will use. Get started by heading over to your Heroku dashboard and go into the app for your bot.

Under the Overview tab you can view your installed add-ons. Tap on Configure Add-ons:

On the next screen you are able to search for add-ons. Search for redis and select Heroku Redis from the list of results:

Select the Hobby Dev option and then Provision:

You will see that Heroku Redis is now in your list of add-ons!.

Setting up the variables

Now that you have provisioned Redis, head over to the Settings tab and tap on Reveal Config Vars you will see you now have a value for REDIS_URL. Create a new key named STORAGE_URL and use the value from REDIS_URL:

Updating Chameleon

Now that we have everything setup on Heroku we need to update our bots code to use the new Redis storage. Currently our bot looks like this:

There’s a fair bit of work to get the bot to use Redis instead of memory, I’ll go through it step by step:

aaaand done! 😄

Next Time… fun stuff!

So far we’ve built and deployed our bot, now it has a brain… next time we will get to know the Chameleon API by building a basic karma service!

If you’re enjoying the project and these articles feel free to recommend or retweet! 😄

You can catch me on Twitter and iOS Developers.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.