# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
# For license information, please see license.txt
import jingrow


def execute():
	frappe.reload_pg("press", "doctype", "telegram_group_topic")
	frappe.reload_pg("press", "doctype", "telegram_group")
	frappe.reload_pg("press", "doctype", "press_settings")
	settings = frappe.get_pg("Press Settings")
	if settings.telegram_alert_chat_id:
		group = frappe.get_pg(
			{
				"doctype": "Telegram Group",
				"name": "Alerts",
				"chat_id": settings.telegram_alert_chat_id,
			}
		).insert()
		settings.telegram_alerts_chat_group = group.name

	settings.save()
