sendMarkdownAsAttachment method

Future<void> sendMarkdownAsAttachment({
  1. required List<String> markdownMessageList,
  2. required String color,
})

pass markdownMessageList as List of String markdown pass color as String (HEX) It'll show as attachments in slack

Implementation

Future<void> sendMarkdownAsAttachment({
  required List<String> markdownMessageList,
  required String color,
}) async {
  _assertInstance();

  try {
    dynamic values;
    List<dynamic> listOfValues = [];
    for (var i = 0; i < markdownMessageList.length; i++) {
      values = {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": markdownMessageList[i],
        }
      };
      listOfValues.add(values);
    }
    var postBody = jsonEncode({
      "attachments": [
        {
          "color": color,
          "blocks": listOfValues,
        }
      ]
    });

    requestUrl(postBody);
  } catch (e) {
    throw SlackLoggerException(e.toString());
  }
}