|
@@ -0,0 +1,103 @@
|
|
|
|
+import json
|
|
|
|
+import requests
|
|
|
|
+import config
|
|
|
|
+from BotClass import JabberBot
|
|
|
|
+import hashlib
|
|
|
|
+from datetime import datetime
|
|
|
|
+import time
|
|
|
|
+import threading
|
|
|
|
+import jsonAndRequest as jsreq
|
|
|
|
+
|
|
|
|
+global ticketlist
|
|
|
|
+
|
|
|
|
+botname = "st_request_in_process"
|
|
|
|
+JID = botname + "@" + config.JSERVER
|
|
|
|
+PORT = config.PORT
|
|
|
|
+PASSWORD = hashlib.md5((botname + config.PASSWORD).encode('utf-8')).hexdigest()
|
|
|
|
+
|
|
|
|
+listen_to = ["st_request_wontfix@ej.sharix-app.org"]
|
|
|
|
+proceed_to = ["numbers"]
|
|
|
|
+
|
|
|
|
+# Новые параметры
|
|
|
|
+DEFAULT_REMINDER_INTERVAL = 30 * 60 # 30 минут в секундах
|
|
|
|
+MAX_REMINDERS = 3 # Максимальное количество напоминаний (-1 для бесконечных уведомлений)
|
|
|
|
+DEFAULT_CHECK_INTERVAL = 5 * 60 # Проверка тикетов каждые 5 минут
|
|
|
|
+
|
|
|
|
+tickets = {}
|
|
|
|
+
|
|
|
|
+def send_reminder(user, ticket):
|
|
|
|
+ message = f"Напоминание: необходимо принять решение по тикету {ticket.id}"
|
|
|
|
+
|
|
|
|
+ # Здесь должен быть код для отправки сообщения пользователю
|
|
|
|
+ bot.send_notification("st_request_in_process@ej.sharix-app.org", "message")
|
|
|
|
+
|
|
|
|
+ print(f"Отправлено напоминание пользователю {user} о тикете {ticket.id}")
|
|
|
|
+
|
|
|
|
+# def send_wontfix_notification(user, ticket):
|
|
|
|
+# message = f"Уведомление: тикет {ticket.id} был отмечен как WONTFIX из-за отсутствия действий"
|
|
|
|
+# # Здесь должен быть код для отправки сообщения пользователю
|
|
|
|
+# print(f"Отправлено уведомление пользователю {user} о WONTFIX для тикета {ticket.id}")
|
|
|
|
+
|
|
|
|
+def process_in_progress_ticket(ticket, max_reminders, default_reminder_interval, start_time):
|
|
|
|
+ bot.bot_log(botname+" "+str(datetime.now())+" "+"Тикет в обработчике\n")
|
|
|
|
+ tickets_new=jsreq.requestGetTicket_user(token, config.API_URL+f"tickets/api/ticket_list/{ticket.id}")
|
|
|
|
+ if tickets_new:
|
|
|
|
+ if not ticket.id in tickets:
|
|
|
|
+ tickets[ticket.id] = {}
|
|
|
|
+ for ticket_new in tickets_new:
|
|
|
|
+ if ticket_new.id in tickets[ticket.id]:
|
|
|
|
+ tickets[ticket.id][ticket_new.id] = {
|
|
|
|
+ "reminders": 0,
|
|
|
|
+ "last_date_reminder": start_time
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (MAX_REMINDERS == -1 or tickets[ticket.id][ticket_new.id]['reminders'] < max_reminders) and (start_time - tickets[ticket.id][ticket_new.id]["last_date_reminder"]) > default_reminder_interval:
|
|
|
|
+ send_reminder("st_request_in_process@ej.sharix-app.org", ticket_new)
|
|
|
|
+
|
|
|
|
+ tickets[ticket.id][ticket_new.id]["reminders"] += 1
|
|
|
|
+ tickets[ticket.id][ticket_new.id]["last_date_reminder"] += start_time
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ # start_time = datetime.now()
|
|
|
|
+ # reminders_sent = 0
|
|
|
|
+
|
|
|
|
+ # current_time = datetime.now()
|
|
|
|
+ # time_in_progress = (current_time - start_time).total_seconds()
|
|
|
|
+
|
|
|
|
+ # if timeout != INFINITE_TIMEOUT and time_in_progress > timeout:
|
|
|
|
+ # # Превышен таймаут, меняем статус на WONTFIX
|
|
|
|
+ # jsreq.requestPatchTicketUser(token, config.API_URL + f"tickets/api/ticket/{ticket.id}/", {"status": "WONTFIX"})
|
|
|
|
+ # send_wontfix_notification(ticket.assigned_to, ticket)
|
|
|
|
+ # break
|
|
|
|
+
|
|
|
|
+ # if time_in_progress >= (reminders_sent + 1) * reminder_interval:
|
|
|
|
+ # send_reminder(ticket.assigned_to, ticket)
|
|
|
|
+ # reminders_sent += 1
|
|
|
|
+
|
|
|
|
+ # if reminders_sent >= MAX_REMINDERS:
|
|
|
|
+ # # Превышено максимальное количество напоминаний
|
|
|
|
+ # jsreq.requestPatchTicketUser(token, config.API_URL + f"tickets/api/ticket/{ticket.id}/", {"status": "WONTFIX"})
|
|
|
|
+ # send_wontfix_notification(ticket.assigned_to, ticket)
|
|
|
|
+ # break
|
|
|
|
+
|
|
|
|
+ # # Проверяем, не изменился ли статус тикета
|
|
|
|
+ # updated_ticket_list = jsreq.requestGetTicket_user(token, config.API_URL + f"tickets/api/ticket/{ticket.id}/")
|
|
|
|
+ # if updated_ticket_list and updated_ticket_list[0].status != "IN PROCESS":
|
|
|
|
+ # break
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def status_changer():
|
|
|
|
+ while True:
|
|
|
|
+ ticketlist = jsreq.requestGetList(token, config.API_URL + "tickets/api/ticket_list/")
|
|
|
|
+ for ticket in ticketlist:
|
|
|
|
+ bot.bot_log(f"{botname} {datetime.now().strftime('%Y-%m-%d')} Тикет {ticket.id} в обработке\n")
|
|
|
|
+ start_time = datetime.now()
|
|
|
|
+ t1 = threading.Thread(target=process_in_progress_ticket, args=(ticket, MAX_REMINDERS, DEFAULT_REMINDER_INTERVAL, start_time))
|
|
|
|
+ t1.start()
|
|
|
|
+ t1.join() # Ожидаем завершения обработки тикета
|
|
|
|
+ time.sleep(DEFAULT_CHECK_INTERVAL)
|
|
|
|
+
|
|
|
|
+# Инициализация и запуск бота
|
|
|
|
+token = jsreq.requestGetToken(config.API_URL + "api/v1/auth/token/login/")
|
|
|
|
+bot = JabberBot(JID, PASSWORD, PORT)
|
|
|
|
+bot.start(status_changer)
|