Skip to content

Commit 6fe3b57

Browse files
authored
API: Slack source connector (#666)
1 parent bcb0ace commit 6fe3b57

File tree

7 files changed

+115
-2
lines changed

7 files changed

+115
-2
lines changed

api-reference/workflow/sources/overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ For the list of specific settings, see:
4141
- [S3](/api-reference/workflow/sources/s3) (`S3` for the Python SDK or `s3` for `curl` and Postman)
4242
- [Salesforce](/api-reference/workflow/sources/salesforce) (`SALESFORCE` for the Python SDK or `salesforce` for `curl` and Postman)
4343
- [SharePoint](/api-reference/workflow/sources/sharepoint) (`SHAREPOINT` for the Python SDK or `sharepoint` for `curl` and Postman)
44+
- [Slack](/api-reference/workflow/sources/slack) (`SLACK` for the Python SDK or `slack` for `curl` and Postman)
4445
- [Snowflake](/api-reference/workflow/sources/snowflake) (`SNOWFLAKE` for the Python SDK or `snowflake` for `curl` and Postman)
4546
- [Zendesk](/api-reference/workflow/sources/zendesk) (`ZENDESK` for the Python SDK or `zendesk` for `curl` and Postman)
4647

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Slack
3+
---
4+
5+
import FirstTimeAPISourceConnector from '/snippets/general-shared-text/first-time-api-source-connector.mdx';
6+
7+
<FirstTimeAPISourceConnector />
8+
9+
Ingest your files into Unstructured from Slack.
10+
11+
The requirements are as follows.
12+
13+
import SlackPrerequisites from '/snippets/general-shared-text/slack.mdx';
14+
15+
<SlackPrerequisites />
16+
17+
To create a Slack source connector, see the following examples.
18+
19+
import SlackSDK from '/snippets/source_connectors/slack_sdk.mdx';
20+
import SlackAPIRESTCreate from '/snippets/source_connectors/slack_rest_create.mdx';
21+
22+
<CodeGroup>
23+
<SlackSDK />
24+
<SlackAPIRESTCreate />
25+
</CodeGroup>
26+
27+
Replace the preceding placeholders as follows:
28+
29+
import SlackAPIPlaceholders from '/snippets/general-shared-text/slack-api-placeholders.mdx';
30+
31+
<SlackAPIPlaceholders />
32+

docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
"api-reference/workflow/sources/s3",
167167
"api-reference/workflow/sources/salesforce",
168168
"api-reference/workflow/sources/sharepoint",
169+
"api-reference/workflow/sources/slack",
169170
"api-reference/workflow/sources/snowflake",
170171
"api-reference/workflow/sources/zendesk"
171172
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- `<name>` (_required_) - A unique name for this connector.
2+
- `<channel>` (_required_): The ID of the target Slack channel from which to read messages.
3+
- `<start-date>`: The date and time, in ISO 8601 format (such as `YYYY-MM-DDTHH:MM:SSZ`), from which to begin reading messages. Messages created before this timestamp are ignored. By default, all messages are read unless an end date is specified.
4+
- `<end-date>`: The date and time, in ISO 8601 format (such as `YYYY-MM-DDTHH:MM:SSZ`), at which to stop reading messages. Messages created after this timestamp are ignored. By default, all messages are read unless a start date is specified.
5+
- `<token>` (_required_): The access token for the Slack app that has permission to read messages from the target Slack channels.

snippets/general-shared-text/slack.mdx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
<iframe
2+
width="560"
3+
height="315"
4+
src="https://www.youtube.com/embed/0F1MXMgk3kY"
5+
title="YouTube video player"
6+
frameborder="0"
7+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
8+
allowfullscreen
9+
></iframe>
10+
111
- A Slack app. Create a Slack app by following [Step 1: Creating an app](https://api.slack.com/quickstart#creating).
2-
- The app must have the `channels:history` OAuth scope. Give the app this scope by following [Step 2: Requesting scopes](https://api.slack.com/quickstart#scopes).
12+
- The app must have the the following OAuth scopes:
13+
14+
- To read messages from public channels, add the scopes `channels:join` and `channels:history`.
15+
- To read messages from private channels, add the scope `groups:history`.
16+
17+
Add these scopes to the app by following [Step 2: Requesting scopes](https://api.slack.com/quickstart#scopes).
18+
319
- The app must be installed and authorized for the target Slack workspace. Install and authorize the app by following [Step 3: Installing and authorizing the app](https://api.slack.com/quickstart#installing).
420
- The app's access token. Get this token by following [Step 3: Installing and authorizing the app](https://api.slack.com/quickstart#installing).
521
- Add the app to the target channels in the Slack workspace. To do this from the channel, open the channel's details page, click the **Integrations** tab, click **Add apps**, and follow the on-screen directions to install the app.
@@ -10,4 +26,9 @@
1026
- `YYYY-MM-DDTHH:MM:SS`
1127
- `YYYY-MM-DDTHH:MM:SSZ`
1228
- `YYYY-MM-DD+HH:MM:SS`
13-
- `YYYY-MM-DD-HH:MM:SS`
29+
- `YYYY-MM-DD-HH:MM:SS`
30+
31+
<Info>
32+
Slack has established API rate limits that could restrict the number and frequency of messages that can be read. To
33+
explore possible workarounds for these cases, see your Slack representative.
34+
</Info>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
```bash curl
2+
curl --request 'POST' --location \
3+
"$UNSTRUCTURED_API_URL/sources" \
4+
--header 'accept: application/json' \
5+
--header "unstructured-api-key: $UNSTRUCTURED_API_KEY" \
6+
--header 'content-type: application/json' \
7+
--data \
8+
'{
9+
"name": "<name>",
10+
"type": "slack",
11+
"config": {
12+
"channels": [
13+
"<channel>",
14+
"<channel>"
15+
],
16+
"start-date": "<start-date>",
17+
"end-date": "<end-date>",
18+
"token": "<token>"
19+
}
20+
}'
21+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
```python Python SDK
2+
import os
3+
4+
from unstructured_client import UnstructuredClient
5+
from unstructured_client.models.operations import CreateSourceRequest
6+
from unstructured_client.models.shared import (
7+
CreateSourceConnector,
8+
SourceConnectorType,
9+
SlackSourceConnectorConfigInput
10+
)
11+
12+
with UnstructuredClient(api_key_auth=os.getenv("UNSTRUCTURED_API_KEY")) as client:
13+
response = client.sources.create_source(
14+
request=CreateSourceRequest(
15+
create_source_connector=CreateSourceConnector(
16+
name="<name>",
17+
type=SourceConnectorType.SLACK,
18+
config=SlackSourceConnectorConfigInput(
19+
channels=[
20+
"<channel>",
21+
"<channel>"
22+
],
23+
start_date="<start-date>",
24+
end_date="<end-date>",
25+
token="<token>"
26+
)
27+
)
28+
)
29+
)
30+
31+
print(response.source_connector_information)
32+
```

0 commit comments

Comments
 (0)