Rewrite TG integration, support for other webhooks
This commit is contained in:
+3
-12
@@ -13,10 +13,11 @@ from dealer.git import git
|
||||
from sikweb.settings import URL
|
||||
|
||||
from members.views.utils import *
|
||||
from kaehmy.models import Application, CustomRole, PresetRole, TelegramChannel
|
||||
from kaehmy.models import Application, CustomRole, PresetRole
|
||||
from kaehmy.forms import ApplicationForm, CommentForm
|
||||
from kaehmy.tables import ExportTable
|
||||
from webapp.utils import send_email
|
||||
from webapp.webhook import processHooks
|
||||
|
||||
|
||||
@ensure_csrf_cookie
|
||||
@@ -135,17 +136,7 @@ def submit(request, *args, **kwargs):
|
||||
send_email(email, subject, body)
|
||||
logging.debug('Sent kaehmy email to recipient <{}>'.format(email))
|
||||
|
||||
CHAT_IDS = [channel.channel_id for channel in TelegramChannel.objects.all()]
|
||||
for chat_id in CHAT_IDS:
|
||||
tg_string = 'https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}'.format(
|
||||
settings.TELEGRAM_BOT_TOKEN,
|
||||
chat_id,
|
||||
'Uusi New kaehmy! {} -> {}'.format(name, url)
|
||||
)
|
||||
response = requests.get(tg_string).json()
|
||||
logging.debug('Telegram API response:\n{}'.format(response))
|
||||
logging.debug('Sent kaehmy announcement to {} channels.'.format(len(CHAT_IDS)))
|
||||
|
||||
processHooks(message=f'Uusi New kaehmy! {name} -> {url}', eventType="kaehmy")
|
||||
else:
|
||||
context = {
|
||||
'error': form.errors
|
||||
|
||||
Reference in New Issue
Block a user