File tree 2 files changed +11
-3
lines changed
2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 2
2
# This is example of config file for slacker.
3
3
# There are two sections:
4
4
# * default: this is default options for sending message to slack.
5
- # * rules: list of rules for matching email message. Currently 'from',
5
+ # * rules: list of rules for matching email message. Currently 'from',
6
6
# 'to' and 'subject' fields are supported. Their values can be
7
7
# regexp to match corresponding email field.
8
- #
8
+ #
9
9
# Each rule in list tested in order. First matched rule is used to update
10
10
# values from 'default' section with its 'options' subsection.
11
11
# #####
@@ -16,6 +16,7 @@ default:
16
16
icon_url : ' '
17
17
slack_token : xoxb-00000000000-aaaaaaaaaaaaaaaaaaaaaaaa
18
18
debug : false
19
+ format : " subject: %(subject)s; body: %(body)s" # # default slack message format
19
20
20
21
21
22
rules :
38
39
channel : ' #cron'
39
40
icon_url : ' '
40
41
debug : true # # will output full email with all headers
42
+ format : " email body is: %(body)s" # # custom message format
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ def handle_message(self, message):
25
25
options = self .process_rules (message )
26
26
27
27
print ('matched' , options )
28
- self .send_to_slack (message . get_payload ( ), ** options )
28
+ self .send_to_slack (self . extract_text ( message ), ** options )
29
29
30
30
if options ['debug' ]:
31
31
self .send_to_slack ('DEBUG: ' + str (message ), ** options )
@@ -58,6 +58,12 @@ def process_rules(self, message):
58
58
59
59
return default
60
60
61
+ def extract_text (self , message ):
62
+ fmt = self .config ['default' ].get ('format' , '%(body)s' )
63
+ body = message .get_payload ()
64
+ subject = message ['Subject' ]
65
+ return fmt % dict (body = body , subject = subject )
66
+
61
67
def send_to_slack (self , text , ** options ):
62
68
print ('sending to slack' , text , options )
63
69
You can’t perform that action at this time.
0 commit comments