DataWeave Slack Library icon

DataWeave Slack Library

(0 reviews)

Builders

slack::Builders

Provides functions to simplify the creation and composition of these Slack API features:

Index

Functions

NameDescription
actionsGenerates an actions block.
blocksGenerates the standard Block Kit syntax to define a group of blocks.
buttonGenerates a button element with a simple plain text object and ID.
buttonWithUrlGenerates a button element with a simple plain text object, an ID, and an URL.
buttonWithValueGenerates a button element with a simple plain text object, an ID, and a value.
contextGenerates a context block with a single plain text element item.
dividerGenerates a divider block.
externalSelectGenerates an external select element with a simple plain text object as placeholder and its ID.
headerGenerates a header block with a simple plain text object.
imageGenerates an image element with its URL and alternative text.
inputBlockGenerates an input block with a simple text label.
inputTextGenerates an input object.
mrkdwnGenerates a mrkdwn text object.
multiStaticSelectGenerates a multi-static select element with a simple text placeholder, ID, and options.
optionGenerates an option object with a simple plain text
object and its value.
optionGroupGenerates an option group object with a simple plain text object and its options.
radioButtonsGenerates a radio buttons group, given its ID and options.
sectionGenerates a simple section block with a mrkdwn object.
staticSelectGenerates a static select element with a simple plain text object as placeholder, its ID, and options.
staticSelectByGroupsGenerates a static select element with a simple plain text object as placeholder, its ID, and option groups.
textGenerates a plain text object with emojis enabled.
withStyleAdds a style field to a button.
withUrlAdds a URL field to a button.
withValueAdds a value field to a button.

Functions

actions ↑↑

actions(actions: Array<Element>): Actions

Generates an actions block.

Actions Block Reference

Parameters
NameTypeDescription
actionsArray<Element>The array of interactive elements to render.
Example

This examples generates an actions block with a simple button.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
actions([button("Click me!", "bait")])
Output
{
  "type": "actions",
  "elements": [
    {
      "type": "button",
      "text": {
        "type": "plain_text",
        "text": "Click me!",
        "emoji": true
      },
      "action_id": "bait"
    }
  ]
}

blocks ↑↑

blocks(blocks: Array<Block>)

Generates the standard Block Kit syntax to define a group of blocks.

Parameters
NameTypeDescription
blocksArray<Block>The array of blocks to render.
Example

This example generates and uses a simple section as a block.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 blocks([section("Hello there!")])
Output
{
   "blocks": [
    {
       "type": "section",
       "text": {
         "type": "plain_text",
         "text": "Hello there!",
         "emoji": true
       }
     }
   ]
}

button ↑↑

button(message: String, id: String): Button

Generates a button element with a simple plain text object and ID.

Button Element Reference

Parameters
NameTypeDescription
messageStringThe value to use in the desired text.
idStringThe value to use in an action_id field.
Example

This example generates a button with simple text and an ID called "bait".

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 button("Click me!", "bait")
Output
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Click me!",
    "emoji": true
  },
  "action_id": "bait"
}

button(text: PlainText, id: String): Button

Generates a button element with a plain text object and ID.

Button Element Reference

Parameters
NameTypeDescription
textPlainTextThe plain text object to use.
idStringThe value to use in an action_id field.
Example

This example generates a button with text with an ID called "emoji".

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 button({'type': "plain_text", text: "Create your own :emoji:"}, "emoji")
Output
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Create your own :emoji:"
  },
  "action_id": "emoji"
}

buttonWithUrl ↑↑

buttonWithUrl(message: String, id: String, url: String): Button

Generates a button element with a simple plain text object, an ID, and an URL.

Button Element Reference

Parameters
NameTypeDescription
messageStringThe value to use in the desired text.
idStringThe value to use in an action_id field.
urlStringThe URL to use.
Example

This example generates a button with simple text, an ID called "bait", and a URL to the Slack site.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 buttonWithUrl("Click me!", "bait", "https://slack.com")
Output
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Click me!",
    "emoji": true
  },
  "action_id": "bait",
  "url": "https://slack.com"
}

buttonWithUrl(text: PlainText, id: String, url: String): Button

Generates a button element with a plain text object, an ID, and a URL.

Button Element Reference

Parameters
NameTypeDescription
textPlainTextThe plain text object to use.
idStringThe value to use in an action_id field.
urlStringThe URL to use.
Example

