Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input examples #112

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions messaging/input_examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Input Examples

This mod contains a collection of input types examples for the notification feature.

## Usage

Notifications requires Flowpipe to be running in [server mode](https://flowpipe.io/docs/run/server), so let's start the Flowpipe server:

```sh
flowpipe server --verbose
```

Then, in another terminal, run the pipeline:

```sh
flowpipe pipeline run button_example --host local
```

29 changes: 29 additions & 0 deletions messaging/input_examples/button_example.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pipeline "button_example" {
title = "Button Example"
description = "This pipeline demonstrates how to use the button input type. It prompts the user to select a coin and then calls another pipeline to get the price of the selected coin."

param "notifier" {
type = string
default = "default"
}

step "input" "my_input_step" {
notifier = notifier[param.notifier]
type = "button"
prompt = "Get quote for BTC or ETH?"

option "BTCUSDT" {}
option "ETHUSDT" {}
}

output "my_input_step" {
value = step.input.my_input_step.value
}

step "pipeline" "get_coin_price" {
pipeline = pipeline.get_coin_price
args = {
symbols = [step.input.my_input_step.value]
}
}
}
32 changes: 32 additions & 0 deletions messaging/input_examples/button_with_labels_and_values_example.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pipeline "button_with_labels_and_values_example" {
title = "Button with Labels and Values Example"
description = "This pipeline demonstrates how to use a button input step by customizing the labels and values of the buttons. It prompts the user to select a coin and then calls another pipeline to get the price of the selected coin."

param "notifier" {
type = string
default = "default"
}

step "input" "my_input_step" {
notifier = notifier[param.notifier]
type = "button"
prompt = "Get quote for BTC or ETH?"

option "btc_button" {
label = "Bitcoin"
value = "BTCUSDT"
}

option "eth_button" {
label = "Ethereum"
value = "ETHUSDT"
}
}

step "pipeline" "get_coin_price" {
pipeline = pipeline.get_coin_price
args = {
symbols = [step.input.my_input_step.value]
}
}
}
36 changes: 36 additions & 0 deletions messaging/input_examples/button_with_style_example.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
pipeline "button_with_style_example" {
title = "Button Example with Style"
description = "This pipeline demonstrates how to use the button input type with different styles. It show the user the current price of Bitcoin and asks them what they want to do with it."

param "notifier" {
type = string
default = "default"
}

step "pipeline" "get_coin_price" {
pipeline = pipeline.get_coin_price
args = {
symbols = ["BTCUSDT"]
}
}

step "input" "my_input_step" {
notifier = notifier[param.notifier]
type = "button"
prompt = "Bitcoin is currently trading at $ ${step.pipeline.get_coin_price.output.prices[0].lastPrice}. What do you want to do?"

option "buy" {
style = "ok"
}
option "sell" {
style = "alert"
}
option "hold" {
style = "info"
}
}

output "my_input_step" {
value = "I'm gonna ${step.input.my_input_step.value} it."
}
}
18 changes: 18 additions & 0 deletions messaging/input_examples/get_coin_price.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pipeline "get_coin_price" {
title = "Get Coin Price"
description = "Gets the price of a coin from Binance API"

param "symbols" {
type = list(string)
}

step "http" "coin_ticker" {
url = "https://api4.binance.com/api/v3/ticker/24hr"
method = "get"
}

output "prices" {
value = [for item in step.http.coin_ticker.response_body : {"symbol" = item.symbol, "lastPrice" = item.lastPrice} if contains(param.symbols, item.symbol)]
}
}

6 changes: 6 additions & 0 deletions messaging/input_examples/mod.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod "input_examples" {
title = "Input Examples"
description = "This module provides examples of how to use the input module."
documentation = file("./README.md")
categories = ["messaging"]
}
27 changes: 27 additions & 0 deletions messaging/input_examples/multiselect_example.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
pipeline "multiselect_example" {
title = "Multiselect Example"
description = "This pipeline demonstrates how to use the multiselect input type. It prompts the user to select one or more coin and then calls another pipeline to get the price of the selected coins."

param "notifier" {
type = string
default = "default"
}

step "input" "my_input_step" {
notifier = notifier[param.notifier]
type = "multiselect"
prompt = "Get quote for:"

option "BTCUSDT" {}
option "ETHUSDT" {}
option "PEPEUSDT" {}
option "DOGEUSDT" {}
}

step "pipeline" "get_coin_price" {
pipeline = pipeline.get_coin_price
args = {
symbols = step.input.my_input_step.value
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pipeline "multiselect_with_dynamic_options_example" {
title = "Multiselect with dynamic options example"
description = "This pipeline demonstrates how to use a multiselect input step with dynamic options. The options are fetched from an API and then used in the input step. The pipeline fetches the current astronauts in space and then asks the user to select their favorite astronaut. The selected astronaut is then printed in the output step."

param "notifier" {
type = string
default = "default"
}

step "http" "who_is_in_space" {
url = "http://api.open-notify.org/astros.json"
method = "get"
}

step "input" "my_input_step" {
notifier = notifier[param.notifier]
type = "multiselect"
prompt = "Which astros do you like the most?"
options = [for astro in step.http.who_is_in_space.response_body.people : {"value" = astro.name}]
}

output "my_favorite_astros" {
value = step.input.my_input_step.value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
pipeline "multiselect_with_lables_and_default_example" {
title = "Multiselect with labels and default example"
description = "This pipeline demonstrates how to use a multiselect input step with custom labels and a default choice. It prompts the user to select one or more coin and then calls another pipeline to get the price of the selected coins."

param "notifier" {
type = string
default = "default"
}

step "input" "my_input_step" {
notifier = notifier[param.notifier]
type = "multiselect"
prompt = "Get quote for:"

option "btc_button" {
label = "Bitcoin"
value = "BTCUSDT"
}
option "eth_button" {
label = "Ethereum"
value = "ETHUSDT"
}
option "pepe_button" {
label = "Pepe Coin"
value = "PEPEUSDT"
}
option "doge_button" {
label = "Doge Coin"
value = "DOGEUSDT"
}
}

step "pipeline" "get_coin_price" {
pipeline = pipeline.get_coin_price
args = {
symbols = step.input.my_input_step.value
}
}
}
27 changes: 27 additions & 0 deletions messaging/input_examples/select_example.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
pipeline "select_example" {
title = "Select Example"
description = "This pipeline demonstrates how to use the select input type. It prompts the user to select a coin and then calls another pipeline to get the price of the selected coin."

param "notifier" {
type = string
default = "default"
}

step "input" "my_input_step" {
notifier = notifier[param.notifier]
type = "select"
prompt = "Get quote for:"

option "BTCUSDT" {}
option "ETHUSDT" {}
option "PEPEUSDT" {}
option "DOGEUSDT" {}
}

step "pipeline" "get_coin_price" {
pipeline = pipeline.get_coin_price
args = {
symbols = [step.input.my_input_step.value]
}
}
}
39 changes: 39 additions & 0 deletions messaging/input_examples/select_with_lables_and_default_example.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
pipeline "select_with_lables_and_default_example" {
title = "Select with Labels and Default Example"
description = "This pipeline demonstrates how to use a select input step by customizing the labels and values of the options to select. It prompts the user to select a coin and then calls another pipeline to get the price of the selected coin."

param "notifier" {
type = string
default = "default"
}

step "input" "my_input_step" {
notifier = notifier[param.notifier]
type = "select"
prompt = "Get quote for:"

option "btc_button" {
label = "Bitcoin"
value = "BTCUSDT"
}
option "eth_button" {
label = "Ethereum"
value = "ETHUSDT"
}
option "pepe_button" {
label = "Pepe Coin"
value = "PEPEUSDT"
}
option "doge_button" {
label = "Doge Coin"
value = "DOGEUSDT"
}
}

step "pipeline" "get_coin_price" {
pipeline = pipeline.get_coin_price
args = {
symbols = [step.input.my_input_step.value]
}
}
}
24 changes: 24 additions & 0 deletions messaging/input_examples/text_example.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pipeline "text_example" {
title = "Text Example"
description = "This pipeline prompts the user for a name and then predicts the nationality based on the name."

param "notifier" {
type = string
default = "default"
}

step "input" "my_input_step" {
notifier = notifier[param.notifier]
type = "text"
prompt = "Type a name and I will predict the nationality based on it."
}

step "http" "name_prediction" {
url = "https://api.nationalize.io/?name=${step.input.my_input_step.value}"
method = "get"
}

output "name_prediction" {
value = step.http.name_prediction.response_body
}
}