A Better Slack Bot for HubSpot

Hero Image

Integrating Slack and HubSpot can be difficult for developers.

HubSpot has an built-in bot for Slack , but sometimes the built-in bot capabilities aren't flexible enough for developers..

In this blog post, you will learn how to code a Slack bot that responds to a specific command and returns the information you need from HubSpot, giving you full control of what data is fetched and how it is displayed.

What could you do with this integration?

Let’s say that you would like to get information about your users by running just one command in Slack. For example, if you run “lookup user@email.com” on Slack and receive relevant information about that user from HubSpot.

Let’s see the integration in action!

Slack Bot in HubSpot

One item to note about the “lookup” keyword is that it can be placed anywhere on a slack message. If you are having a conversation with a team member, you can say for example “Hey @user2 can you please reach out to customer Acme, here's the contact info lookup acme@email.com”, the team member will receive the information needed from that user.

Try it out now!

  1. Install the bot for free.

  2. You will need to authorize access to your HubSpot instance and Slack workspace.

  3. Add the bot to a Slack channel, by clicking the drop-down next to the channel name, clicking Integrations, and then selecting Add an App and then finding “HubSpot Bot”.

  4. Type the “lookup” command followed by the email address of a HubSpot contact, for example “lookup joe@example.com”.

Once you have the example running, you may wish to customize it to your needs, including modifying HubSpot search or how the data is displayed. Read on to learn how.

Create New Integration

First, sign up to Fusebit for free.

Click on the HubSpot Slack Bot integration. You can customize the Slack and HubSpot connector name. Click on “Create”.

HubSpot Slack Bot

You can edit the code of the Integration by hitting the Edit button in the middle.

Edit Integration

Test the Integration

We can invoke the test method of this integration right from inside the editor to see how this works, but we first need to configure a test request passing the HubSpot email to look up:

Configuration slack bot

In the Payload section, add the email you want to look for in JSON format.

Configure Runner

You will need to authenticate before being able to successfully run this integration. Choose a HubSpot account and authorize Fusebit to connect to it.

Authenticate HubSpot

You will also need to authorize access to a Slack workspace, so you can see the results of the HubSpot search.

Authenticate Slack

You are now ready to hit Run to try it out!

Run Integration

Once you have authorized HubSpot to connect with Fusebit, you will see the contact you configured in the Run button retrieved and its details shown in the Console output.

Console output

You should also see a message in Slack with the search result.

Final Output

hubspotClient and slackClient in line 10 and 11 create pre-configured clients with credentials necessary to communicate with your HubSpot and Slack account. The lookupAndPost function in line 13 will look for the email you provided on slack and create a contact.

Feel free to modify the hubSpotClient.crm.contacts.searchApi.doSearch (line 54) and slackClient.chat.postMessage (line 65) calls in the lookupAndPost method to customize what your bot does. If you want to have custom properties, you can change it in the line 40 in properties.

Enabling search from Slack

So far we’ve tested this integration from inside Fusebit using the Run button. However we really want to be able to start the search from inside Slack by sending a “lookup” command.

  1. In the Fusebit portal, select the Slack connector. You will need to create your own Slack application to be able to receive Slack events. Follow our developer guide to see how.
  2. You will need to go to the integration Installs tab and delete any existing installs after you switch over to your own Slack application, and you will have to re-authenticate.
  3. When a message is received from Slack, the integration.event.on on line 21 is invoked to receive the data. In line 28 we have a regex which will extract the email from the information received from Slack ("lookup mailto:contact@fusebit.io|contact@fusebit.io"), if there is a result, it will look up that email and post it in the Slack channel. Modify this logic to change the command the bot responds to or to collect additional parameters.
  4. Don’t forget to make sure the bot is added to the Slack channel where you are sending commands, otherwise your events will not be received.

Before you go…

If you are looking to create flexible and powerful integrations using other SaaS platforms, check out Fusebit, and follow us on Twitter!


Most Recent

15 September 2022
What Is Deno and Why You Should Try It

Learn the basics of what the Deno runtime environment is all about, and highlight the key features, benefits, and detractions.

1 September 2022
How to Implement GitHub OAuth in Your Node.js App

OAuth is a standard protocol used for authorization. This post will discuss implementing GitHub OAuth in your Node.js app.

31 August 2022
QuickBooks OAuth: How to Set up the Online Accounting API in Your Web App

Intuit uses OAuth2 to authorize applications for access to company data. Here's how to use their library to authorize your Node app.