
#################
NotificationEvent
#################


****
NAME
****


Kernel::System::NotificationEvent - to manage the notifications


***********
DESCRIPTION
***********


All functions to manage the notification and the notification jobs.


****************
PUBLIC INTERFACE
****************


new()
=====


Don't use the constructor directly, use the ObjectManager instead:


.. code-block:: perl

     my $NotificationEventObject = $Kernel::OM->Get('Kernel::System::NotificationEvent');



NotificationList()
==================


returns a hash of all notifications


.. code-block:: perl

     my %List = $NotificationEventObject->NotificationList(
         Type    => 'Ticket', # type of notifications; default: 'Ticket'
         Details => 1,        # include notification detailed data. possible (0|1) # ; default: 0
         All     => 1,        # optional: if given all notification types will be returned, even if type is given (possible: 0|1)
     );



NotificationGet()
=================


returns a hash of the notification data


.. code-block:: perl

     my %Notification = $NotificationEventObject->NotificationGet(
         Name => 'NotificationName',
     );
 
     my %Notification = $NotificationEventObject->NotificationGet(
         ID => 1,
     );


Returns:


.. code-block:: perl

     %Notification = (
         ID      => 123,
         Name    => 'Agent::Move',
         Data => {
             Events => [ 'TicketQueueUpdate' ],
             # ...
             Queue => [ 'SomeQueue' ],
         },
         Message => {
             en => {
                 Subject     => 'Hello',
                 Body        => 'Hello World',
                 ContentType => 'text/plain',
             },
             de => {
                 Subject     => 'Hallo',
                 Body        => 'Hallo Welt',
                 ContentType => 'text/plain',
             },
         },
         Comment    => 'An optional comment',
         ValidID    => 1,
         CreateTime => '2010-10-27 20:15:00',
         CreateBy   => 2,
         ChangeTime => '2010-10-27 20:15:00',
         ChangeBy   => 1,
         UserID     => 3,
     );



NotificationAdd()
=================


adds a new notification to the database


.. code-block:: perl

     my $ID = $NotificationEventObject->NotificationAdd(
         Name => 'Agent::OwnerUpdate',
         Data => {
             Events => [ 'TicketQueueUpdate' ],
             # ...
             Queue => [ 'SomeQueue' ],
         },
         Message => {
             en => {
                 Subject     => 'Hello',
                 Body        => 'Hello World',
                 ContentType => 'text/plain',
             },
             de => {
                 Subject     => 'Hallo',
                 Body        => 'Hallo Welt',
                 ContentType => 'text/plain',
             },
         },
         Comment => 'An optional comment', # (optional)
         ValidID => 1,
         UserID  => 123,
     );



NotificationUpdate()
====================


update a notification in database


.. code-block:: perl

     my $Ok = $NotificationEventObject->NotificationUpdate(
         ID      => 123,
         Name    => 'Agent::OwnerUpdate',
         Data => {
             Events => [ 'TicketQueueUpdate' ],
             # ...
             Queue => [ 'SomeQueue' ],
         },
         Message => {
             en => {
                 Subject     => 'Hello',
                 Body        => 'Hello World',
                 ContentType => 'text/plain',
             },
             de => {
                 Subject     => 'Hallo',
                 Body        => 'Hallo Welt',
                 ContentType => 'text/plain',
             },
         },
         Comment => 'An optional comment',  # (optional)
         ValidID => 1,
         UserID  => 123,
     );



NotificationDelete()
====================


deletes an notification from the database


.. code-block:: perl

     $NotificationEventObject->NotificationDelete(
         ID     => 1,
         UserID => 123,
     );



NotificationEventCheck()
========================


returns array of notification affected by event


.. code-block:: perl

     my @IDs = $NotificationEventObject->NotificationEventCheck(
         Event => 'ArticleCreate',
     );



NotificationExport()
====================


export a notification


.. code-block:: perl

     my $ExportData = $NotificationEventObject->NotificationExport(
         # required either ID or ExportAll
         ID                       => $NotificationID,
         ExportAll                => 0,               # possible: 0, 1
 
         UserID                   => 1,               # required
         Type                     => 'Ticket',        # optional, default: 'Ticket'
         All                      => 1                # optional, default: undef
     }


returns Notification hashes in an array with data:


.. code-block:: perl

     my $ExportData =
     [
         {
             'ChangeTime' => '2024-02-06 14:49:56',
             'ValidID' => 1,
             'ID' => 16,
             'CreateBy' => 1,
             'Data' => {
                 'Transports' => [
                     'Email'
                 ],
                 'LanguageID' => [
                     'en'
                 ],
                 'VisibleForAgent' => [
                     '1'
                 ],
                 'Events' => [
                     'UserMention'
                 ],
                 'ArticleAttachmentInclude' => [
                     '0'
                 ],
                 'AgentEnabledByDefault' => [
                     'Email'
                 ],
                 'TransportEmailTemplate' => [
                     'Default'
                 ]
             },
             'Name' => 'Mention notification',
             'ChangeBy' => 1,
             'Comment' => '',
             'CreateTime' => '2024-02-06 14:49:56',
             'Message' => {
                 'en' => {
                     'ContentType' => 'text/plain',
                     'Body' => 'Hi <OTRS_NOTIFICATION_RECIPIENT_UserFirstname>,


you have been mentioned in ticket <OTRS_TICKET_NUMBER>.
<OTRS_AGENT_BODY[5]>

<OTRS_CONFIG_HttpType>://<OTRS_CONFIG_FQDN>/<OTRS_CONFIG_ScriptAlias>index.pl?Action=AgentTicketZoom;TicketID=<OTRS_TICKET_TicketID>

-- <OTRS_CONFIG_NotificationSenderName>',
                    'Subject' => 'Mention in ticket: <OTRS_TICKET_Title>'
                },
                'de' => {
                    'ContentType' => 'text/plain',
                    'Body' => "Hallo <OTRS_NOTIFICATION_RECIPIENT_UserFirstname> <OTRS_NOTIFICATION_RECIPIENT_UserLastname>,

Sie wurden erw\x{e4}hnt in Ticket <OTRS_TICKET_NUMBER>.
<OTRS_AGENT_BODY[5]>

<OTRS_CONFIG_HttpType>://<OTRS_CONFIG_FQDN>/<OTRS_CONFIG_ScriptAlias>index.pl?Action=AgentTicketZoom;TicketID=<OTRS_TICKET_TicketID>

-- <OTRS_CONFIG_NotificationSenderName>",
                    'Subject' => "Erw\x{e4}hnung in Ticket: <OTRS_TICKET_Title>"
                }
            }
        }
    ]


