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

WechatNotifierAction   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
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
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