From 429db1a8e3ad094f98e85c954ceeb26bfc920b20 Mon Sep 17 00:00:00 2001 From: mark <mark878@users.noreply.github.com> Date: Wed, 25 Oct 2023 10:37:51 -0400 Subject: [PATCH] Add example application about how to write to Slack using the http-request agent (#628) --- examples/applications/slack/README.md | 21 ++++++++++++ .../applications/slack/configuration.yaml | 22 +++++++++++++ examples/applications/slack/gateways.yaml | 27 ++++++++++++++++ examples/applications/slack/pipeline.yaml | 32 +++++++++++++++++++ examples/secrets/secrets.yaml | 10 +++++- 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 examples/applications/slack/README.md create mode 100644 examples/applications/slack/configuration.yaml create mode 100644 examples/applications/slack/gateways.yaml create mode 100644 examples/applications/slack/pipeline.yaml diff --git a/examples/applications/slack/README.md b/examples/applications/slack/README.md new file mode 100644 index 000000000..91399f420 --- /dev/null +++ b/examples/applications/slack/README.md @@ -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. + diff --git a/examples/applications/slack/configuration.yaml b/examples/applications/slack/configuration.yaml new file mode 100644 index 000000000..2e5e3f493 --- /dev/null +++ b/examples/applications/slack/configuration.yaml @@ -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/" diff --git a/examples/applications/slack/gateways.yaml b/examples/applications/slack/gateways.yaml new file mode 100644 index 000000000..31ace1b8c --- /dev/null +++ b/examples/applications/slack/gateways.yaml @@ -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 diff --git a/examples/applications/slack/pipeline.yaml b/examples/applications/slack/pipeline.yaml new file mode 100644 index 000000000..aa28c2a25 --- /dev/null +++ b/examples/applications/slack/pipeline.yaml @@ -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" diff --git a/examples/secrets/secrets.yaml b/examples/secrets/secrets.yaml index 0ab10adf5..261bfe73a 100644 --- a/examples/secrets/secrets.yaml +++ b/examples/secrets/secrets.yaml @@ -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}" \ No newline at end of file + 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}"