Skip to content

Commit

Permalink
Add example application about how to write to Slack using the http-re…
Browse files Browse the repository at this point in the history
…quest agent (#628)
  • Loading branch information
mark878 authored Oct 25, 2023
1 parent eb15dbd commit 429db1a
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
21 changes: 21 additions & 0 deletions examples/applications/slack/README.md
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.

22 changes: 22 additions & 0 deletions examples/applications/slack/configuration.yaml
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/"
27 changes: 27 additions & 0 deletions examples/applications/slack/gateways.yaml
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
32 changes: 32 additions & 0 deletions examples/applications/slack/pipeline.yaml
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"
10 changes: 9 additions & 1 deletion examples/secrets/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,12 @@ secrets:
access-key: "${BEDROCK_ACCESS_KEY}"
secret-key: "${BEDROCK_SECRET_KEY}"
region: "${REGION:-us-east-1}"
completions-model: "${BEDROCK_COMPLETIONS_MODEL}"
completions-model: "${BEDROCK_COMPLETIONS_MODEL}"
- id: slack
data:
token: "${SLACK_TOKEN:-}"
url: "${SLACK_URL:-}"
provider: "${SLACK_PROVIDER:-slack}"
# embeddings-model: "${OPEN_AI_EMBEDDINGS_MODEL:-text-embedding-ada-002}"
# chat-completions-model: "${OPEN_AI_CHAT_COMPLETIONS_MODEL:-gpt-3.5-turbo}"
# text-completions-model: "${OPEN_AI_TEXT_COMPLETIONS_MODEL:-gpt-3.5-turbo-instruct}"

0 comments on commit 429db1a

Please sign in to comment.