Slack Source
Provided by: "Apache Software Foundation"
Support Level for this Kamelet is: "Stable"
Reads the new messages posted in a public Slack channel, by asking Slack at a regular interval, one message per Slack message.
Use it to react to what people write in a channel, for example to turn a message in #support into a ticket, to archive a channel, or to start a job when someone posts a command. To post to Slack instead, use slack-sink.
Output: the body is the Slack message as JSON text, with fields such as text (what was written), user (the ID of the author) and ts (the time stamp that identifies the message). The Content-Type header is application/json.
Good to know: when it starts, it also sends the most recent message already in the channel, then only the messages posted after it. It does not remember where it stopped: after a restart it starts again from the most recent message. It reads public channels only, by their name, and needs a token of a Slack app, see token.
Configuration Options
The following table summarizes the configuration options available for the slack-source Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
Channel | Required The name of the public channel to read, without the leading | string | support | ||
Token | Required The OAuth token of your Slack app, which starts with | string | |||
Delay | How long to wait between two checks for new messages. A number is in milliseconds; a unit can be added, such as | string | 60000 | 30s | |
Natural Order | If true, the new messages found at a check are sent oldest first. If false, they are sent newest first. | boolean | false | ||
Server URL | The address of the Slack API. Change it only to use a test server or a proxy that stands in for Slack. | string | https://slack.com |
Dependencies
At runtime, the slack-source Kamelet relies upon the presence of the following dependencies:
-
camel:gson
-
camel:slack
-
camel:kamelet
Camel JBang usage
Prerequisites
-
You’ve installed JBang.
-
You have executed the following command:
jbang app install camel@apache/camel Supposing you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:slack-source"
parameters:
.
.
.
steps:
- to:
uri: "kamelet:log-sink" You can now run it directly through the following command
camel run route.yaml Slack Source Kamelet Description
Authentication
This Kamelet requires the OAuth token of a Slack app. You need to create a Slack app and give it the permissions (scopes) to read channels and their messages.
Configuration
The Slack Source Kamelet supports the following configurations:
-
Token: OAuth token of the Slack app (required)
-
Channel: the name of the public channel to read, without the leading
#(required) -
Server URL: Slack API server URL (optional, defaults to
https://slack.com) -
Delay: how long to wait between two checks for new messages, in milliseconds or with a unit such as
30s -
Natural Order: whether the new messages of a check are sent oldest first
Output Format
The Kamelet outputs each Slack message as JSON text, with fields such as text (the content), user (the ID of the author) and ts (the time stamp of the message). The message does not say in which channel it was posted.
When it starts, the Kamelet also sends the most recent message already in the channel. After that it sends only the messages posted since the last check.
Setup Requirements
-
Create a Slack app in your workspace at https://api.slack.com/apps
-
Add the necessary OAuth scopes (
channels:history,channels:read, and the others listed for thetokenoption) -
Install the app to your workspace
-
Copy the OAuth token from the OAuth & Permissions page of the app
Usage Example
- route:
from:
uri: "kamelet:slack-source"
parameters:
token: "{{slack.token}}"
channel: "general"
delay: 10000
steps:
- to:
uri: "kamelet:log-sink"