sendTextWithButton method

Future<void> sendTextWithButton({
  1. required String markdownMessage,
  2. required String buttonLabel,
  3. required String url,
})

pass markdownMessage as string text message, buttonLabel as string - button label, url as string - when user clicks button

Implementation

Future<void> sendTextWithButton({
  required String markdownMessage,
  required String buttonLabel,
  required String url,
}) async {
  _assertInstance();

  try {
    var postBody = jsonEncode(
      {
        "blocks": [
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": markdownMessage,
            },
            "accessory": {
              "type": "button",
              "text": {
                "type": "plain_text",
                "text": buttonLabel,
                "emoji": true
              },
              "value": "click_me_123",
              "url": url,
              "action_id": "button-action"
            }
          }
        ]
      },
    );
    requestUrl(postBody);
  } catch (e) {
    throw SlackLoggerException(e.toString());
  }
}