Completed
Pull Request — master (#527)
by
unknown
02:48
created

WechatNotifierAction.run()   B

Complexity

Conditions 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
dl 0
loc 17
rs 8.5454
1
from st2actions.runners.pythonrunner import Action
2
from lib.wechatutil.wechatclient import WechatClient
3
class WechatNotifierAction(Action):
4
    def run(self, corpID, corpSecret, agentid, message, touser=None, togroup=None, totag=None):
5
        receivers=dict()
6
        if touser:
7
            receivers={"touser": touser}
8
9
        if togroup:
10
            receivers.update({"toparty": togroup})
11
12
        if totag:
13
            receivers.update({"totag": totag})
14
15
        if len(receivers) == 0:
16
            raise KeyError('touser, togroup, totag can not be empty at the same time')
17
18
        wechatClient=WechatClient(corpID, corpSecret)
19
        wechatClient.sendTextMessage(agentid, message,**receivers)
20
        return