mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-09 03:09:34 +00:00
perf: 优化通知,对支持 markdown 的发 markdown
This commit is contained in:
@@ -151,12 +151,29 @@ class DingTalk:
|
||||
'data': data
|
||||
}
|
||||
data = self._request.post(URL.SEND_MESSAGE_BY_TEMPLATE, json=body, with_token=True)
|
||||
return data
|
||||
|
||||
def send_markdown(self, user_ids, title, msg):
|
||||
body = {
|
||||
'agent_id': self._agentid,
|
||||
'userid_list': ','.join(user_ids),
|
||||
'to_all_user': False,
|
||||
'msg': {
|
||||
'msgtype': 'markdown',
|
||||
'markdown': {
|
||||
'title': title,
|
||||
'text': msg
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info(f'Dingtalk send markdown to user {user_ids}: {msg}')
|
||||
data = self._request.post(URL.SEND_MESSAGE, json=body, with_token=True)
|
||||
return data
|
||||
|
||||
def send_text(self, user_ids, msg):
|
||||
body = {
|
||||
'agent_id': self._agentid,
|
||||
'userid_list': ','.join(user_ids),
|
||||
# 'dept_id_list': '',
|
||||
'to_all_user': False,
|
||||
'msg': {
|
||||
'msgtype': 'text',
|
||||
@@ -165,7 +182,7 @@ class DingTalk:
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info(f'Dingtalk send text: user_ids={user_ids} msg={msg}')
|
||||
logger.info(f'Dingtalk send msg to user {user_ids}: {msg}')
|
||||
data = self._request.post(URL.SEND_MESSAGE, json=body, with_token=True)
|
||||
return data
|
||||
|
||||
|
@@ -90,7 +90,10 @@ class WeCom(RequestMixin):
|
||||
timeout=timeout
|
||||
)
|
||||
|
||||
def send_text(self, users: Iterable, msg: AnyStr, **kwargs):
|
||||
def send_markdown(self, users: Iterable, msg: AnyStr, **kwargs):
|
||||
pass
|
||||
|
||||
def send_text(self, users: Iterable, msg: AnyStr, markdown=False, **kwargs):
|
||||
"""
|
||||
https://open.work.weixin.qq.com/api/doc/90000/90135/90236
|
||||
|
||||
@@ -115,6 +118,13 @@ class WeCom(RequestMixin):
|
||||
},
|
||||
**extra_params
|
||||
}
|
||||
if markdown:
|
||||
body['msgtype'] = 'markdown'
|
||||
body["markdown"] = {
|
||||
"content": msg
|
||||
}
|
||||
body.pop('text', '')
|
||||
|
||||
logger.info(f'Wecom send text: users={users} msg={msg}')
|
||||
data = self._requests.post(URL.SEND_MESSAGE, json=body, check_errcode_is_0=False)
|
||||
|
||||
|
Reference in New Issue
Block a user