Set up the Openflow Connector for Slack¶
Note
The connector is subject to the Connector Terms.
This topic describes the steps to set up the Openflow Connector for Slack.
Prerequisites¶
Ensure that you have reviewed Openflow Connector for Slack.
Ensure that you have set up Openflow.
Set up a Slack App¶
Set up a Slack App in your Slack workspace. A Slack Admin is needed to set up access to the Slack Workspace. This is done by creating or supplying credentials to a Slack App and installing the App to the Slack workspace and channels. You can create a Slack App by using the JSON configuration:
Update the JSON manifest. Copy the JSON manifest text below. Change the name and display name properties from
EXAMPLE_NAME_CHANGE_THIS
to the desired name of your Slack App. It is recommended to use the same name and display name for your App.{ "display_information": { "name": "EXAMPLE_NAME_CHANGE_THIS" }, "features": { "bot_user": { "display_name": "EXAMPLE_NAME_CHANGE_THIS", "always_online": false } }, "oauth_config": { "scopes": { "bot": [ "channels:history", "channels:read", "groups:history", "groups:read", "im:history", "im:read", "mpim:history", "mpim:read", "users.profile:read", "users:read", "users:read.email" ] } }, "settings": { "event_subscriptions": { "bot_events": [ "message.channels", "message.groups", "message.im", "message.mpim" ] }, "interactivity": { "is_enabled": true }, "org_deploy_enabled": false, "socket_mode_enabled": true, "token_rotation_enabled": false } }
Create a Slack app through the Apps page.
On the Your Apps page, select Create New App.
Select From a manifest.
Select the Workspace where you’ll be developing your app. You’ll be able to [distribute your app](https://api.slack.com/distribution) to other workspaces later if you choose.
Copy the updated manifest JSON from step 1.
Generate an app-level token. You need to create an app-level token even after using the JSON manifest. Under Basic Information, scroll to the App-level tokens section and click the button to generate an [app-level token](https://api.slack.com/concepts/token-types#app). Include the
connections:write
scope to the token.Install and authorize the app.
Return to the Basic Information section of the app management page.
Install your app by selecting the Install to Workspace button.
You’ll now be sent through the Slack OAuth flow. Select Allow on the following screen.
If you want to add your app to a different workspace besides your own, these steps would need to be performed by a user from that workspace. After installation, navigate back to the OAuth & Permissions page. You’ll see an access token under OAuth Tokens. Access tokens represent the permissions delegated to your app by the installing user. Keep it safe and secure. Avoid checking them into public version control. Instead, access them through an environment variable.
Adding the App to channels. Your app isn’t a member of any channels yet, so pick a channel to add some test messages in and
/invite
your app. For example,/invite @Grocery Reminders
.
Note
Restart the processors to load the new channels. After the App is added to a new channel, the ConsumeSlackConversation
processor in the OpenFlow Runtime needs to be stopped and restarted.
Setup necessary ingress rules¶
A Snowflake Admin should follow the egress guide
to apply egress rules to the endpoint https://slack.com/api
and
enable WebSocket egress on wss://wss.slack.com
. This is easiest
done by adding a rule to enable egress on the “slack.com” domain.
Set up Snowflake account¶
As a Snowflake account administrator, perform the following tasks:
Create a new role or use an existing role and grant the Database privileges.
Create a new Snowflake service user with the type as SERVICE.
Grant the Snowflake service user the role you created in the previous steps.
Configure with key-pair auth for the Snowflake SERVICE user from step 2.
Snowflake strongly recommends this step. Configure a secrets manager supported by Openflow, for example, AWS, Azure, and Hashicorp, and store the public and private keys in the secret store.
Note
If for any reason, you do not wish to use a secrets manager, then you are responsible for safeguarding the public key and private key files used for key-pair authentication according to the security policies of your organization.
Once the secrets manager is configured, determine how you will authenticate to it. On AWS, it’s recommended that you the EC2 instance role associated with Openflow as this way no other secrets have to be persisted.
In Openflow, configure a Parameter Provider associated with this Secrets Manager, from the hamburger menu in the upper right. Navigate to Controller Settings » Parameter Provider and then fetch your parameter values.
At this point all credentials can be referenced with the associated parameter paths and no sensitive values need to be persisted within Openflow.
If any other Snowflake users require access to the raw ingested documents and tables ingested by the connector (for example, for custom processing in Snowflake), then grant those users the role created in step 1.
Designate a warehouse for the connector to use. Start with the smallest warehouse size, then experiment with size depending on the number of tables being replicated, and the amount of data transferred. Large table numbers typically scale better with multi-cluster warehouses, rather than larger warehouse sizes.
Configure the connector¶
As a data engineer, perform the following tasks to configure a connector:
Create a database and schema in Snowflake for the connector to store ingested data.
Download the
connector definition file
.Import the connector definition into Openflow:
Open the Snowflake Openflow canvas.
Add a process group. To do this, drag and drop the Process Group icon from the tool palette at the top of the page onto the canvas. Once you release your pointer, a Create Process Group dialog appears.
On the Create Process Group dialog, select the connector definition file to import.
Right-click on the imported process group and select Parameters.
Populate the required parameter values as described in Flow parameters.
Right-click on the plane and select Enable all Controller Services.
Right-click on the imported process group and select Start. The connector starts the data ingestion.
Flow parameters¶
Parameter Name |
Description |
Example or Default Value |
---|---|---|
App Token |
App token of the Slack App created by the Slack Admin |
xapp -1-12345678910-123456 7890123-abcdefghijklm |
Bot Token |
Bot token of the Slack App created by the Slack Admin |
|
Chunk Overlap |
When chunking text, the amount of overlap text to keep between chunks. |
|
Connector ID |
A unique ID to assign the connector. This will be included in the message metadata |
|
Cortex Search Name |
The name of the Cortex Search resource that is created. |
`` SLACK_CORTEX_SEARCH`` |
Max Chunk Chars |
The number of characters to include in text chunks. |
|
Membership Table |
The table name to include Slack membership records |
|
Message Table |
The table name to include Slack message records |
|
Openflow Instance Database |
Database will be created in the user’s Snowflake account if necessary. Conversations, metadata and ACLs will be ingested into tables in the schema specified |
Openflow |
Openflow Instance Schema |
Schema will be created in the target database in the user’s Snowflake account if necessary. Stage and tables will be created to ingest files, metadata and ACLs. |
production |
Refresh Slack Members |
Amount of time in between refreshing Slack membership |
120 minutes |
Reply Monitor Window Seconds |
The number of seconds the Con sumeSlackConversation processor will look back in time for replies to threads. |
300 |
Snowflake Account |
Snowflake account identifier with organization name and account name formatted as [organization -name]-[account-name] |
myorg-myaccount |
Snowflake Role |
The role to assume after authenticating to Snowflake |
INGEST_ADMIN |
Snowflake Username |
The username to connect to the Snowflake account. |
|
Snowflake Private Key |
The RSA private key which is used for authentication. The RSA key must be formatted according to PKCS8 standards and have standard PEM headers and footers. Note that either Snowflake Private Key File or Snowflake Private Key must be defined |
N/A |
Snowflake Private Key File |
The file that contains the RSA Private Key used for authentication to Snowflake, formatted according to PKCS8 standards and having standard PEM headers and footers. The header line starts with —–BEGIN PRIVATE |
/opt/resources/ snowflake/ rsa_key.p8 |
Snowflake Private Key Password |
The password associated with the Snowflake Private Key File |
N/A |
Snowflake Warehouse |
The Snowflake warehouse to use for Snowflake operations and for the Cortex Service |
dev_warehouse |
Upload Latency |
The amount of time to wait to upload data to Snowflake in batches. |
60 seconds |
Query the Cortex Search service¶
You can use the Cortex Search service to build chat and search applications to chat with or query your messages in Slack.
After you install and configure the connector and it begins ingesting content from Slack, you can query the Cortex Search service. For more information about using Cortex Search, see Query a Cortex Search service.
Filter responses
To restrict responses from the Cortex Search service to messages that a specific user
has access to in Slack you can specify a filter containing the email address of the user
when you query Cortex Search. For example, filter.@contains.memberids
or filter.@contains.memberemails
.
The Cortex Search service is created in the same database and schema as the Slack tables, specified by the Openflow Instance Database
and Openflow Instance Schema
parameters. The name of the Cortex Search service is determined by the Cortex Search Name
parameter.
Run the following SQL code in a SQL worksheet to query the Cortex Search service with messages ingested by Slack.
Replace the following:
cortex_db
: Name of the database containing the cortex search service, specified by theOpenflow Instance Database
parameter.cortex_schema
: Name of the schema containing the cortex search service, specified by theOpenflow Instance Schema
parameter.cortex_search_service_name
: Name of the cortex search service, specified by theCortex Search Name
parameter.user_emailID
: Email ID of the user who you want to filter the responses for.your_question
: The question that you want to get responses for.number_of_results
: Maximum number of results to return in the response. The maximum value is 1000 and the default value is 10.
SELECT PARSE_JSON(
SNOWFLAKE.CORTEX.SEARCH_PREVIEW(
'<cortex_db>.<cortex_schema>.<cortex_search_service_name>',
'{
"query": "<your_question>",
"columns": ["text", "channel", "ts","username"],
"filter": {"@contains": {"memberemails": "<user_emailID>"} },
"limit": <number_of_results>
}'
)
)['results'] AS results
Here’s a complete list of values that you can enter for columns
:
type
subtype
channel
user
username
connectorId
workspaceId
ts
threadTs
Example: Query an AI assistant for human resources (HR) information
You can use Cortex Search to query an AI assistant for employees to chat about the latest Slack posts. The messages that are searched can come from informative Slack channels such as general or it-help.
Run the following in a SQL worksheet to query the Cortex Search service over messages ingested from Slack.
Replace the following:
cortex_db
: Name of the database containing the cortex search service, specified by theOpenflow Instance Database
parameter.cortex_schema
: Name of the schema containing the cortex search service, specified by theOpenflow Instance Schema
parameter.cortex_search_service_name
: Name of the cortex search service, specified by theCortex Search Name
parameter.user_emailID
: Email ID of the user who you want to filter the responses for.
SELECT PARSE_JSON(
SNOWFLAKE.CORTEX.SEARCH_PREVIEW(
'<cortex_db>.<cortex_schema>.<cortex_search_service_name>',
'{
"query": "What is my vacation carry over policy?",
"columns": ["text", "channel", “ts”,”username”],
"filter": {"@contains": {"memberemails": "<user_emailID>"} },
"limit": 1
}'
)
)['results'] AS results
Run the following code in a Python worksheet to query the
Cortex Search service over messages ingested from Slack
Ensure that you add the snowflake.core
package to your database.
Replace the following:
cortex_db
: Name of the database containing the cortex search service, specified by theOpenflow Instance Database
parameter.cortex_schema
: Name of the schema containing the cortex search service, specified by theOpenflow Instance Schema
parameter.cortex_search_service_name
: Name of the cortex search service, specified by theCortex Search Name
parameter.user_emailID
: Email ID of the user who you want to filter the responses for.
import snowflake.snowpark as snowpark
from snowflake.snowpark import Session
from snowflake.core import Root
def main(session: snowpark.Session):
root = Root(session)
# fetch service
my_service = (root
.databases["<cortex_db>"]
.schemas["<cortex_schema>"]
.cortex_search_services["<cortex_search_service_name>"]
)
# query service
resp = my_service.search(
query="What is my vacation carry over policy?",
columns = ["text", "channel", "ts","username"],
filter = {"@contains": {"memberemails": "<user_emailID>"} },
limit=1
)
return (resp.to_json())
Execute the following code in a command line interface to query the Cortex Search service over messages ingested from Slack. You will need to authentication through key pair authentication and OAuth to access the Snowflake REST APIs. For more information, see Rest API and Authenticating Snowflake REST APIs with Snowflake.
Replace the following:
cortex_db
: Name of the database containing the cortex search service, specified by theOpenflow Instance Database
parameter.cortex_schema
: Name of the schema containing the cortex search service, specified by theOpenflow Instance Schema
parameter.cortex_search_service_name
: Name of the cortex search service, specified by theCortex Search Name
parameter.account_url
: Your Snowflake account URL. For instructions on finding your account URL, see Finding the organization and account name for an account.
curl --location "https://<account_url>/api/v2/databases/<cortex_db>/schemas/<cortex_schema>/cortex-search-services/<cortex_search_service_name>" \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header "Authorization: Bearer <CORTEX_SEARCH_JWT>" \
--data '{
"query": "What is my vacation carry over policy?",
"columns": ["text", "channel"],
"limit": 1
}'
Sample response:
{
"results" : [ {
"channel" : "dev notes",
"text" : "Answer to the question asked."
} ]
}