Jump to content

auto email clients when ticket status changed to "in progress"


hoya8

Recommended Posts

Hi Community

We do know Katamaze/WHMCS-Action-Hook-Factory 's  hook about emailing clients when tickets status changed but the problems was that this hook even emails clients when we really type something on ticket to reply to client, clients will receive two emails, which is confuing

is there anyway to let us only auto-email clients when ticket status changed to "in progress"?  and also include ticket ID on email subject?

email only no auto reply to ticket needed

thanks

 

<?php

/**
 * Send Email & Add Reply on Ticket status change
 *
 * @package     WHMCS
 * @copyright   Katamaze
 * @link        https://katamaze.com
 * @author      Davide Mantenuto <info@katamaze.com>
 */

use WHMCS\Database\Capsule;

add_hook('TicketStatusChange', 1, function($vars) {

    $adminUsername = 'admin'; // The reply will be added by this Admin user. Set false to open the ticket using your own customer
    $ticketDetails = Capsule::table('tbltickets')->where('id', $vars['ticketid'])->first(['userid', 'tid', 'title']);

    // Email notification
    $EmailData = array(
        'id' => $ticketDetails->userid,
        'customtype' => 'general',
        'customsubject' => $ticketDetails->title. ' Changed to ' . strtoupper($vars['status']) . ' [Ticket ID #' . $ticketDetails->tid . ']',
        'custommessage' => 'Your ticket status has been changed to ' .$vars['status']
    );

    localAPI('SendEmail', $EmailData);

    // Ticket reply
    $TicketData = array(
        'ticketid' => $vars['ticketid'],
        'message' => $ticketDetails->title. ' Changed to ' . strtoupper($vars['status']) . ' [Ticket ID #' . $ticketDetails->tid . ']',
        'clientid' => $userID,
        'adminusername' => $adminUsername,
    );

    localAPI('AddTicketReply', $TicketData);
});

 

Link to comment
Share on other sites

17 hours ago, hoya8 said:

is there anyway to let us only auto-email clients when ticket status changed to "in progress"?  and also include ticket ID on email subject?

it should be as simple as wrapping the Email Notification part in an if statement...

<?php

use WHMCS\Database\Capsule;

add_hook('TicketStatusChange', 1, function($vars) {

	if ($vars['status'] == "In Progress") {
		$ticketDetails = Capsule::table('tbltickets')->where('id', $vars['ticketid'])->first(['userid', 'tid', 'title']);
		// Email notification
		$EmailData = array(
			'id' => $ticketDetails->userid,
			'customtype' => 'general',
			'customsubject' => $ticketDetails->title. ' Changed to ' . strtoupper($vars['status']) . ' [Ticket ID #' . $ticketDetails->tid . ']',
			'custommessage' => 'Your ticket status has been changed to ' .$vars['status']
		);
		localAPI('SendEmail', $EmailData);
	}
});

with regards to the email subject, it should already include the ticket ID, but if you wanted the subject to contain only the TID, then it would be..

			'customsubject' => '[Ticket ID #' . $ticketDetails->tid . ']',
Link to comment
Share on other sites

10 minutes ago, hoya8 said:

is there any way to make it show translated status
so clients will see "in progress"  in their own chosen language

'custommessage' => 'Your ticket status has been changed to ' . Lang::trans('supportticketsstatusinprogress')

you could use a custom language override for the entire line if you wanted to.

Link to comment
Share on other sites

great thanks again man , so final hook for us, as a note here, is

 

<?php

use WHMCS\Database\Capsule;

add_hook('TicketStatusChange', 1, function($vars) {

	if ($vars['status'] == "In Progress") {
		$ticketDetails = Capsule::table('tbltickets')->where('id', $vars['ticketid'])->first(['userid', 'tid', 'title']);
		// Email notification
		$EmailData = array(
			'id' => $ticketDetails->userid,
			'customtype' => 'general',
			'customsubject' => ' [Ticket ID #' . $ticketDetails->tid . ']' . $ticketDetails->title. ' staus is changed ' . strtoupper(Lang::trans('supportticketsstatusinprogress')),
			'custommessage' => 'Your ticket status has been changed to ' . Lang::trans('supportticketsstatusinprogress')
		);
		localAPI('SendEmail', $EmailData);
	}
});

 

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