This example generates a button with an emoji and text, an ID called "emoji", and a URL to the Slack site.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 buttonWithUrl({'type': "plain_text", text: "Create your own :emoji:"}, "emoji", "https://slack.com")
Output
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Create your own :emoji:"
  },
  "action_id": "emoji",
  "url": "https://slack.com"
}

buttonWithValue ↑↑

buttonWithValue(message: String, id: String, value: String): Button

Generates a button element with a simple plain text object, an ID, and a value.

Button Element Reference

Parameters
NameTypeDescription
messageStringThe value to use in the desired text.
idStringThe value to use in an action_id field.
valueStringThe value to use.
Example

This example generates a button with a simple text, an ID called "bait", and a value.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 buttonWithValue("Click me!", "bait", "something to share")
Output
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Click me!",
    "emoji": true
  },
  "action_id": "bait",
  "value": "something to share"
}

buttonWithValue(text: PlainText, id: String, value: String): Button

Generates a button element with a plain text object, an ID, and a value.

Button Element Reference

Parameters
NameTypeDescription
textPlainTextThe value to use in the desired text.
idStringThe value to use in an action_id field.
valueStringThe value to use.
Example

This example generates a button with text with an emoji, an ID called "emoji", and a value.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 buttonWithValue({'type': "plain_text", text: "Create your own :emoji:"}, "emoji", "origin")
Output
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Create your own :emoji:"
  },
  "action_id": "emoji",
  "value": "origin"
}

context ↑↑

context(message: String): Context

Generates a context block with a single plain text element item.

Context Block Reference

Parameters
NameTypeDescription
messageStringThe value to use as text.
Example

This example shows how context behaves.

Source
%dw 2.0
output application/json
---
context(":calendar: Make sure to add this to your events")
Output
{
  "type": "context",
  "elements": [
    {
      "type": "plain_text",
      "text": ":calendar: Make sure to add this to your events",
      "emoji": true
    }
  ]
}

context(elements: Array<Image | Text>): Context

Generates a context block with the desired elements.

Context Block Reference

Parameters
NameTypeDescription
elementsArray<Image|Text>The image or text elements.
Example

This example shows how context behaves.

Source
%dw 2.0
output application/json
---
context([mrkdwn("Built with :heart: by the DataWeave team")])
Output
{
  "type": "context",
  "elements": [
    {
      "type": "mrkdwn",
      "text": "Built with :heart: by the DataWeave team"
    }
  ]
}

divider ↑↑

divider(): Divider

Generates a divider block.

Divider Block Reference

Example

This example generates a divider block.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 divider()
Output
{
  "type": "divider"
}

externalSelect ↑↑

externalSelect(placeholder: String, id: String): ExternalSelect

Generates an external select element with a simple plain text object as placeholder and its ID.

External Data Source Reference

Parameters
NameTypeDescription
placeholderStringThe value to use in the desired placeholder
idStringThe value to use in an action_id field.
Example

This example shows how externalSelect behaves.

Source
%dw 2.0
output application/json
---
externalSelect("Choose a dish", "dishes")
Output
{
  "type": "external_select",
  "placeholder": {
    "type": "plain_text",
    "text": "Choose a dish",
    "emoji": true
  },
  "action_id": "dishes"
}

externalSelect(placeholder: PlainText, id: String): ExternalSelect

Generates an external select element with a text object as placeholder and its ID.

External Data Source Reference

Parameters
NameTypeDescription
placeholderPlainTextThe text to use in the desired placeholder
idStringThe value to use in an action_id field.
Example

This example shows how externalSelect behaves.

Source
%dw 2.0
output application/json
---
externalSelect(text("Choose a dish"), "dishes")
Output
{
  "type": "external_select",
  "placeholder": {
    "type": "plain_text",
    "text": "Choose a dish",
    "emoji": true
  },
  "action_id": "dishes"
}

header ↑↑

header(message: String): Header

Generates a header block with a simple plain text object.

Header Block Reference

Parameters
NameTypeDescription
messageStringThe value to use in the desired text.
Example

This example generates a header with a simple text.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 header("Hello!")
Output
{
  "type": "header",
  "text": {
    "type": "plain_text",
    "text": "Hello!",
    "emoji": true
  }
}

header(text: PlainText): Header

Generates a header block with a plain text object.

Header Block Reference

Parameters
NameTypeDescription
textPlainTextThe plain text object to use.
Example

