Completed
Pull Request — master (#554)
by
unknown
02:41
created

WechatNotifierAction   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 18
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 17 5
1
from st2actions.runners.pythonrunner import Action
2
from lib.wechatutil.wechatclient import WechatClient
3
4
5
class WechatNotifierAction(Action):
6
    def run(self, corpID, corpSecret, agentid, message, touser=None, togroup=None, totag=None):
7
        receivers = dict()
8
        if touser:
9
            receivers = {"touser": touser}
10
11
        if togroup:
12
            receivers.update({"toparty": togroup})
13
14
        if totag:
15
            receivers.update({"totag": totag})
16
17
        if len(receivers) == 0:
18
            raise KeyError('touser, togroup, totag can not be empty at the same time')
19
20
        wechatClient = WechatClient(corpID, corpSecret)
21
        wechatClient.sendTextMessage(agentid, message, **receivers)
22
        return
23