Slack Adapters Sample

Introduction

This topic describes how to run the sample applications for the TIBCO StreamBase® Slack Adapters.

The samples, Slack.sbapp, SlackBot.sbapp and SlackRTMInputAdapter.sbapp, demonstrate how to use Slack Client Adapter to chat and interact with Slack channels. They also demonstrate how to use shared Slack Real Time Messaging Input Adapter to subscribe to certain events and send real-time messages.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, select File>Import Samples and Community Content.

  • Enter Slack to narrow the list of options.

  • Select Slack Adapter from the StreamBase Standard Adapters category.

  • Click Import Now.

StreamBase Studio creates a single project for the Slack adapter samples in your current Studio workspace.

Getting Tokens for Your Own Slack App

You must create a Slack application ("Slack app") and obtain a user access token in order to run this sample. Log into https://api.slack.com/apps and perform the following steps (as written, the steps are current as of 10.6.0):

  • Click Create an App, assign a name to your app, and select the workspace where you want to set the app.

  • Add User Token Scopes: channels:write, im:read, mpim:read, groups:read, groups:write, im:write, mpim:write, channels:read.

  • Then click Install App to Workspace from the StreamBase Standard Adapters category.

  • Look for your generated OAuth Access Token.

To get a Bot User OAuth Access Token, go to the Bot Users tab to add a bot to your Slack app.

Running the Slack Sample in StreamBase Studio

Run this sample in Studio as follows:

  1. In the Project Explorer view, open this sample's folder.

    Keep an eye on the bottom right status bar of the Studio window. Make sure any Updating, Downloading, Building, or Rebuild project messages finish before you proceed.

  2. Open the src/main/eventflow/packageName folder.

  3. Double-click to open the Slack.sbapp application.

  4. From the Operator Properties tab, enter the generated OAuth token that starts with xoxp-.

  5. Make sure the application is the currently active tab in the EventFlow Editor, then click the Run button. This opens the SB Test/Debug perspective and starts the application.

  6. In the Manual Input view, enter createchannel to command, testchannel to channelName, and then click Send Data.

  7. In the Output Stream view, look for status of successfully created a new channel. Make sure your OAuth scope has channels:write.

  8. In the Manual input, enter sendmemessage to command, testmessage to text, test message to chat.sendMeMesssage.text, then click Send Data.

  9. In the Output Stream view, look for status of successfully sent message. Make sure your OAuth scope contains chat:write:user.

  10. Explore other commands.

  11. When done, press F9 or click the Stop Running Application button.

Running the SlackBot Sample in StreamBase Studio

Run this sample in Studio as follows:

  1. In the Project Explorer view, open this sample's folder.

    Keep an eye on the bottom right status bar of the Studio window. Make sure any Updating, Downloading, Building, or Rebuild project messages finish before you proceed.

  2. Open the src/main/eventflow/packageName folder.

  3. Double-click to open the SlackBot.sbapp application.

  4. From the Operator Properties tab, enter the generated OAuth token that starts with xoxp-.

  5. From the Events Properties tab, make sure Message Event, UserTyping Event, and ChannelJoined Event are selected.

  6. Make sure the application is the currently active tab in the EventFlow Editor, then click the Run button. This opens the SB Test/Debug perspective and starts the application.

  7. In your Slack workspace, start typing in any channel. Look for your bot replying to the message.

  8. Try join a channel, expecting a welcome message from your bot. Make sure your OAuth scope has chat:write:bot.

  9. In the Output Stream view, look for status of all events you have selected.

  10. When done, press F9 or click the Stop Running Application button.

Running the SlackRTMInputAdapter Sample in StreamBase Studio

Run this sample in Studio as follows:

  1. In the Project Explorer view, open this sample's folder.

    Keep an eye on the bottom right status bar of the Studio window. Make sure any Updating, Downloading, Building, or Rebuild project messages finish before you proceed.

  2. Open the src/main/eventflow/packageName folder.

  3. Double-click to open the SlackRTMInputAdapter.sbapp application.

  4. From the Operator Properties tab, enter the generated OAuth token that starts with xoxp-.

  5. From the Events Properties tab, make sure Message Event, UserTyping Event and ChannelJoined Event are selected.

  6. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

  7. In the Output Stream view, look for status and data output for all of your selected events.

  8. When done, press F9 or click the Stop Running Application button.

RTM Control Port

Description

Use the control port to send action commands to the adapter. Tuples enqueued on this port will connect or disconnect the adapter, as well as change the OAuth value at runtime.

Control Port Schema

  • Command, string: the command to send to the adapter.

    The values are:

    • Connect — Starts the Slack Real Time Messaging input adapter.

    • Disconnect — Stops the RTM connection.

  • botUserOAuthToken, string.

    • The OAuth can be changed at runtime

Sample Location

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_adapter_embedded_Slack

See Default Installation Directories for the default location of studio-workspace on your system.

streambase-install-dir/sample/adapter/embedded/Slack