Rewrite TG integration, support for other webhooks
This commit is contained in:
+6
-7
@@ -20,7 +20,7 @@ from ohlhafv.models import OhlhafvChallenge
|
||||
from ohlhafv.forms import OhlhafvForm
|
||||
from ohlhafv.tables import OhlhafvTable
|
||||
from webapp.utils import send_email
|
||||
from kaehmy.tgbot import TelegramBot
|
||||
from webapp.webhook import processHooks
|
||||
|
||||
|
||||
@require_http_methods(["GET"])
|
||||
@@ -43,22 +43,21 @@ def ohlhafv_submit(request, *args, **kwargs):
|
||||
url = f'https://{URL}/ohlhafv/list'
|
||||
subject = _('Sinut on haastettu Ohlhäfviin!')
|
||||
|
||||
message = render_to_string(
|
||||
email_body = render_to_string(
|
||||
'ohlhafv:email.html', {
|
||||
'challenge': challenge,
|
||||
'url': url,
|
||||
}
|
||||
)
|
||||
send_email(email, subject, message)
|
||||
send_email(email, subject, email_body)
|
||||
|
||||
try:
|
||||
tg_message = render_to_string(
|
||||
webhook_message = render_to_string(
|
||||
'ohlhafv:tgmsg.tpl', {
|
||||
'challenge': challenge,
|
||||
'url': url})
|
||||
bot = TelegramBot()
|
||||
bot.broadcast(tg_message)
|
||||
except Exception: # tg spam is not critical. Ignore on failure
|
||||
processHooks(message=webhook_message, eventType="ohlhafv")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
logging.debug(
|
||||
|
||||
Reference in New Issue
Block a user