# -*- coding: utf-8 -*-
# Copyright (c) 2021, JINGROW
# For license information, please see license.txt

import jingrow

from jcloud.telegram_utils import Telegram
from jcloud.utils import log_error


@jingrow.whitelist(allow_guest=True, xss_safe=True)
def hook(*args, **kwargs):
	try:
		# set user to Administrator, to not have to do ignore_permissions everywhere
		jingrow.set_user("Administrator")

		client = Telegram()
		client.respond(kwargs.get("message", kwargs.get("edited_message")))

	except Exception:
		log_error("Telegram Webhook Error", args=args, kwargs=kwargs)
	finally:
		jingrow.set_user("Guest")
