Commit 06526c2f authored by Zac Wood's avatar Zac Wood

Send slack messages on /newLink

parent bb7b3254
Pipeline #5143 passed with stages
in 2 minutes and 7 seconds
......@@ -14,4 +14,5 @@ GO_EMAIL_HOST_PASSWORD=
import requests
from django.conf import settings
import logging
import sys
import functools
from threading import Thread
logger = logging.getLogger(__name__)
def build_msg(request):
target = request.POST['target']
short = f'{request.POST["short"]}'
return f'Short: {short}\nTarget: {target}'
def send_slack_message(msg):
# Send slack message
slack_url = settings.SLACK_URL
Thread(, args=(slack_url,), kwargs={ 'json': { 'text': msg }}).start()
......@@ -18,10 +18,12 @@ from django.utils import timezone
# Other imports
from ratelimit.decorators import ratelimit
import requests
# App Imports
from .forms import URLForm, EditForm
from .models import URL, RegisteredUser
from .utils import build_msg, send_slack_message
def index(request):
......@@ -88,6 +90,9 @@ def _new_link_post(request):
# Call our post method to assemble our new URL object
res = post(request, url_form)
if settings.SLACK_URL:
# If there is a 500 error returned, handle it
if res == 500:
return HttpResponseServerError(render(request, '500.html'))
......@@ -193,3 +193,5 @@ EMAIL_TO = os.environ["GO_EMAIL_TO"]
# Domain used to email to users. See implementation in
# ie. ''
SLACK_URL = os.environ.get("GO_SLACK_URL", "")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment