If your organization is using Slack, you may already be automating tasks and enabling more efficient business processes with Slackbots. Using the integrator.io platform, you can integrate with Slackbots to send and retrieve data between Slack and other applications.
In this tutorial, we explain how to set up a flow so that people in your organization (such as the sales team) can request and obtain customer information directly from a Slack channel. In this scenario, customer data is managed in Salesforce.
Contents
- I. Build and connect a Slackbot to an integrator.io webhook listener
- A. Build a Slackbot
- B. Build a new flow with a Slack webhook listener
- C. Configure the /getcustomer command for the Slackbot
- D. Install the Slack app to your workspace
- II. Create a lookup to retrieve customer data
- III. Build and configure the import step to send results to Slack
- IV. Try it out
- V. Experiment
I. Build and connect a Slackbot to an integrator.io webhook listener
To get started, we will use Slack API management interface to build a Slackbot within a new Slack app. Then, we’ll create the corresponding webhook listener in integrator.io, configure the command that our sales team users will be able to use in Slack, and install the Slack app to the workspace to make it available to them.
A. Build a Slackbot
- Open the Slack API management interface.
- Click Click New App. For App Name, enter Get customer details.
- Confirm the workspace is correct and click Create App.
Many settings and features are available for the new app. Our next step in the Slackbot configuration is to create the /getcustomer command that our salespeople will enter in Slack when they want to retrieve customer details. We’ll need a Request URL for that command, so we’ll switch over to integrator.io first and create a Slack webhook listener as the first step in our flow. Since integrator.io will need a Signing Secret from Slack, we’ll take a moment to copy that value to the clipboard. - Under the Basic information settings, locate the Signing Secret. Click Show to display the value. Then copy it to the clipboard.
B. Build a new flow with a Slack webhook listener
In integrator.io, we’ll start by building a new flow with a webhook listener to receive the request from the Slackbot.
- Navigate to Flow Builder and click Add source.
- On the Create source page, select Slack from the application list. Then, under What would you like to do? select Listen for real-time data from source application.
- Click Next.
- On the Create listener page, enter a Name and Description.
- Next, paste the Signing Secret.
- Click Generate URL. When the new URL appears, click Copy URL.
- Click Save & close.
- The new flow appears with the Slack listener displayed. Click New flow at the top of the page and change it to a meaningful name, such as Slack – Salesforce customer details.
C. Configure the /getcustomer command for the Slackbot
Now, we return to the Slackbot configuration to configure the command our sales team will use.
- Navigate to Slash Commands and click Create New Command.
- Create the command with the following configuration:
- Command – /getcustomer
- Request URL – The Public URL copied from the integrator.io listener configuration.
- Short Description – Send company name to integrator.io to retrieve details.
-
Usage Hint – [company name]
When our sales team users start entering the command in Slack, they’ll see a popup that reminds them to enter a portion of the company’s name as a search term.
- Click Save.
The new command appears in the list. Because Slack will automatically create a bot user, no additional configuration steps are required here.
D. Install the Slack app to your workspace
To connect the app to the workspace where our sales team communicates and enable them to use the Slackbot, we need to install the app.
- Navigate to the Basic Information settings and click Install to Workspace.
- Click Allow to authorize the app’s access to the workspace:
Slack then displays the OAuth token for the newly created bot user.
II. Create a lookup to retrieve customer data
At this point, we have a command available in Slack that uses a bot to send a request to integrator.io. We also have a webhook listener in integrator.io ready to receive that command. Now we need to build onto that flow to retrieve customer data based on the company name the sales team member provides. For this scenario we’ll create a lookup to get an account by company name using an existing connection to Salesforce.
- In integrator.io, navigate to the standalone flow we created earlier: Slack – Salesforce customer details.
- Click Add destination/lookup.
- On the Create destination/lookup page, select Salesforce.
- Under What would you like to do? select Lookup additional records (per record).
- For Connection, select an existing connection to Salesforce.
- Click Next.
- Enter the following information for the query, leaving other default settings as is:
- Name – Get account by company name
- Description – Query to retrieve account number and address from Salesforce for given company name
- SOQL query – SELECT AccountNumber, BillingCity, BillingCountry, BillingPostalCode, BillingState, BillingStreet, Id, Name, Phone FROM Account WHERE Name LIKE '%{{record.text}}%'
- Export type – All
- Click Save & close.
Our flow now includes two steps:
III. Build and configure the import step to send results to Slack
Next, we need to build the import (page processor) step. In addition, we’ll map and format the data before it’s sent to Slack.
A. Build the import step
- Next to Destinations & Lookups, click the + icon.
- On the Create destination/lookup page, select Slack.
- Under What would you like to do? select Import records into destination application.
- Click the + icon to create a new connection.
- Provide a Name, such as Slack connection to Sales channel.
- For Authentication Type, select OAuth 2.0.
- Click Configure scopes. For ease, click the >> button to initially select all available scopes and move them to the right side of the editor. Then, click the checkbox next to each of the scopes not necessary for this scenario: admin, files:read, files:write:user, remote_files:read, and remote_files:share. Click < to move the unnecessary scopes back to the left side.
-
- Click Save.
- On the Create Connection page, click Save & authorize.
- On the Slack authorization page, ensure the correct workspace is selected on the top right. Then, select the channel where integrator.io should post the results. For this scenario, we’re selecting the #sales channel.
-
- Click Allow.
Now that the new connection is authorized, we can finish creating the import step in the flow.
- Click Allow.
- Click Next.
- Enter the following information for the import, leaving other default settings as is:
- Name – Send results to Slack channel
- Description – Import records using chat resource
- Resource – chat
- Method – chat.postMessage
- Click Save & close. The flow now contains three steps:
B. Map the lookup results
Now, we need to map the field where the data is returned in the lookup to a field that will hold that data. We do this between the Lookup step and the Import step in our flow.
- Click the + icon within the Lookup step. Then, click the Mapping button () between the two steps.
- On the Define response mapping page, configure the following:
- Under Lookup response field, select data from the list that appears when you place your cursor in the field.
- Under Source record field, define where the data returned from the lookup should be merged back in to the source record. For this example we’ll enter lookupRecord.
-
- Click Save & close.
C. Map the import data to the Slack channel
Within the Import step, we also need to map the Slack channel and output field.
- Click the Define options button (+) within the Import step. Then, click the Import mapping button () inside the step.
-
On the Edit mapping page, the import fields for channel and text automatically appear on the right because we specified the Slack API’s chat resource and chat.postmessage method when we configured the import.
- Enter the name of the Slack channel enclosed in quotes: "#sales"
- Enter the handlebars syntax {{text}} to map the text field in our records to the Slack message.
-
- Click Save & close.
D. Format the import data with a script
When a sales team member uses the /getcustomer command, we want all records that match the company name to be returned in a format that’s easy to read. To do this for this scenario, we’ll create a hook that uses JavaScript to format the pre-map results.
- Click the + icon within the Import step. Then, click the Hook button ().
- Under the Pre map section, for Scripts, select the script to use. In this scenario, we’re selecting a previously created script called formattedFinalOutput. The code from this script is pasted below for reference:
function formattedFinalOutput (options) { var formattedText = "<@"+options.data[0].user_id +"> has requested data for *" + options.data[0].text + "*: " + "\n"; var lookups;
for (var i=0; i<options.data[0].lookupRecord.length; i++){ lookups += "==================" + "\n"; lookups += options.data[0].lookupRecord[i].Name + " (" + options.data[0].lookupRecord[i]
.AccountNumber + ")\n"; lookups += options.data[0].lookupRecord[i].Phone + "\n"; lookups += options.data[0].lookupRecord[i].BillingStreet + "\n"; } if (!lookups) lookups = '_<< None found >>_'; options.data[0].text = formattedText + lookups;
return options.data.map((d) => { return {
data: d } }) }
- For Function, enter formattedFinalOutput.
- Click Save & close.
IV. Try it out
Our flow is complete! We can turn it on in integrator.io and test it from Slack.
- Click the toggle button to enable the new flow.
- In the Slack channel where the Slackbot was installed, enter the /getcustomer command followed by the name of the company. In this example, we want to get the customer details for any company with “edge” in the name:
- A few moments after the command is sent, the results are returned:
V. Experiment
Now that you’ve learned the basics of setting up a flow through integrater.io to send and retrieve data between a Slackbot and other applications, you can experiment with adding on to this flow. For example, if you discover there is a delay for users while the information is retrieved and returned to Slack, consider adding an initial import step to provide confirmation that integrator.io received the request.
As you experiment, consider how you can apply and extend these concepts to meet your organization’s needs. Check out these articles for additional information:
Slack blog: Bringing bot interaction to a new level
Celigo.com: Connect to anything
Integrator.io: Set up an OAuth 2.0 connection to Slack
Comments
0 comments
Please sign in to leave a comment.