import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:json_annotation/json_annotation.dart'; import 'package:dart_framework/utils/system_util.dart'; import 'package:http/http.dart'; // ignore: depend_on_referenced_packages, implementation_imports import 'package:http_parser/src/media_type.dart'; part 'slack_data.g.dart'; enum SlackActionType { button, select } enum SlackActionStyle { danger, primary } @JsonSerializable() class DataSlack { String? message; late List attachments; String getAttachments() { var list = []; for (var item in attachments) { list.add(item.toJson()); } return jsonEncode(list); } DataSlack(); factory DataSlack.fromJson(Map json) => _$DataSlackFromJson(json); Map toJson() => _$DataSlackToJson(this); } @JsonSerializable() class SlackAttachment { String? fallback; String? color; String? author_name; String? author_link; String? author_icon; String? title; String? title_link; String? pretext; String? text; String? image_url; String? thumb_url; String? footer; String? footer_icon; String? ts; List? fields; List? actions; SlackAttachment(); factory SlackAttachment.fromJson(Map json) => _$SlackAttachmentFromJson(json); Map toJson() => _$SlackAttachmentToJson(this); } @JsonSerializable() class SlackField { String? title; String? value; SlackField(); SlackField.withParam(this.title, this.value); factory SlackField.fromJson(Map json) => _$SlackFieldFromJson(json); Map toJson() => _$SlackFieldToJson(this); } @JsonSerializable() class SlackAction { SlackActionType? type; String? name; String? text; String? url; String? value; SlackActionStyle? style; /*SlackField options; SlackConfirm confirm;*/ SlackAction(); SlackAction.withParam( this.name, this.text, this.url, this.value, this.type, this.style); factory SlackAction.fromJson(Map json) => _$SlackActionFromJson(json); Map toJson() => _$SlackActionToJson(this); } @JsonSerializable() class SlackConfirm { String? title; String? text; // ignore: non_constant_identifier_names String? ok_text; // ignore: non_constant_identifier_names String? dismiss_text; } // To-do: File upload test @JsonSerializable() class SlackFile { String? title; // ignore: non_constant_identifier_names String? initial_comment; String? filePath; String? fileName; String? mimeType; Future setFileData(MultipartRequest form) async { // var bytes = await readFileByte(filePath!); if (title != null) { form.fields['title'] = title!; } if (initial_comment != null) { form.fields['initial_comment'] = initial_comment!; } form.fields['filetype'] = "auto"; //참조 - https://api.slack.com/types/file#file_types if (fileName != null && mimeType != null) { form.files.add(MultipartFile.fromBytes( 'file', await File.fromUri(Uri.parse(filePath!)).readAsBytes(), contentType: MediaType(HttpHeaders.contentTypeHeader, mimeType!))); } var c = Completer(); c.complete(form); return c.future; } }