Your first Drift Conversation Bot

Chris Buonocore
4 min readJul 3, 2018

For many businesses, Drift can be the first line of communication with a potential customer.

In your use of Drift, you may have come across a need for custom external workflows and integrations with other applications. Drift has a number of prebuilt applications, such native integrations with Salesforce as well as Zapier hooks, but if none of the current features precisely fit, we also have an API to empower you to build!

In this example, I’ll go through the process of creating an external drift application that listens in on messages within the Drift conversations view will define words when the agent enters a certain trigger phrase. I have called this app Definely.

The source code is available on github: https://github.com/Driftt/definely, though you can follow along without viewing this. I’ll also mention here that the core bot source code is under 100 lines!

The Drift API

Before I get started, a lot of what I am going to be talking about can be found in our drift API documentation. You can find this here:

https://devdocs.drift.com/docs

Creating a new App

With your drift account, log into our dev platform at http://dev.drift.com.

From here create a new application:

Creating a new drift application

Once you log in, you’ll want to define the title and description/goal for the app, as well as a logo. For our app, I created a simple logo for definely which will show up on the apps page within Drift.

We’re all set! We can now install to drift, click here to install app to your organization’s account.

Installing the Drift App to your org

After clicking this, your app token will be revealed. This will be used by the server to authenticate requests into the drift message api.

Now, if you’re following along fully, I would recommend downloading the Definely app source code and starting the server (after following the readme)— the server will run locally on port 3001 by default.

For testing, I recommend exposing this for interaction with Drift via the tool ngrok:

You can now expose your local server with the following ngrok command.

./ngrok http 3001

Take the public url of the form https://XXXXX.ngrok.io and plug into the event field — appending /api to this url as the callback route. Also be sure to set the event subscription to new_message as shown below.

Setting the callback url

Once the event subscription and callback urls are defined, you will need to add auth scopes to the app to be able to read and write to conversations. This is shown below.

If everything worked successfully, you should see your app and “Connected” visible in the My Apps view back from the main drift console.

We made an App!

Navigate to a live conversation and try it out! This is now active for your organization!

Definely in Action!

Wrapping Up

This is a simple example and you can do a lot more with our API’s such as building external integrations and pulling/inserting information into drift. We have customers that build things like CRM integrations, custom reporting tools, and external conversation management platforms. We’re continuing to build new features into the API and would love your feedback.

Next Steps:

Exposing your app to other users

For your particular use case, it might be sufficient to leave the app internal, and that’s perfectly fine. We think the real strength of building custom apps comes from sharing your creation with other users — which can not only bring awareness to your brand, but also bring new opportunities for partnerships and value.

For a public app to be accepted, it will need to meet higher quality standards and be available on either a remote server or a service such as AWS lambda (and not ngrok unfortunately), we’ll review all apps that get submitted to us.

I won’t go into detail here on submission, but the submission process is well described in our docs:

Revisiting the App Source code

https://github.com/Driftt/definely

Joining our Dev Slack

https://bit.ly/2lFhqDn

Let us know what you build or if you have any questions!

Other Examples:

Insert shareable gifs into the conversation view

https://github.com/Driftt/Driffy

Translate messages in the conversations view

https://github.com/Driftt/babel-bot

Happy Drifting.

Chris

--

--