This example generates a header with a plain text object with no support for emojis.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
header({
    'type': "plain_text",
    text: "Hello!",
    emojis: false
})
Output
{
  "type": "header",
  "text": {
    "type": "plain_text",
    "text": "Hello!",
    "emoji": false
  }
}

image ↑↑

image(url: String, text: String): Image

Generates an image element with its URL and alternative text.

Image Element Reference

Parameters
NameTypeDescription
urlStringThe URL to the image.
textStringThe text to use if the image cannot be rendered.
Example

This example shows how image behaves.

Source
%dw 2.0
output application/json
---
image("https://api.slack.com/img/blocks/bkb_template_images/profile_1.png", "Michael Scott")
Output
{
  "type": "image",
  "image_url": "https://api.slack.com/img/blocks/bkb_template_images/profile_1.png",
  "alt_text": "Michael Scott"
}

image(url: String, altText: String, title: String): ImageBlock

Generates an image block with a simple text title.

Image Block Reference

Parameters
NameTypeDescription
urlStringThe URL for the image.
altTextStringThe alternative text for the image.
titleStringThe value to use for the text title.
Example

This example shows how image behaves.

Source
%dw 2.0
output application/json
---
image("https://api.slack.com/img/blocks/bkb_template_images/profile_1.png", "profile pic", "Your new profile picture is saved")
Output
{
  "type": "image",
  "image_url": "https://api.slack.com/img/blocks/bkb_template_images/profile_1.png",
  "alt_text": "profile pic",
  "title": {
    "type": "plain_text",
    "text": "Your new profile picture is saved",
    "emoji": true
  }
}

image(url: String, altText: String, title: PlainText): ImageBlock

Generates an image block with a text title.

Image Block Reference

Parameters
NameTypeDescription
urlStringThe URL for the image.
altTextStringThe alternative text for the image.
titlePlainTextThe text value to use as the title.
Example

This example shows how image behaves.

Source
%dw 2.0
output application/json
---
image("https://api.slack.com/img/blocks/bkb_template_images/profile_1.png", "profile pic", text("Your new profile picture is saved"))
Output
{
  "type": "image",
  "image_url": "https://api.slack.com/img/blocks/bkb_template_images/profile_1.png",
  "alt_text": "profile pic",
  "title": {
    "type": "plain_text",
    "text": "Your new profile picture is saved",
    "emoji": true
  }
}

inputBlock ↑↑

inputBlock(label: String, element: Element): Input

Generates an input block with a simple text label.

Input Block Reference

Parameters
NameTypeDescription
labelStringThe label for the input.
elementElementThe element to use in the input.
Example

This example shows how inputBlock behaves.

Source
%dw 2.0
output application/json
---
inputBlock("Please select your desired lunch:", inputText("lunch"))
Output
{
  "type": "input",
  "label": {
    "type": "plain_text",
    "text": "Please select your desired lunch:",
    "emoji": true
  },
  "element": {
    "type": "plain_text_input",
    "action_id": "lunch",
    "multiline": false
  }
}

inputBlock(label: PlainText, element: Element): Input

Generates an input block.

Input Block Reference

Parameters
NameTypeDescription
labelPlainTextThe label for the input.
elementElementThe element to use in the input.
Example

This example shows how inputBlock behaves.

Source
%dw 2.0
output application/json
---
inputBlock(text("Please select your desired lunch:"), inputText("lunch"))
Output
{
  "type": "input",
  "label": {
    "type": "plain_text",
    "text": "Please select your desired lunch:",
    "emoji": true
  },
  "element": {
    "type": "plain_text_input",
    "action_id": "lunch",
    "multiline": false
  }
}

inputText ↑↑

inputText(id: String, multiline: Boolean = false): PlainTextInput

Generates an input object.

Plain-text Input Element Reference

Parameters
NameTypeDescription
idStringThe value to use in the action_id field.
multilineBooleanWhether the input should be multiline. Defaults to false.
Example

This example shows how inputText behaves.

Source
%dw 2.0
output application/json
---
inputText("suggestions", true)
Output
{
  "type": "plain_text_input",
  "action_id": "suggestions",
  "multiline": true
}

mrkdwn ↑↑

mrkdwn(message: String): Mrkdwn

Generates a mrkdwn text object.

Text Reference

Parameters
NameTypeDescription
messageStringThe mrkdwn to use.
Example

