turbot / flowpipe-mod-slack

Slack pipeline library for the Flowpipe cloud scripting engine. Automation and workflows to connect Slack to the people, systems and data that matters.
https://hub.flowpipe.io/mods/turbot/slack
Apache License 2.0
2 stars 1 forks source link

Add additional optional param for blocks #24

Closed johnlayton closed 2 months ago

johnlayton commented 2 months ago

Checklist

There is no issue yet. This should add the option to post Blocks JSON to Slack;

Sample;

  step "transform" "buckets" {
    value = jsondecode(<<EOT
  [
      {
          "type": "section",
          "text": {
              "type": "mrkdwn",
              "text": "Pick an item from the dropdown list"
          },
          "accessory": {
              "action_id": "select_bucket",
              "type": "static_select",
              "placeholder": {
                  "type": "plain_text",
                  "text": "Select a bucket...."
              },
              "options": [
                  %{ for idx, name in step.pipeline.buckets.output.buckets[*].Name }
                  {
                    "text" : {
                      "type" : "plain_text",
                      "text" : "${name}"
                    },
                    "value" : "${name}"
                  } %{ if idx < length(step.pipeline.buckets.output.buckets[*].Name) - 1 },%{ endif }
                  %{ endfor }
              ]
          }
      }
  ]
  EOT
    )
  }

  step "pipeline" "post_message" {
    pipeline = slack.pipeline.post_message
    args = {
      channel = "test"
      blocks = jsonencode(step.transform.buckets.value)
    }
  }

Result;

Screenshot 2024-09-04 at 9 35 08 PM

Sample;

  step "pipeline" "post_message" {
    pipeline = slack.pipeline.post_message
    args = {
      channel = "test"
      blocks = jsonencode([

        {
          "type" : "section",
          "block_id" : "section678",
          "text" : {
            "type" : "mrkdwn",
            "text" : "*This is a bold text block*"
          }
        },
        {
          "type" : "section",
          "block_id" : "section679",
          "text" : {
            "type" : "plain_text",
            "text" : "This is a plain text block"
          }
        },
        {
          "type": "section",
          "block_id" : "section680",
          "text": {
            "type": "mrkdwn",
            "text": "This is a section block with an accessory image."
          },
          "accessory": {
            "type": "image",
            "image_url": "https://pbs.twimg.com/profile_images/625633822235693056/lNGUneLX_400x400.jpg",
            "alt_text": "cute cat"
          }
        }

      ])
    }
  }

Produces;

Screenshot 2024-09-04 at 9 41 30 PM
misraved commented 2 months ago

Thanks @johnlayton for the enhancement 👍 !!

Following the above sample, could you please add a sample output/screenshot of how the block appears on slack?