21 lines
1.2 KiB
Python
21 lines
1.2 KiB
Python
from datetime import datetime
|
|
from decouple import config
|
|
|
|
from chalicelib.core.collaboration_slack import Slack
|
|
|
|
|
|
def send_batch(notifications_list):
|
|
if notifications_list is None or len(notifications_list) == 0:
|
|
return
|
|
webhookId_map = {}
|
|
for n in notifications_list:
|
|
if n.get("destination") not in webhookId_map:
|
|
webhookId_map[n.get("destination")] = {"tenantId": n["notification"]["tenantId"], "batch": []}
|
|
webhookId_map[n.get("destination")]["batch"].append({"text": n["notification"]["description"] \
|
|
+ f"\n<{config('SITE_URL')}{n['notification']['buttonUrl']}|{n['notification']['buttonText']}>",
|
|
"title": n["notification"]["title"],
|
|
"title_link": n["notification"]["buttonUrl"],
|
|
"ts": datetime.now().timestamp()})
|
|
for batch in webhookId_map.keys():
|
|
Slack.send_batch(tenant_id=webhookId_map[batch]["tenantId"], webhook_id=batch,
|
|
attachments=webhookId_map[batch]["batch"])
|