@@ -20,6 +20,7 @@ use IO::Async::Timer::Periodic;
2020use JSON::MaybeXS qw( decode_json encode_json) ;
2121use Lingua::EN::Inflect qw( PL_N PL_V) ;
2222use List::Util qw( first uniq) ;
23+ use Slack::BlockKit::Sugar -all => { -prefix => ' bk_' };
2324use Synergy::CommandPost;
2425use Synergy::Logger ' $Logger' ;
2526use Synergy::Util qw( reformat_help) ;
@@ -941,46 +942,38 @@ sub _announce_oncall_change ($self, $before, $after) {
941942 if (@leaving ) {
942943 my $verb = @leaving > 1 ? ' have' : ' has' ;
943944 my $removed = join ' , ' , sort @leaving ;
944- push @lines , " $removed $verb been removed from the oncall group" ;
945+ push @lines , " $removed $verb been removed from the oncall group. " ;
945946 }
946947
947948 if (@joining ) {
948949 my $verb = @joining > 1 ? ' have' : ' has' ;
949950 my $added = join ' , ' , sort @joining ;
950- push @lines , " $added $verb been added to the oncall group" ;
951+ push @lines , " $added $verb been added to the oncall group. " ;
951952 }
952953
953954 my $oncall = join ' , ' , sort keys %after ;
954955 push @lines , " Now oncall: $oncall " ;
955956
956957 my $text = join qq{ \n } , @lines ;
957958
958- my $blocks = [
959- {
960- type => " section" ,
961- text => {
962- type => " mrkdwn" ,
963- text => " $text " ,
964- }
965- },
966- ];
959+ my @blocks = bk_richsection(bk_richtext($text ))-> as_struct;
967960
968961 $self -> _active_incidents_summary-> then(sub ($summary = {}) {
969962 if (my $summary_text = delete $summary -> {text }) {
970963 $text .= " \n $summary_text " ;
971964 }
972965
973966 if (my $slack = delete $summary -> {slack }) {
974- push @$ blocks , { type => ' divider' };
975- push @$ blocks , $slack -> {blocks }-> @*;
967+ push @blocks , { type => ' divider' };
968+ push @blocks , $slack -> {blocks }-> @*;
976969 }
977970
978971 $self -> oncall_channel-> send_message(
979972 $self -> oncall_change_announce_address,
980973 $text ,
981974 {
982975 slack => {
983- blocks => $ blocks ,
976+ blocks => \ @ blocks ,
984977 }
985978 }
986979 );
@@ -1001,42 +994,29 @@ sub _active_incidents_summary ($self) {
1001994
1002995 my @text ;
1003996
1004- my $blocks = [
1005- {
1006- type => " section" ,
1007- text => {
1008- type => " mrkdwn" ,
1009- text => " *$title *" ,
1010- }
1011- },
1012- ];
997+ my @bk_items ;
1013998
1014999 for my $incident (@incidents ) {
10151000 my $created = $ISO8601 -> parse_datetime($incident -> {created_at });
10161001 my $ago = ago(time - $created -> epoch);
10171002
10181003 push @text , " - $incident ->{description} (fired $ago )" ;
10191004
1020- my $slack_text = sprintf (" • <%s |#%s > (fired %s ): %s " ,
1021- $incident -> {html_url },
1022- $incident -> {incident_number },
1023- $ago ,
1024- $incident -> {description },
1005+ push @bk_items , bk_richsection(
1006+ bk_link($incident -> {html_url }, " #$incident ->{incident_number}" ),
1007+ " (fired $ago ): $incident ->{description}" ,
10251008 );
1026-
1027- push @$blocks , {
1028- type => " section" ,
1029- text => {
1030- type => " mrkdwn" ,
1031- text => $slack_text ,
1032- }
1033- };
10341009 }
10351010
10361011 my $text = join qq{ \n } , $title , @text ;
10371012
10381013 my $slack = {
1039- blocks => $blocks ,
1014+ blocks => bk_blocks(
1015+ bk_richblock(
1016+ bk_richsection(bk_bold($title )),
1017+ bk_ulist(@bk_items ),
1018+ )
1019+ )-> as_struct,
10401020 };
10411021
10421022 return Future-> done({ text => $text , slack => $slack });
0 commit comments