-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example application about how to write to Slack using the http-re…
…quest agent (#628)
- Loading branch information
Showing
5 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Slack channel witer | ||
|
||
This sample application shows how to write to a slack channel | ||
|
||
Export the slack incoming webhook (token) (iwebhooks are locked to slack apps channels at creation): | ||
export SLACK_TOKEN="<token>" | ||
|
||
## Deploy the LangStream application | ||
``` | ||
langstream docker run slack -app examples/applications/slack -i examples/instances/kafka-docker.yaml -s examples/secrets/secrets.yaml | ||
``` | ||
|
||
## write | ||
|
||
Since the application opens a gateway, we can use the gateway API to send and consume messages using the use gateway `chat` feature: | ||
``` | ||
langstream gateway produce slack produce-input -p sessionId=$(uuidgen) -v "hello" | ||
``` | ||
|
||
This is currently working because the slack message and token are hardcoded and need to be referenced by variables. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# | ||
# Copyright DataStax, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
configuration: | ||
defaults: | ||
globals: | ||
slack: | ||
url: "https://hooks.slack.com/services/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# | ||
# Copyright DataStax, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
gateways: | ||
- id: produce-input | ||
type: produce | ||
topic: input-topic | ||
parameters: | ||
- sessionId | ||
produce-options: | ||
headers: | ||
- key: langstream-client-session-id | ||
value-from-parameters: sessionId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# Copyright DataStax, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
topics: | ||
- name: "input-topic" | ||
creation-mode: create-if-not-exists | ||
pipeline: | ||
- name: "convert-to-json" | ||
type: "document-to-json" | ||
input: "input-topic" | ||
configuration: | ||
text-field: "text" | ||
- name: "submit to slack API" | ||
type: "http-request" | ||
configuration: | ||
url: "${globals.slack.url}${secrets.slack.token}" | ||
body: '{"text":"{{ value.text }}"}' | ||
output-field: "value.response" | ||
method: "POST" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters