Tools & Technology

Chatbot or Human? Yes.

Chatbots are transforming customer service. They are available to customers 24/7 and can quickly respond to a wide range of inquiries. However, there are some times when human intervention is necessary to resolve a customer issue. Enter Megatron, an open-source service we built that allows teams to take over a DM between Teampay and a customer when they have a question the Slack bot can’t answer. This happens from within your existing Slack app; there’s nothing more your customers need to install or authorize, and you don’t have to use any new, external tools.

Here’s a quick example of how it works:

  1. Phil, a customer, gets stuck trying to talk to your bot.
  2. Jane, your customer service rep, asks Megatron to connect to Phil. Megatron opens a channel on your Slack workspace. This channel immediately imports the conversation between Phil and your Slack bot.
  3. Jane pauses the bot and responds to Phil in the new channel, e.g “Hi Phil. I see you’re having some trouble make a purchase. I’m here to help!”
  4. Phil receives that message on his own Slack team from the bot he was just talking to.
  5. Phil and Jane continue speaking across two different Slack workspaces until the issue is resolved and Jane closes the channel, unpausing Phil’s bot. It’s that easy.

Here, we’ll take you on a short tour of three of the Slack features that make Megatron powerful and easy to use:

  1. Slack authorization tokens
  2. The ability to replicate a Slack conversation
  3. Pausing and unpausing your bot

Connecting to teams via Slack tokens

Slack tokens are how Slack understands the permissions granted to your app. If you have installed a Slack app, you’ve already used them. Megatron leverages two types of tokens: User and Bot user.

User tokens represent workspace members. Bot user tokens represent a bot associated with the app installed in a workspace.

Our use of the User token is mostly unexciting: Megatron is installed as a new app on your team and asks for permissions to watch channels, forward messages to users, and add some slash commands. Regular Slack app stuff here.

Bot user tokens give us a lot more flexibility since, if you have an existing bot, they’re already connected to your customer’s team. Once you have the bot user token, you have control of that bot. We don’t need to reauthorize Megatron with a customer’s team. This is a big deal and one of the key pillars of Megatron; Megatron is simply your existing bot.

Obviously, do not share your bot token outside of services you control, and make sure that any communication between your apps encrypts your token.

Replicating customer conversations

When you need to provide support in a hurry, you don’t want to query a database to retrieve JSON records of previous messages and translate those into visual representations; you want to know what went wrong immediately. Existing solutions didn’t allow us to see exactly what the customer was experiencing when speaking to the bot. Megatron lets us watch a perfect recreation of a customer’s conversation with the bot in real time. Let’s walk through the process.

  1. Install Megatron and begin POSTing incoming messages (from the user) and outgoing messages (from your bot) to your Megatron service. Initially, Megatron will just discard most messages immediately since you haven’t told it which to watch for.
  2. Tell Megatron to start watching a user’s channel with a simple slash command, /megatron open <users's name>. We’ve added some neat features to help you find exactly who you’re looking for, but for now let’s assume you got it right on your first try.
  3. Megatron uses conversations.create to create a new channel on your team that references the customer’s name – something like “#CS-JohnCustomer” – which makes it easier to locate the support channel if you need it again.
  4. To show where the customer ran into trouble, Megatron uses im.history to grab the last few messages from the DM channel and posts them into the new “#CS-JohnCustomer” channel. Because both ends of this exchange are in Slack, we’re able accurately copy the customer’s DMs, including formatting.
  5. Now that the channel is open, Megatron starts to watch for and then post messages (via chat.postMessage) between the bot and the customer to the “CS-JohnCustomer” channel.
  6. For each POST message call, we change the username and user image of each message received by editing icon_url and username to match either the customer or the chatbot. It looks like your customer is having a conversation with your bot right in your Slack workspace, but it’s all Megatron.

Megatron can also communicate with the customer as the installed bot. Once a channel has been opened, Megatron begins to watch for new messages in that channel via the Slack events API, specifically the event. When Megatron sees a new message in that channel, it alerts your app, allowing you to send it directly to your own bot’s post_message method. Since you’re sending the message via your bot, the effect is seamless.

Report Download:

How Netflix Navigated the Recession 

    Pausing and unpausing

    With customer service reps jumping in and out of your bots, it’s vital that you’re able to pause and unpause them. Otherwise, you and the bot would trip over each other trying to respond to the customer’s latest message.

    Megatron exposes a simple slash command for /megatron pause <customer>and /megatron unpause <customer>. In a support channel, you can drop the <customer> parameter since Megatron assumes you want to pause the user you’re currently speaking to.

    The implementation for this is pretty simple, but powerful. Megatron sends your app a POST request to an endpoint of your choosing containing the newly paused channel_id. Then, your main bot can flip the record for that channel over to “paused,” and start discarding messages from Slack for that channel. While your main bot app is now paused, your Megatron app doesn’t change anything for paused channels: we still want Megatron to watch for and pass through new messages.

    We wanted to be sure our team remembered to pause and unpause as needed. Here are some design tricks that Megatron uses to encourage correct pausing behavior:

    • Megatron will remind you to pause if you start speaking to a customer with a still-active bot.
    • Megatron will remind you to unpause after about three minutes of idle time in a channel.
    • Megatron will automatically unpause bots for customers whose channels you archive with /megatron close.

    What’s next for Megatron?

    Megatron is fully open-source and you can start using it or contributing to it today! It is in active development at Teampay. We’re adding new features and fixes daily.

    Feel free to reach out to Preston Hale, Software Engineer at Teampay, at with any questions or comments.