@@ -26,8 +26,9 @@ type Module struct {
26
26
Config * config.Module
27
27
Logger * logger.Module
28
28
29
- client slackClient
30
- config struct {
29
+ LogMessages bool
30
+ client slackClient
31
+ config struct {
31
32
SlackConfig struct {
32
33
Channel string `json:"channel"`
33
34
APIToken string `json:"api_token"`
@@ -56,14 +57,7 @@ type PostMessageParameters = slack.PostMessageParameters
56
57
57
58
// Post a message to the default channel
58
59
func (m * Module ) Post (txt string , params * PostMessageParameters ) {
59
- var p PostMessageParameters
60
- if params != nil {
61
- p = * params
62
- }
63
- _ , _ , err := m .client .PostMessage (m .config .SlackConfig .Channel , txt , p )
64
- if err != nil {
65
- m .Logger .Error (errors .Wrap (err ))
66
- }
60
+ m .PostC (m .config .SlackConfig .Channel , txt , params )
67
61
}
68
62
69
63
// PostC posts a message to the given channel
@@ -72,6 +66,9 @@ func (m *Module) PostC(channel, txt string, params *PostMessageParameters) {
72
66
if params != nil {
73
67
p = * params
74
68
}
69
+ if m .LogMessages {
70
+ m .Logger .Infof ("[%s] %s" , m .config .SlackConfig .Channel , txt )
71
+ }
75
72
_ , _ , err := m .client .PostMessage (channel , txt , p )
76
73
if err != nil {
77
74
m .Logger .Error (errors .Wrap (err ))
@@ -83,6 +80,6 @@ type dummyClient struct {
83
80
}
84
81
85
82
func (d * dummyClient ) PostMessage (channel , text string , params slack.PostMessageParameters ) (string , string , error ) {
86
- d .logger .Infof ("[%s] %s" , channel , text )
83
+ d .logger .Infof ("[%s] %s (not sent) " , channel , text )
87
84
return "" , "" , nil
88
85
}
0 commit comments