@@ -43,8 +43,7 @@ func (ctx *slackContext) L() *zap.Logger {
4343}
4444
4545func (ctx * slackContext ) MessageLimit () int {
46- // https://stackoverflow.com/questions/60344831/slack-api-invalid-block
47- return 2500
46+ return 2000
4847}
4948
5049func (ctx * slackContext ) StampNames () * domain.StampNames {
@@ -57,21 +56,26 @@ func (ctx *slackContext) StampNames() *domain.StampNames {
5756 }
5857}
5958
60- func (ctx * slackContext ) sendSlackMessage (channelID string , text string ) error {
59+ func (ctx * slackContext ) sendSlackMessage (channelID string , lines [] string , color string ) error {
6160 api := ctx .api
6261 return utils .WithRetry (ctx , 10 , func (ctx context.Context ) error {
63- _ , _ , err := api .PostMessage (channelID , slack .MsgOptionBlocks (
64- slack .NewSectionBlock (
65- slack .NewTextBlockObject (
66- slack .MarkdownType ,
67- text ,
68- false ,
69- false ,
70- ),
71- nil ,
72- nil ,
73- ),
74- ))
62+ var options []slack.MsgOption
63+ options = append (options , slack .MsgOptionText (lines [0 ], false ))
64+ if len (lines ) >= 2 {
65+ options = append (options , slack .MsgOptionAttachments (
66+ slack.Attachment {
67+ Color : color ,
68+ Fields : []slack.AttachmentField {
69+ {
70+ Title : "" ,
71+ Value : strings .Join (lines [1 :], "\n " ),
72+ Short : false ,
73+ },
74+ },
75+ },
76+ ))
77+ }
78+ _ , _ , err := api .PostMessage (channelID , options ... )
7579 return err
7680 })
7781}
@@ -83,17 +87,17 @@ func (ctx *slackContext) pushSlackReaction(message slack.ItemRef, stampID string
8387 })
8488}
8589
86- func (ctx * slackContext ) reply (message ... string ) error {
87- return ctx .sendSlackMessage (ctx .message .Channel , strings . Join ( message , " \n " ) )
90+ func (ctx * slackContext ) reply (color string , message ... string ) error {
91+ return ctx .sendSlackMessage (ctx .message .Channel , message , color )
8892}
8993
90- func (ctx * slackContext ) replyWithStamp (stamp string , message ... string ) error {
94+ func (ctx * slackContext ) replyWithStamp (stamp string , color string , message ... string ) error {
9195 err := ctx .pushSlackReaction (ctx .message , stamp )
9296 if err != nil {
9397 return err
9498 }
9599 if len (message ) > 0 {
96- err = ctx .reply (message ... )
100+ err = ctx .reply (color , message ... )
97101 if err != nil {
98102 return err
99103 }
@@ -102,21 +106,21 @@ func (ctx *slackContext) replyWithStamp(stamp string, message ...string) error {
102106}
103107
104108func (ctx * slackContext ) ReplyBad (message ... string ) error {
105- return ctx .replyWithStamp (config .C .Stamps .BadCommand , message ... )
109+ return ctx .replyWithStamp (config .C .Stamps .BadCommand , config . C . Slack . Colors . BadCommand , message ... )
106110}
107111
108112func (ctx * slackContext ) ReplyForbid (message ... string ) error {
109- return ctx .replyWithStamp (config .C .Stamps .Forbid , message ... )
113+ return ctx .replyWithStamp (config .C .Stamps .Forbid , config . C . Slack . Colors . Forbid , message ... )
110114}
111115
112116func (ctx * slackContext ) ReplySuccess (message ... string ) error {
113- return ctx .replyWithStamp (config .C .Stamps .Success , message ... )
117+ return ctx .replyWithStamp (config .C .Stamps .Success , config . C . Slack . Colors . Success , message ... )
114118}
115119
116120func (ctx * slackContext ) ReplyFailure (message ... string ) error {
117- return ctx .replyWithStamp (config .C .Stamps .Failure , message ... )
121+ return ctx .replyWithStamp (config .C .Stamps .Failure , config . C . Slack . Colors . Failure , message ... )
118122}
119123
120124func (ctx * slackContext ) ReplyRunning (message ... string ) error {
121- return ctx .replyWithStamp (config .C .Stamps .Running , message ... )
125+ return ctx .replyWithStamp (config .C .Stamps .Running , config . C . Slack . Colors . Running , message ... )
122126}
0 commit comments