dart-app-core/lib/utils/slack/slack_template.dart
build@lguplus.co.kr c59bccf805 slack 업데이트
2023-12-08 16:03:24 +09:00

97 lines
No EOL
4.2 KiB
Dart

import 'package:dart_framework/utils/slack/slack_data.dart';
//Format info
//https://api.slack.com/reference/surfaces/formatting
class SlackTemplate {
static DataSlack getAttachments(String channel) {
DataSlack data = DataSlack(channel);
data.attachments = [];
var attachment = SlackAttachment();
attachment.fallback = 'Plain-text summary of the attachment.';
attachment.color = '#2eb886';
attachment.pretext = 'Optional text that appears above the attachment block';
attachment.author_name = 'Bobby Tables';
attachment.author_link = 'http://flickr.com/bobby/';
attachment.author_icon = 'http://flickr.com/icons/bobby.jpg';
attachment.title = 'Slack API Documentation';
attachment.title_link = 'https://api.slack.com/';
attachment.text = 'Optional text that appears within the attachment';
attachment.fields = [
SlackField.withParam('Priority', 'High', short: false),
];
attachment.image_url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Flat_tick_icon.svg/1024px-Flat_tick_icon.svg.png';
attachment.thumb_url = 'https://cdn-icons-png.flaticon.com/512/3771/3771140.png';
attachment.footer = 'Slack API';
attachment.footer_icon = 'https://platform.slack-edge.com/img/default_application_icon.png';
attachment.ts = '123456789';
data.attachments!.add(attachment);
return data;
}
static DataSlack getBlocks(String channel) {
DataSlack data = DataSlack(channel);
data.attachments = [];
var attachment = SlackAttachment();
data.blocks = [];
var blockSection = SlackBlockSection();
blockSection.text = SlackBlockText();
blockSection.text!.text = 'Danny Torrence left the following review for your property:';
data.blocks!.add(blockSection);
blockSection = SlackBlockSection();
blockSection.text = SlackBlockText();
blockSection.text!.text = '<https://example.com|Overlook Hotel> \n :star: \n Doors had too many axe holes, guest in room 237 was far too rowdy, whole place felt stuck in the 1920s.';
blockSection.accessory = SlackAccessory();
blockSection.accessory!.type = SlackActionType.image;
blockSection.accessory!.image_url = 'https://is5-ssl.mzstatic.com/image/thumb/Purple3/v4/d3/72/5c/d3725c8f-c642-5d69-1904-aa36e4297885/source/256x256bb.jpg';
blockSection.accessory!.alt_text = 'Haunted hotel image';
data.blocks!.add(blockSection);
blockSection = SlackBlockSection();
blockSection.block_id = 'section789';
blockSection.fields = [];
var field = SlackBlockText();
field.text = '*Average Rating*\n1.0';
blockSection.fields!.add(field);
data.blocks!.add(blockSection);
attachment.blocks = [];
blockSection = SlackBlockSection();
blockSection.text = SlackBlockText();
blockSection.text!.text = '*Alternative hotel options*';
attachment.blocks!.add(blockSection);
blockSection = SlackBlockSection();
blockSection.text = SlackBlockText();
blockSection.text!.text = '<https://example.com|Bates Motel> :star::star:';
blockSection.accessory = SlackAccessory();
blockSection.accessory!.type = SlackActionType.button;
blockSection.accessory!.url = 'https://www.google.com';
blockSection.accessory!.text = SlackBlockText();
blockSection.accessory!.text!.type = SlackTextType.plain_text;
blockSection.accessory!.text!.text = 'View';
blockSection.accessory!.text!.emoji = true;
blockSection.accessory!.value = 'view_alternate_1';
attachment.blocks!.add(blockSection);
blockSection = SlackBlockSection();
blockSection.text = SlackBlockText();
blockSection.text!.text = '<https://example.com|The Great Northern Hotel> :star::star::star::star:';
blockSection.accessory = SlackAccessory();
blockSection.accessory!.type = SlackActionType.button;
blockSection.accessory!.url = 'https://www.naver.com';
blockSection.accessory!.text = SlackBlockText();
blockSection.accessory!.text!.type = SlackTextType.plain_text;
blockSection.accessory!.text!.text = 'View';
blockSection.accessory!.text!.emoji = true;
blockSection.accessory!.value = 'view_alternate_2';
attachment.blocks!.add(blockSection);
data.attachments!.add(attachment);
return data;
}
}