Rewrite TG integration, support for other webhooks

This commit is contained in:
Aarni Halinen
2022-01-13 00:05:02 +02:00
parent 6f316401f7
commit 4a530826a8
15 changed files with 461 additions and 258 deletions
+6 -7
View File
@@ -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(