This example generates a mrkdwn text object that has bold text.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 mrkdwn("*Hello*")
Output
{
  "type": "mrkdwn",
  "text": "*Hello*"
}

multiStaticSelect ↑↑

multiStaticSelect(placeholder: String, id: String, options: Array<Option>): MultiStaticSelect

Generates a multi-static select element with a simple text placeholder, ID, and options.

Multi-select Menu Element Reference

Parameters
NameTypeDescription
placeholderStringThe value to use in the desired placeholder.
idStringThe value to use in the action_id field.
optionsArray<Option>The options to select.
Example

This example shows how multiStaticSelect behaves.

Source
%dw 2.0
output application/json
var versions = ["4.2.1", "4.2.2", "4.3.0"]
---
multiStaticSelect("Choose versions...", "versions", versions map ((item, index) -> option(item, item)))
Output
{
  "type": "multi_static_select",
  "placeholder": {
    "type": "plain_text",
    "text": "Choose versions...",
    "emoji": true
  },
  "action_id": "versions",
  "options": [
    {
      "text": {
        "type": "plain_text",
        "text": "4.2.1",
        "emoji": true
      },
      "value": "4.2.1"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "4.2.2",
        "emoji": true
      },
      "value": "4.2.2"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "4.3.0",
        "emoji": true
      },
      "value": "4.3.0"
    }
  ]
}

multiStaticSelect(placeholder: PlainText, id: String, options: Array<Option>): MultiStaticSelect

Generates a multi-static select element with its placeholder, ID, and options.

Multi-select Menu Element Reference

Parameters
NameTypeDescription
placeholderPlainTextThe text to use as a placeholder.
idStringThe value to use in the action_id field.
optionsArray<Option>The options to select.
Example

This example shows how multiStaticSelect behaves.

Source
%dw 2.0
output application/json
var versions = ["4.2.1", "4.2.2", "4.3.0"]
---
multiStaticSelect(text("Choose versions..."), "versions", versions map ((item, index) -> option(item, item)))
Output
{
  "type": "multi_static_select",
  "placeholder": {
    "type": "plain_text",
    "text": "Choose versions...",
    "emoji": true
  },
  "action_id": "versions",
  "options": [
    {
      "text": {
        "type": "plain_text",
        "text": "4.2.1",
        "emoji": true
      },
      "value": "4.2.1"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "4.2.2",
        "emoji": true
      },
      "value": "4.2.2"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "4.3.0",
        "emoji": true
      },
      "value": "4.3.0"
    }
  ]
}

option ↑↑

option(message: String, value: String)

Generates an option object with a simple plain text
object and its value.

Option Object Reference

Parameters
NameTypeDescription
messageStringThe value to use in the desired text.
valueStringThe value to use in the option.
Example

This example generates multiple options from a list of strings, using the same text and value.

Source
%dw 2.0
output application/json
import * from slack::Builders
var versions = ["4.3.0", "4.2.2", "4.1.6"]
---
 versions map ((item) -> option(item, item))
Output
[
  {
    "text": {
      "type": "plain_text",
      "text": "4.3.0",
      "emoji": true
    },
    "value": "4.3.0"
  },
  {
    "text": {
      "type": "plain_text",
      "text": "4.2.2",
      "emoji": true
    },
    "value": "4.2.2"
  },
  {
    "text": {
      "type": "plain_text",
      "text": "4.1.6",
      "emoji": true
    },
    "value": "4.1.6"
  }
]

option(text: Text, val: String): Option

Generates an option object with a text object and its value.

Option Object Reference

Parameters
NameTypeDescription
textTextThe text to use.
valueStringThe value to use in the option.
Example

This example generates an option with mrkdwn text to select the color red. Its value references the hex
color representation for red.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 option(mrkdwn("*Red*"), "FF0000")
Output
{
  "text": {
    "type": "mrkdwn",
    "text": "*Red*"
  },
  "value": "FF0000"
}

optionGroup ↑↑

optionGroup(message: String, options: Array<Option>): OptionGroup

Generates an option group object with a simple plain text object and its options.

Option Group Object Reference

Parameters
NameTypeDescription
messageStringThe value to use in the desired text.
optionsArray<Option>The options to group.
Example

This example generates an option group with a simple value for some options.

Source
%dw 2.0
output application/json
import * from slack::Builders
var options = ["4.3.0", "4.2.2"] map ((item) -> option(item, item))
---
 optionGroup("Recommended", options)
