Breadcrumbs

Slack - Send Message Conditionally

Overview

Send a message to Slack conditionally by determining if a file exists or not.

Tasks built with this Template should never fail, as the presence or lack or presence of the file only indicates whether or not the message should be sent.

Works primarily when used as part of a Workflow, where a File can be generated or downloaded by an upstream Task.

Note: This Task cannot be used to access a local file from your computer.

Recommended Setup:

  1. A Workflow built with this Template should typically run after a Task that either downloads a file to Workflows or generates a file with code.

Variables

Name

Reference

Type

Required

Default

Options

Description

Destination Type

SLACK_DESTINATION_TYPE

Select

channel

Channel: channel

DM: dm

The type of location where you want your message to be sent. If Channel is selected, a message can be sent directly to a channel. If DM is selected, users can be sent messages directly from your app.

Channel Name

SLACK_CHANNEL_NAME

Alphanumeric

None

-

The name of the channel where you want your message to be sent, without the # prefix. This field will be ignored if the destination type is DM.

Users to Notify

SLACK_USERS_TO_NOTIFY

Alphanumeric

None

-

A comma separated list of case insensitive user emails, used to look up slack user IDs. This field is only required if the Destination Type is DM.

Message

SLACK_MESSAGE

Alphanumeric

None

-

The message that you want sent to a user. You can use all of the same markdown syntax that you would typically use in a Slack message. If you want to create a link in your message, you can use the format of

Send Message Only When

SLACK_CONDITIONAL_SEND

Select

file_exists

File(s) Exist: file_exists

File(s) Don't Exist: file_dne

Determines what condition needs to be met for a message to send. File(s) Exist - Send the message only if a file can be found using the provided folder/filename.ext combination. File(s) Don't Exist - Send the message only if a file cannot found using the provided folder/filename.ext combination.

File Name Match Type

SLACK_SOURCE_FILE_NAME_MATCH_TYPE

Select

exact_match

Regex: regex_match

Exact: exact_match

Determines if the text in "File Name" will look for one file with exact match, or multiple files using regex.

File Name

SLACK_SOURCE_FILE_NAME

Alphanumeric

None

-

The name of the file you want to search for.

Folder Name

SLACK_SOURCE_FOLDER_NAME

Alphanumeric

None

-

The folder that the file can be found in. Unless specified elsewhere, starts by looking in the current working directory. Can contain leading, trailing, or no slashes (if only looking for the file in a single folder). This field is not required and the folder name can technically be provided as part of the File Name.If left blank, will look for the file in the current working directory.

Upload File to Slack?

SLACK_UPLOAD_FILE

Select

no

Yes: yes

No: no

Determines whether or not the file(s) you're looking for to conditionally send the message should get uploaded to Slack. Defaults to no.

Include File In Thread

SLACK_INCLUDE_FILE_IN_THREAD

Select

yes

Yes: yes

No

Determines whether the file will be included in the main message, or as a reply in the thread. Default setting is a reply in the thread

Combine multiple files into one ZIP

SLACK_COMPRESS

Boolean

True

-

Bundle all matching files into one .zip for upload. Turn off to upload files individually.(Very large single files may still be zipped automatically.)

YAML

Below is the YAML template

YAML

source:
  template: Slack - Send Message Conditionally
  inputs:
    SLACK_DESTINATION_TYPE: channel
    SLACK_CHANNEL_NAME:
    SLACK_USERS_TO_NOTIFY:
    SLACK_MESSAGE:
    SLACK_CONDITIONAL_SEND: file_exists
    SLACK_SOURCE_FILE_NAME_MATCH_TYPE: exact_match
    SLACK_SOURCE_FILE_NAME:
    SLACK_SOURCE_FOLDER_NAME:
    SLACK_UPLOAD_FILE: no
    SLACK_INCLUDE_FILE_IN_THREAD: yes
    SLACK_COMPRESS: true
  type: TEMPLATE
guardrails:
  retry_count: 1
  retry_wait: 0h0m0s
  runtime_cutoff: 1h0m0s
  exclude_exit_code_ranges:
    - 100
    - 102
    - 200
    - 203