Skip to content

Commit

Permalink
Add pipeline throw_error_example_using_slack
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdatasourav committed Nov 29, 2023
1 parent eb722c2 commit 905fcc3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
8 changes: 8 additions & 0 deletions simple/throw_error_example_using_slack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Throw Error Example Using Slack

Throw an error if the requested Slack channel is unavailable.

## Usage

- Add your Slack API token to `flowpipe.pvars`
- Run the pipeline and specify the `channel` arg, e.g., `flowpipe pipeline run throw_error_example_using_slack --arg 'channel=my-channel'`
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
slack_token = "xoxp-12345-67890"
4 changes: 4 additions & 0 deletions simple/throw_error_example_using_slack/mod.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod "throw_error_example_using_slack" {
title = "Throw Error Example Using Slack"
description = "Throw an error if the requested Slack channel is unavailable."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# // usage: flowpipe pipeline run throw_error_example_using_slack --arg channel="C012ABCDZ"
pipeline "throw_error_example_using_slack" {
title = "Throw Error Example Using Slack"
description = "Throw an error if the requested Slack channel is unavailable."

param "slack_token" {
type = string
default = var.slack_token
description = "Authentication token bearing required scopes."
}

param "channel" {
type = string
description = "Channel, private group, or IM channel to send message to. Must be an encoded ID."
}

step "http" "get_channel" {
url = "https://slack.com/api/conversations.info"
method = "post"

request_headers = {
Content-Type = "application/x-www-form-urlencoded"
Authorization = "Bearer ${param.slack_token}"
}

request_body = "channel=${param.channel}"

# When the requested channel is unavilable, exit the pipeline.
throw {
if = result.response_body.error == "channel_not_found"
message = "The requested channel is not found. Exiting the pipeline."
}
}

output "channel" {
value = step.http.get_channel.response_body.channel
description = "Channel details."
}
}
5 changes: 5 additions & 0 deletions simple/throw_error_example_using_slack/variables.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "slack_token" {
type = string
description = "Slack app token used to authenticate to your Slack workspace."
default = "xoxb-2556146250-5954186987473-G8tirESWljrAEtiiAUPaMbWf"
}

0 comments on commit 905fcc3

Please sign in to comment.