Output
{
  "label": {
    "type": "plain_text",
    "text": "Recommended",
    "emoji": true
  },
  "options": [
    {
      "text": {
        "type": "plain_text",
        "text": "4.3.0",
        "emoji": true
      },
      "value": "4.3.0"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "4.2.2",
        "emoji": true
      },
      "value": "4.2.2"
    }
  ]
}

optionGroup(text: PlainText, options: Array<Option>): OptionGroup

Generates an option group object with a plain text object and its options.

Option Group Object Reference

Parameters
NameTypeDescription
textPlainTextThe plain text to use.
optionsArray<Option>The options to group.
Example

This example generates an option group with text for some options.

Source
%dw 2.0
output application/json
import * from slack::Builders
var options = ["4.2.0", "4.2.1"] map ((item) -> option(item, item))
---
 optionGroup({'type': "plain_text", text: "Others"}, options)
Output
{
  "label": {
    "type": "plain_text",
    "text": "Others"
  },
  "options": [
    {
      "text": {
        "type": "plain_text",
        "text": "4.2.0",
        "emoji": true
      },
      "value": "4.2.0"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "4.2.1",
        "emoji": true
      },
      "value": "4.2.1"
    }
  ]
}

radioButtons ↑↑

radioButtons(id: String, options: Array<Option>): RadioButtonGroup

Generates a radio buttons group, given its ID and options.

Radio Button Group Element Reference

Parameters
NameTypeDescription
idStringThe value to use in the action_id field.
optionsArray<Option>The options to group.
Example

This example shows how radioButtons behaves.

Source
%dw 2.0
output application/json
---
radioButtons("food", ["spaghetti", "fusilli", "orecchiette"] map option($, $))
Output
{
  "type": "radio_buttons",
  "action_id": "food",
  "options": [
    {
      "text": {
        "type": "plain_text",
        "text": "spaghetti",
        "emoji": true
      },
      "value": "spaghetti"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "fusilli",
        "emoji": true
      },
      "value": "fusilli"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "orecchiette",
        "emoji": true
      },
      "value": "orecchiette"
    }
  ]
}

section ↑↑

section(message: String): Section

Generates a simple section block with a mrkdwn object.

Section Block Reference

Parameters
NameTypeDescription
messageStringThe value to use in the desired mrkdwn text.
Example

This example generates a section with mrkdwn text.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 section("Hello!")
Output
{
  "type": "section",
  "text": {
    "type": "mrkdwn",
    "text": "Hello!"
  }
}

section(text: Text): Section

Generates a section block with a text object.

Section Block Reference

Parameters
NameTypeDescription
textTextThe text object to use.
Example

This example generates a section with mrkdwn text.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 section(mrkdwn("*Hello*"))
Output
{
  "type": "section",
  "text": {
    "type": "mrkdwn",
    "text": "*Hello*"
  }
}

section(message: String, accessory: Element): Section

Generates a section block with a mrkdwn text object and an accessory element.

Section Block Reference

Parameters
NameTypeDescription
messageStringThe value to use in the desired mrkdwn text.
accessoryElementThe element to use.
Example

This example generates a section with simple text and a simple button.

Source
%dw 2.0
output application/json
---
section("*Tim's Farewell Party* is tonight at 8 PM", button("RSVP", "invite"))
Output
{
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": "*Tim's Farewell Party* is tonight at 8 PM"
    },
    "accessory": {
      "type": "button",
      "text": {
        "type": "plain_text",
        "text": "RSVP",
        "emoji": true
      },
      "action_id": "invite"
    }
  }

section(text: Text, accessory: Element): Section

Generates a section block with a text object and an accessory element.

Section Block Reference

Parameters
NameTypeDescription
textTextThe text object to use.
accessoryElementThe element to use.
Example

This example generates a section with mrkdwn text and a simple button.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 section(mrkdwn("*Hello*"), button("Click me!", "bait"))
Output
{
  "type": "section",
  "text": {
    "type": "mrkdwn",
    "text": "*Hello*"
  },
  "accessory": {
    "type": "button",
    "text": {
      "type": "plain_text",
      "text": "Click me!",
      "emoji": true
    },
    "action_id": "bait"
  }
}

section(fields: Array<Text>): Section

Generates a section block with an array of text objects or fields.

Section Block Reference

