yuheijotaki.com

Slack APIの確認ダイアログ

Slackメッセージ内のボタンクリックをトリガーとしてダイアログを表示させる場合。

ダイアログ内でユーザーのインプットが必要なときは dialog.open が必要。
Interacting with users through dialogs | Slack

シンプルに OK , Cancel などの2択のボタンをダイアログで置く場合は buttonconfirm フィールドで実装できる。
Reference: Composition objects | Slack

// main/function.gs
const blockKit = [
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": "ボタン横のテキスト"
    },
    "accessory": {
      "type": "button",
      "text": {
        "type": "plain_text",
        "text": "ボタンのラベルテキスト",
        "emoji": true
      },
      "value": "BUTTON CLICKED",
      "action_id": "button-action-id",
      "confirm": {
        "title": {
          "type": "plain_text",
          "text": "確認ダイアログのタイトルテキスト"
        },
        "text": {
          "type": "mrkdwn",
          "text": "確認ダイアログの本文テキスト"
        },
        "confirm": {
          "type": "plain_text",
          "text": "OK"
        },
        "deny": {
          "type": "plain_text",
          "text": "Cancel"
        }
      }
    }
  }
]
postSlack(blockKit)
// post/slack.gs
const postSlack = (blocks) => {
  const blockKit = blocks
  const endpoint = 'https://slack.com/api/chat.postMessage'
  const headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + SLACK_AUTH_TOKEN
  }
  const payload = {
    channel: SLACK_CHANNEL_ID,
    blocks: blockKit,
    unfurl_links: false,
    unfurl_media: false,
  }
  const params = {
    method : 'post',
    headers: headers,
    payload : JSON.stringify(payload),
  }
  UrlFetchApp.fetch(endpoint, params)
}

GASで受け取る場合、 doPost() の値にOKを押したときのみ BUTTON CLICKED が入ってくる。

// event/doPost.gs
const doPost = (event) => {
  const parameter = event.parameter
  const data = parameter.payload
  const json = JSON.parse(decodeURIComponent(data))

  const value = json.actions[0].value
  console.log(value) // BUTTON CLICKED
}