NotificationImport()
====================


import an Notification YAML file/content


.. code-block:: perl

     my $NotificationImport = $NotificationEventObject->NotificationImport(
         Content                        => $YAMLContent, # mandatory, YAML format
         OverwriteExistingNotifications => 0,            # optional, possible: 0, 1
         UserID                         => 1,            # mandatory
     );


Returns:


.. code-block:: perl

     $NotificationImport = {
         Success          => 1,                                  # 1 if success or undef if operation could not
                                                                 # be performed
         Message          => 'The Message to show.',             # error message
         Added            => 'Notification1, Notification2',     # string list of Notifications correctly added
         Updated          => 'Notification3, Notification4',     # string list of Notifications correctly updated
         NotUpdated       => 'Notification5, Notification6',     # string of Notifications not updated due to existing entity
                                                                 # with the same name
         Errors           => 'Notification5',                    # string list of Notifications that could not be added or updated
         AdditionalErrors => ['Some error occured!', 'Error2!'], # list of additional error not necessarily related to specified Notification
 
         # for compatibility with existing code
         AddedNotifications   => 'Notification1, Notification2',     # string list of Notifications correctly added
         UpdatedNotifications => 'Notification3, Notification4',     # string list of Notifications correctly updated
         NotificationErrors   => 'Notification5',                    # string list of Notifications that could not be added or updated
     };



NotificationCopy()
==================


copy a notification


.. code-block:: perl

     my $NewNotificationID = $NotificationEventObject->NotificationCopy(
         ID     => 1, # mandatory
         UserID => 1, # mandatory
     );



NotificationBodyCheck()
=======================


Check if body has a proper length depending on DB type.


.. code-block:: perl

     my $Ok = $NotificationEventObject->NotificationBodyCheck(
         Content => $BodyContent, # mandatory
         UserID  => 1,            # mandatory
     );



NotificationExportDataGet()
===========================


get data to export notification


.. code-block:: perl

     my %NotificationData = $NotificationEventObject->NotificationExportDataGet(
         ID               => 1, # mandatory
     );


Returns:


.. code-block:: perl

     my %NotificationData = (
         'ChangeTime' => '2024-02-06 14:49:56',
         'ValidID' => 1,
         'ID' => 16,
         'CreateBy' => 1,
         'Data' => {
             'Transports' => [
                 'Email'
             ],
             'LanguageID' => [
                 'en'
             ],
             'VisibleForAgent' => [
                 '1'
             ],
             'Events' => [
                 'UserMention'
             ],
             'ArticleAttachmentInclude' => [
                 '0'
             ],
             'AgentEnabledByDefault' => [
                 'Email'
             ],
             'TransportEmailTemplate' => [
                 'Default'
             ]
         },
         'Name' => 'Mention notification',
         'ChangeBy' => 1,
         'Comment' => '',
         'CreateTime' => '2024-02-06 14:49:56',
         'Message' => {
             'en' => {
                 'ContentType' => 'text/plain',
                 'Body' => 'Hi <OTRS_NOTIFICATION_RECIPIENT_UserFirstname>,


you have been mentioned in ticket <OTRS_TICKET_NUMBER>.
<OTRS_AGENT_BODY[5]>

<OTRS_CONFIG_HttpType>://<OTRS_CONFIG_FQDN>/<OTRS_CONFIG_ScriptAlias>index.pl?Action=AgentTicketZoom;TicketID=<OTRS_TICKET_TicketID>

-- <OTRS_CONFIG_NotificationSenderName>',
                'Subject' => 'Mention in ticket: <OTRS_TICKET_Title>'
            },
            'de' => {
                'ContentType' => 'text/plain',
                'Body' => "Hallo <OTRS_NOTIFICATION_RECIPIENT_UserFirstname> <OTRS_NOTIFICATION_RECIPIENT_UserLastname>,

Sie wurden erw\x{e4}hnt in Ticket <OTRS_TICKET_NUMBER>.
<OTRS_AGENT_BODY[5]>

<OTRS_CONFIG_HttpType>://<OTRS_CONFIG_FQDN>/<OTRS_CONFIG_ScriptAlias>index.pl?Action=AgentTicketZoom;TicketID=<OTRS_TICKET_TicketID>

-- <OTRS_CONFIG_NotificationSenderName>",
                'Subject' => "Erw\x{e4}hnung in Ticket: <OTRS_TICKET_Title>"
            }
        }
    )


NotificationExportFilenameGet()
===============================


get export file name based on notification name & type


.. code-block:: perl

     my $Filename = $NotificationEventObject->NotificationExportFilenameGet(
         Type => 'Appointment',
         Name => 'notification_1',
         Format => 'YAML',
     );