Parameters
NameTypeDescription
fieldsArray<Text>An array of text objects to use.
Example

This example generates a section with mrkdwn text and plain text.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 section([mrkdwn("*Hello*"), text("Bye!")])
Output
{
   "type": "section",
   "fields": [
     {
       "type": "mrkdwn",
       "text": "*Hello*"
     },
     {
       "type": "plain_text",
       "text": "Bye!",
       "emoji": true
     }
   ]
 }

section(fields: Array<Text>, accessory: Element): Section

Generates a section block with an array of text objects or fields, and an accessory element.

Section Block Reference

Parameters
NameTypeDescription
fieldsArray<Text>An array of text objects to use.
accessoryElementThe element to use.
Example

This example generates a section with mrkdwn text, plain text, and a simple button.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 section([mrkdwn("*Hello*"), text("Bye!")], button("Click me!", "bait"))
Output
{
  "type": "section",
  "fields": [
    {
      "type": "mrkdwn",
      "text": "*Hello*"
    },
    {
      "type": "plain_text",
      "text": "Bye!",
      "emoji": true
    }
  ],
  "accessory": {
    "type": "button",
    "text": {
      "type": "plain_text",
      "text": "Click me!",
      "emoji": true
    },
    "action_id": "bait"
  }
}

staticSelect ↑↑

staticSelect(placeholder: String, id: String, options: Array<Option>): StaticSelect

Generates a static select element with a simple plain text object as placeholder, its ID, and options.

Static Options Reference

Parameters
NameTypeDescription
messageStringThe value to use in the desired placeholder.
idStringThe value to use in an action_id field.
optionsArray<Option>The array of options to offer.
Example

This example creates a static group of options with a simple text placeholder.

Source
%dw 2.0
output application/json
import * from slack::Builders
var options = ["4.3.0", "4.2.2", "4.1.6"] map ((item) -> option(item, item))
---
 staticSelect("Choose a version...", "version_menu", options)
Output
{
  "type": "static_select",
  "placeholder": {
    "type": "plain_text",
    "text": "Choose a version...",
    "emoji": true
  },
  "action_id": "version_menu",
  "options": [
    {
      "text": {
        "type": "plain_text",
        "text": "4.3.0",
        "emoji": true
      },
      "value": "4.3.0"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "4.2.2",
        "emoji": true
      },
      "value": "4.2.2"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "4.1.6",
        "emoji": true
      },
      "value": "4.1.6"
    }
  ]
}

staticSelect(placeholder: PlainText, id: String, options: Array<Option>): StaticSelect

Generates an static select element with a simple plain text object as placeholder, its ID, and options.

Static Options Reference

Parameters
NameTypeDescription
messageStringThe value to use in the desired placeholder.
idStringThe value to use in an action_id field.
optionsArray<Option>The array of options to offer.
Example

This example creates a static group of options with a simple text placeholder.

Source
%dw 2.0
output application/json
import * from slack::Builders
var options = ["4.3.0", "4.2.2", "4.1.6"] map ((item) -> option(item, item))
---
 staticSelect("Choose a version...", "version_menu", options)
Output
{
  "type": "static_select",
  "placeholder": {
    "type": "plain_text",
    "text": "Choose a version...",
    "emoji": true
  },
  "action_id": "version_menu",
  "options": [
    {
      "text": {
        "type": "plain_text",
        "text": "4.3.0",
        "emoji": true
      },
      "value": "4.3.0"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "4.2.2",
        "emoji": true
      },
      "value": "4.2.2"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "4.1.6",
        "emoji": true
      },
      "value": "4.1.6"
    }
  ]
}

staticSelectByGroups ↑↑

staticSelectByGroups(placeholder: String, id: String, optionGroups: Array<OptionGroup>): StaticSelect

Generates a static select element with a simple plain text object as placeholder, its ID, and option groups.

Static Options Reference

Parameters
NameTypeDescription
messageStringThe value to use in the desired placeholder.
idStringThe value to use in an action_id field.
optionGroupsArray<OptionGroup>The array of options groups to offer.
Example

This example creates a static group of option groups with a simple text placeholder.

Source
%dw 2.0
output application/json
import * from slack::Builders
var recommendedGroup = optionGroup("Recommended", [option("4.3.0", "latest")])
var otherGroup = optionGroup("Other", [option("4.1.1", "original")])
---
 staticSelectGrouped("Choose a version...", "version_menu", [recommendedGroup, otherGroup])
