Bubble Talks by BubbleIQ

Building a Drift App Part 2: Drift Chat NPM, Slash Commands & Contacts API

Tristan RubadeauTristan Rubadeau

Building a Drift App Part 2: Drift Chat NPM, Slash Commands & Contacts API

We’re continuing to learn about the Drift developer platform as we build out our Drift<->Zendesk integration. Last week we did a basic tutorial on receiving your first event from the Drift API.

We’re building our bot using Node, and we figured we were going to be building lots of javascript wrappers around the Drift API, which would be great to share with the community as an open source NPM module: Drift-Chat NPM

To install the NPM package, just do:

npm install drift-chat --save

Have features, ideas, or issues using the NPM module? Submit an issue to Github. We’d also love some help from the community building this out to support the entire API.

This week, we’re getting into some of the finer details of the Drift platform. We want to be able to trigger our script based on a specific command in Drift, and have it look up the details of the user in the Drift chat.

Receiving slash commands

Slash commands are a popular way in many modern chat tools for users to trigger Bots or other Apps to execute a command.  In the Drift use case, we see Agents using these commands to start a workflow interaction with a Bot.

In the example below, we are using .startsWith() to match the beginning of a new message to see if it is a slash command. The program will disregard any other messages you and the contact have in the convo.

Pinging the Contacts API

After the ‘new_message’ matches the conditional slash command to start the Bot interaction, we want to get the details of the user who is chatting on the website through Drift. The Drift developer platform identifies end users as “Contacts.”

We need to do a few things to set up the API call to Drift:  

  1. Pass in an OAuth token when using the Drift Constructor function.  You will need your token from the Drift Dev Portal
  2. Refer to the Drift Chat NPM documentation for usage of functions, but to use .getContact() you just need to pass in the id of a contact.



Head over to the Drift website client and imitate a contact.  Make a message that starts with /yourslash command.  You are imitating a new website visitor so don’t use your agent email.

Back in your terminal, you should be able to see the output of the User Object for the Contact.  Drift has enriched the email with lots of helpful identity resolution data and social media accounts associated with the Contact.  Well wasn’t that nice of em!


You should now be able to trigger a script based on words in the Drift message, and lookup details about the Contact in that Drift conversation.

That’s all for this week. Next, we will look at the Conversations API!

Get part 3 in your inbox!