SparkPost has some awesome functionality, including the ability to receive email through webhooks. Whenever I’ve seen anything built with inbound email it’s always required sending an email back, whether the tool collected data or added songs to a spotify playlist. I thought it would be fun to take the SparkPost API one step further and fuse *ahem* the abilities to send and receive email, ie email chatbots. And thus, Fuse-email.

What is it?

Anyone familiar with chatbots has probably used or heard of Botkit. At its core, it’s a wrapper around several bot APIs to make it easy to get chatbots up and running. Fuse-email is a library written in Node.js, with the same goal but for email chatbots. It could be used to build something like, or anything else really. So let’s build something!

What to build…

Let’s build a basic email bot that helps you send a postcard to the White House. There are troves of cool APIs out there, including a favorite of mine called Lob which is like SparkPost but for physical mail. They have an API for sending postcards, letters, and checks.

When designing a new bot, I always like to start by writing a script for how I believe the bot should respond. Our bot should have the following conversation:

  • Me: Let’s send a card to the White House
  • Bot: Ok, what message should your postcard have?
  • Me: Hello there!
  • Bot: Got it 🙂 What image should we put on the postcard?
  • Me: <some attached file>
  • Bot: Sweet! We’ll send that off for you. Here is a link to the card preview <some link>.

The Setup

Getting set up is pretty straight forward. First, we’ll need a SparkPost account. We will also need to add a sending domain and an inbound domain.

Once we have those things set up it’s time to start writing our bot. Let’s start a project and grab the fuse-email framework:

We then want to configure it to start developing:

I’m going to set this up for local development. Because SparkPost needs to have a URL to pass the inbound email to via relay webhooks, I’ll use ngrok which will expose my localhost at a specific port to the outside world. Fuse has a function called setupTransport that will verify whether our SparkPost sending and inbound domains are correctly set up, and then create a relay webhook targeting the endpoint on the given domain as provided in the options.

Now we can write the setupServer function to use the shortcut methods from Fuse to set up the server and endpoint:

Building the Bot

After we set up the server, we called the setupTheConversation  function. Let’s build that out. Here we can add a listener to Fuse that will start the conversation when it “hears” or matches the pattern in the email subject or body. Let’s listen for any of the following keywords: 'postcard', 'card', 'start', 'send' . Now if we send a message with the body or subject that contains any of these words, we will start the process of sending a postcard.

Next we need to define the function startSending , which will kick off our conversation. We’ll add a postcard key to the convo as a way to store the user’s responses.

The getMessage function will be called when they respond with the message for the postcard. Fuse has a few helper methods to pull out their response. We’ll use fuse.getLatest to get their response to the question and fuse.clean to strip out any html or extra whitespace from the message.

Following the same pattern we can define the getImage function in order to pull out the image the user sent us. We need to call convo.wait() to keep the conversation alive while we do some async work with the Lob API.

Finally, we want to create the sendTheCard function. This will end the bot conversation with a link to the preview that Lob has created for us.

And that’s it! We’ve created an email bot that will send postcards to the White House. You can view a preview of a postcard here. Interested in the code? Feel free to fork the repo or submit a pull request. Leave a comment below or come chat in our Community Slack — I’d love to hear what you build.

Avi Goldman


Howdy there! You and I have talked before about how we build Slack bots at SparkPost, but I didn’t say much about how we use them. We use bots at SparkPost to do all sorts of things. We’ve learned a lot and I thought now would be a good time to share some of that with you. I love bots, you love bots, so let’s turn the lights down, light a few candles and have a nice glass of your favorite beverage over some bot talk.

How we use slack bots to stay productive people connected via slack

How We’re Using Slack Bots to Maximize Productivity

Like I said, we use Slack bots for a lot of things. We run our standups with bots, we use them to get links to our docs, to post sample data from our endpoints, and to encourage each other. We do internal reporting and monitoring from bots. We track the status of our deploys along with any new PRs and issues on our Github repos all from Slack.

Why do we use bots for all these things? I mean, there are other tools that do almost each one of the things we use bots for. Well, that’s the thing: there’s at least one tool for each of those things. Our Slack bots consolidate everything into one place and one interface.

There are some advantages to using Slack as that central platform for us at SparkPost. First, since we’re a distributed team, Slack has become lingua franca – it’s our primary communication tool – so everyone is comfortable with it. Slack access doesn’t require any special VPN connections (though you should set up two-factor auth for safety). It’s accessible on mobile devices so we can make API calls from just about anywhere. We make our Slack bots easy to use for non-technical people so they don’t have to use developer tools like cURL or Postman.

Basically, since we’re already in Slack on a regular basis, it’s easier and faster to simply perform as many of our everyday tasks from there as possible. Not only does it mean fewer steps to complete something, but we also don’t have to leave the interface where we’re already spending a lot of time. Just repeat this over and over with me:


Botify All the Things!

So how do you choose what to add to your bot? Be on the lookout for things that are inconvenient or painful. Start with the things you do a lot. For example, in our community Slack team we found we spent a lot of time tracking down links to our docs: we’d open a browser, go to the docs page, search for the right resource, copy the link, go back to Slack… It was just awkward. And in that time the conversation would often have moved on. Now we have a single command that will give us a link to the resource our users need when they need it.

Do you have something that only you can do because you’re the only one technical enough? Bam! Slack bot! Or do you want to empower your team to do things on their own? Botify it! Want to let new users know what’s up when they join your Slack team? Bot time! You get the picture. It’s open-ended, the only limits are your creativity and a few pesky natural laws.

How to Succeed at Bots Without Really Trying

Ok, you have this awesome idea for this bot that is going to save you time and frustration and probably the world. You set up a repo and a sweet continuous deployment pipeline for easy deployments. You’ve got 100% test coverage, the build is green. But nobody is using it. Nobody? Seriously? Yep, nobody.

Remember, bots are an interface, just like a web page. And just like any web site they can be hard to use or unintuitive or just plain off-putting. Bots have the extra challenge of being a pure text interface to your code and code is rigid and brittle. But human language is fluid and nuanced and weird. So when you build your bot be creative, funny, and offbeat. Find that unique voice inside of you and channel it into your bot. That helps offset your bot’s rigidity (and even make it endearing!).

Making your bot enjoyable goes a long way to getting users to engage with them. We’ve also found a lot of success by including help text for every command. The skellington library we use for our bots makes help text a first-class citizen and makes it easy to add help messages. The easier and more fun you make the bot to use, the more people will use it!

If you use Slack or some other chat program, bots are a great way to empower your team and make rote tasks easier. Make your bots useful, interesting, and entertaining (in that order) and before you know it your bots will take over the world! Ok, not the world but at least the hearts of your users.

– Cole Furfaro-Strode

We’d love to hear how you’re using bots! Either post a comment below, or come find us in our Community Slack channel.

we love developers