diff --git a/scripts/wk/osticket.py b/scripts/wk/osticket.py index 7b700dd9..0bb4336a 100644 --- a/scripts/wk/osticket.py +++ b/scripts/wk/osticket.py @@ -4,6 +4,7 @@ import atexit import logging import socket +import time import mysql.connector as mariadb @@ -174,6 +175,41 @@ class osTicket(): # pylint: disable=invalid-name LOG.error('Ticket ID not set') raise RuntimeError('Ticket ID not set') + def post_response(self, response, color='Normal'): + """Post a reply to a ticket in osTicket.""" + self._connect() + self._verify_ticket_id() + + # Bail if disabled + if self.disabled: + return + + # Format response + response = str(response).replace("`", "'").replace("'", "\\'") + + # Build SQL cmd + sql_cmd = ( + f"INSERT INTO `{SQL['DB']}`.`{TABLE_RESPONSE}` " + f"(ticket_id, staff_id, staff_name, response, created, code) " + f"VALUES (" + f" '{self.ticket_id}'," + f" '{STAFF['ID']}'," + f" '{STAFF['Name']}'," + f" '{response}'," + f" '{time.strftime('%Y-%m-%d %H:%M:%S')}'," + f" '{RESPONSE_COLOR_CODES.get(color, 'Normal')}'" + f");" + ) + + # Run SQL cmd + try: + self.db_cursor.execute(sql_cmd) + except mariadb.errors.Error: + self.errors = True + + # Done + self._disconnect() + def select_ticket(self): """Set ticket number and name from osTicket DB.""" print_standard('Connecting to osTicket...')