-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pipeline throw_error_example_using_slack
- Loading branch information
1 parent
eb722c2
commit 905fcc3
Showing
5 changed files
with
57 additions
and
0 deletions.
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,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'` |
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 @@ | ||
slack_token = "xoxp-12345-67890" |
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,4 @@ | ||
mod "throw_error_example_using_slack" { | ||
title = "Throw Error Example Using Slack" | ||
description = "Throw an error if the requested Slack channel is unavailable." | ||
} |
39 changes: 39 additions & 0 deletions
39
simple/throw_error_example_using_slack/throw_error_example_using_slack.fp
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,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." | ||
} | ||
} |
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,5 @@ | ||
variable "slack_token" { | ||
type = string | ||
description = "Slack app token used to authenticate to your Slack workspace." | ||
default = "xoxb-2556146250-5954186987473-G8tirESWljrAEtiiAUPaMbWf" | ||
} |