Output
{
  "type": "static_select",
  "placeholder": {
    "type": "plain_text",
    "text": "Choose a version...",
    "emoji": true
  },
  "action_id": "version_menu",
  "option_groups": [
    {
      "label": {
        "type": "plain_text",
        "text": "Recommended",
        "emoji": true
      },
      "options": [
        {
          "text": {
            "type": "plain_text",
            "text": "4.3.0",
            "emoji": true
          },
          "value": "latest"
        }
      ]
    },
    {
      "label": {
        "type": "plain_text",
        "text": "Others",
        "emoji": true
      },
      "options": [
        {
          "text": {
            "type": "plain_text",
            "text": "4.1.1",
            "emoji": true
          },
          "value": "original"
        }
      ]
    }
  ]
}

staticSelectByGroups(placeholder: PlainText, id: String, optionGroups: Array<OptionGroup>): StaticSelect

Generates an static select element with a plain text object as placeholder, its ID, and option groups.

Static Options Reference

Parameters
NameTypeDescription
textPlainTextThe text to use as a placeholder.
idStringThe value to use in an action_id field.
optionGroupsArray<OptionGroup>The array of options groups to offer.
Example

This example creates a static group of option groups with a text placeholder.

Source
%dw 2.0
output application/json
import * from slack::Builders
var recommendedGroup = optionGroup("Recommended", [option("4.3.0", "latest")])
var otherGroup = optionGroup("Other", [option("4.1.1", "original")])
---
 staticSelectByGroups({'type': "plain_text", text:"Some versions"}, "version_menu", [recommendedGroup, otherGroup])
Output
{
  "type": "static_select",
  "placeholder": {
    "type": "plain_text",
    "text": "Some versions"
  },
  "action_id": "version_menu",
  "option_groups": [
    {
      "label": {
        "type": "plain_text",
        "text": "Recommended",
        "emoji": true
      },
      "options": [
        {
          "text": {
            "type": "plain_text",
            "text": "4.3.0",
            "emoji": true
          },
          "value": "latest"
        }
      ]
    },
    {
      "label": {
        "type": "plain_text",
        "text": "Others",
        "emoji": true
      },
      "options": [
        {
          "text": {
            "type": "plain_text",
            "text": "4.1.1",
            "emoji": true
          },
          "value": "original"
        }
      ]
    }
  ]
}

text ↑↑

text(message: String): PlainText

Generates a plain text object with emojis enabled.

Text Object Reference

Parameters
NameTypeDescription
messageStringThe text to use.
Example

This example generates a text object that has a wave emoji.

Source
%dw 2.0
output application/json
import * from slack::Builders
---
 text("Hello! :wave:")
Output
{
  "type": "plain_text",
  "text": "Hello! :wave:",
  "emoji": true
}

withStyle ↑↑

withStyle(button: Button, style: Style): Button

Adds a style field to a button.

Parameters
NameTypeDescription
buttonButtonThe button to add a value to.
styleStyleThe style to add.
Example

This example shows how to use withStyle.

Source
%dw 2.0
output application/json
---
button("Click me!", "bait") withStyle "danger"
Output
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Click me!",
    "emoji": true
  },
  "action_id": "bait",
  "style": "danger"
}

withUrl ↑↑

withUrl(button: Button, url: String): Button

Adds a URL field to a button.

Parameters
NameTypeDescription
buttonButtonThe button to add a value to.
urlStringThe URL to add.
Example

This example shows how to use withUrl.

Source
%dw 2.0
output application/json
---
button("Click me!", "bait") withUrl "http://httpbin.org"
Output
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Click me!",
    "emoji": true
  },
  "action_id": "bait",
  "url": "http://httpbin.org"
}

withValue ↑↑

withValue(button: Button, value: String): Button

Adds a value field to a button.

Parameters
NameTypeDescription
buttonButtonThe button to add a value to.
valueStringThe value to add.
Example

This example shows how to use withValue.

Source
%dw 2.0
output application/json
---
button("Click me!", "bait") withValue "spam"
Output
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Click me!",
    "emoji": true
  },
  "action_id": "bait",
  "value": "spam"
}


Reviews

TypeDataWeave Library
OrganizationMuleSoft
Published by
MuleSoft Organization
Published onMar 23, 2022
Asset overview

Asset versions for 1.0.x

Asset versions
VersionActions
1.0.0