The Traveling Slack Bot Troupe

Dennis Mellican
Chatbots Magazine
Published in
5 min readFeb 3, 2019

--

Troupe is a group of chatbots working together on a shared activity.

Troupe is a distributed chatbot program, that can be tasked to monitor and control your home. Troupe allows smart home devices to be controlled directly or indirectly via Slack. My 5-year-old uses an Amazon Dash button to toggle his bedroom light on or off. The Dash button when pressed, issues a webhook call to Slack. A Troupe chatbot answers the call. I prefer to interact directly with the home via the messaging app. Mark Zuckerberg had the same thoughts too when he was Building Javis.

Figure 1. I use Slack. Benny presses a button.

Smart Home Security

Troupe has a Watchdog service that provides intelligent lighting control along with a dog alarm. Watchdog imitates an occupied home when the motion sensor is tripped. A dog will bark (a recording played on a wireless speaker) and the lights inside and then out will switch on. Being on Slack, real-time push notifications are sent to a mobile device.

Watchdog has proven its worth in replacing my dumb security lights by deterring burglars from my property.

Video 1: Please wipe your feet before entering.

It has become too good at imitating real life. Watchdog has fooled the native wildlife but has also backfired on me a couple of times.

  • My neighbor visited, the “dog” barked and the lights switched on inside, then out. She left disappointed because we “ignored” and “hid” from her. Sorry, Jo! I later explained my 100-year-old house is automated. Jo looked confused. Next time, I’ll just say it’s haunted.
  • The “dog” barks at passing cars, pedestrians, and the postman. Typical K-9 behavior. I need to dial down the sensitivity of the motion detector to avoid a noise complaint from the next door neighbor.

The Watchdog “screenplay” is configurable, for example, you could add a sprinkler to turn on or possibly write a plugin to passively capture Bluetooth and WiFi signals for a digital signature of the intruder.

Next Level HomeOps Security

How many chatbots does it take to switch a light on?

We’re in this together.

Troupe is my personal home automation system I created out of necessity. I wasn’t content with the current Home Automation software offerings. Having a DevOps background, this heavily influenced my goals when architecting my solution:

  1. Simple architecture. My home is not an Enterprise and doesn’t have the resources or capacity (ie. a team of techies and quality hardware) of a Data Center. The fewer moving parts, the better.
  2. Highly Available. The software will be running on Raspberry Pis and other single board devices. These are susceptible to SD corruption. Redundancy will be important.
  3. Continuous Delivery. I want to confidently push updates automatically.
  4. Usability. One of my home users will be my 5-year-old son. His use case is simple: toggle a light on or off. I’ll be sticking mostly to a messaging app.

I have several Raspberry Pi’s scattered throughout the house. I wanted the chatbot to run on each of these single board computers to achieve high availability. Slack allows the same chatbot account to connect multiple times allowing it to appear as a single entity in the channel. With debug enabled, Figure 2 reveals that the HomeOps chatbot is actually three different devices.

Figure 2. With debug enabled, the Troupe of HomeOps devices are revealed.

Slack being the primary interface for the chatbots, it also provides the heavy lifting of a basic Message Queue by leveraging the Python SlackMQ library.

Diagram 1: SlackMQ workflow
  1. In diagram 1, the publisher sends Troupe a “switch the dining light on” message to a Slack channel. The chatbot devices are the workers that are subscribed to the channel. All the chatbot devices will receive the message.
  2. The first to “acknowledge” will be tasked with the job. In SlackMQ, the acknowledgment occurs by “pinning”, “starring” or “reacting” to a message. Did you notice the pinning occurring in Figure 1? In Slack, this can only happen once per message per user.
  3. As all the chatbots use the same Slack account, the other chatbot devices that try to acknowledge the message will receive an exception, complaining that it has already been pinned, starred or reacted with (ie. acknowledged)
  4. The job is actioned by the first chatbot that successfully acknowledged the message.

For the home automation use case, Slack’s restrictions and rate limits are sufficed to perform tasks within seconds of a command being issued.

By leveraging SlackMQ, Troupe becomes a distributed program. As such, we are left with a minimal technology stack, just somewhere to run the Troupe Python script and a connection to Slack. Keeping it Simple, Stupid! 💋

The Travelling DevOps Troupe

Infrastructure as code is accomplished by integrating the Troupe Git repository to Slack. The Troupe code base and settings are separate repositories respectively. Any commits pushed to the troupe-properties repository will trigger a sequence of events that will follow DevOps best practices. A commit to the code base, however, will trigger a Travis CI build. If those build tests pass, the same DevOps practices will kick off in Continuous Delivery, Canary Deployments and Rolling Updates of all connected chatbot devices. This all occurs with zero downtime. 👍

Video 2: Bringing Home all the Ops: DevOps, ChatOps, GitOps.

The Traveling Troupe Chatbot is Touring

Troupe is on GitHub: https://github.com/meltaxa/troupe. It is a work in progress and I welcome contributions for more IoT device integration.

I suspect there are opportunities for Troupe to do more than just home automation and home security.

If you have ideas, let me know.

--

--