Jump to content

Follow Ups


TaskHusky

Recommended Posts

I'm trying to achieve a support ticket reminder setup. 

If a ticket within the sales department is in the status of Answered for 3 days or longer, I want to trigger another Supply Reply email reminding the client that the ticket is still needing a reply. The following script is what I have; however, it doesn't seem to be working in my tests. What is wrong with the current code?

<?php

use WHMCS\Database\Capsule;

// Require the init.php file to access WHMCS functions
require_once dirname(__FILE__) . '/../../init.php';

// Set time threshold (72 hours in seconds)
$timeThreshold = 72 * 60 * 60;
$currentTime = time();

// Get tickets that meet our criteria
$tickets = Capsule::table('tbltickets')
    ->where('department', '=', 1) // Sales department
    ->where('status', '=', 'Answered')
    ->where('clientunread', '=', 1)
    ->get();

foreach ($tickets as $ticket) {
    // Get the last reply timestamp
    $lastReply = Capsule::table('tblticketreplies')
        ->where('tid', '=', $ticket->id)
        ->orderBy('date', 'desc')
        ->first();
    
    $lastReplyTime = strtotime($lastReply ? $lastReply->date : $ticket->date);
    $hoursSinceReply = ($currentTime - $lastReplyTime) / 3600;
    
    // Check if it's time to send a reminder (every 72 hours)
    if ($hoursSinceReply >= 72 && ($hoursSinceReply % 72) < 1) {
        // Send reminder email
        $client = localAPI('GetClientsDetails', array('clientid' => $ticket->userid));
        
        $merge_fields = array(
            'ticket_id' => $ticket->tid,
            'ticket_subject' => $ticket->title,
            'client_name' => $client['client_name'],
        );
        
        sendMessage(
            'Support Ticket Reply',  // Email template name
            $ticket->userid,            // Client ID
            $merge_fields              // Merge fields
        );
        
        // Log the reminder
        logActivity("Sent reminder for Ticket #" . $ticket->tid . " to client #" . $ticket->userid);
    }
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated