Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial mattermost notification system
- Loading branch information
1 parent
2b97d18
commit bb9f941
Showing
5 changed files
with
88 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from blinker import Namespace | ||
|
||
namespace = Namespace() | ||
|
||
#: Trigerred when a spam is detected | ||
on_new_potential_spam = namespace.signal('on-new-potential-spam') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import requests | ||
from udata.tasks import connect | ||
from udata.core.spam.signals import on_new_potential_spam | ||
from flask import current_app | ||
|
||
@connect(on_new_potential_spam) | ||
def notify_potential_spam(title, link, text, reason): | ||
message = ':warning: @all Spam potentiel sur \n' | ||
if link: | ||
message += f'[{title}]({link})' | ||
else: | ||
message += title | ||
|
||
message += f' ({reason})\n\n' | ||
message += f'> {text}' | ||
|
||
send_message(message) | ||
|
||
|
||
def send_message(text: str): | ||
"""Send a message to a mattermost channel | ||
Args: | ||
text (str): Text to send to a channel | ||
""" | ||
data = {'text': text} | ||
|
||
r = requests.post(current_app.config.get('MATTERMOST_WEBHOOK', []), json=data) | ||
r.raise_for_status() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters