Jump to content

Send Ticket note hook


snake

Recommended Posts

I have the following hook, but it is not working, no email is being sent, can anyone tell me why?

 

<?php

 

//hook to send notes to all dept staff rather than only to the person assigned to the ticket.

 

if (!defined("WHMCS"))

die("This file cannot be accessed directly");

 

function send_note_ticket($vars) {

 

$ticketid = $vars['ticketid'];

$message = $vars['message'];

$adminid = $vars['adminid'];

 

//Get department id

$query = mysql_query("SELECT `did`,`tid` FROM `tbltickets` WHERE `id` = '$ticketid'");

$dep_data = mysql_fetch_assoc($query);

$departmentid = $dep_data['did'];

$tid = $dep_data['tid'];

 

//send email notification

$command = "sendadminemail";

$adminuser = "ADMINAPI";//change this if you change admin username

$values = array();

$values["messagename"] = "Ticket Note Added";

$values["mergefields"] = array(

"ticket_id" => $ticketid,

"ticket_tid" => $tid,

"ticket_message" => $message,

);

$values["type"] = "support";

$values["deptid"] = $departmentid;

 

$results = localAPI($command,$values,$adminuser);

 

}

 

add_hook("TicketAddNote",1,"send_note_ticket");

Link to comment
Share on other sites

Thanks I had a look, I cannot reply to that thread since it is too old.

This looks like it sends an email to ALL staff.

Do you know, Is there any way to limit it to only send an email staff of the DEPT that the ticket is in, so that billing and sales not get an email about a SUPPORT ticket.

This is what my hook did.

Link to comment
Share on other sites

I was assuming you were just going to take your deptid query and replace the adminroles query from the other script.

 

but if you say your hook code worked previously, then it might be worth outputting at each step to see where the issue lies... I assume there is an admin email template called "Ticket Note Added" ??

Link to comment
Share on other sites

I was assuming you were just going to take your deptid query and replace the adminroles query from the other script.

 

but if you say your hook code worked previously, then it might be worth outputting at each step to see where the issue lies... I assume there is an admin email template called "Ticket Note Added" ??

 

I did not write this hook myself, I am not a PHP developer.

Link to comment
Share on other sites

  • 1 month later...

Below is my updated code.

You need to create an email template, this really belongs under admin messages, which you cannot create via WHMCS, so you will need to do in via PHPMyAdmin if you want to put it there.

 

subject: Note Added to ticket #{$ticket_tid} {$ticket_subject}

content:

{$sender} has added the following note to ticket

----------------------------------------------
Ticket ID: #{$ticket_tid}
Subject: {$subject}
Status: {$status}
----------------------------------------------
Note:
{$ticket_message}

 

<?php

//hook to send notes to all dept staff rather than only to the person assigned to the ticket.

if (!defined("WHMCS"))
die("This file cannot be accessed directly");

function send_note_ticket($vars) {

$ticketid = $vars['ticketid'];
$message = $vars['message'];
$adminid = $vars['adminid'];

//Get department id
$query = mysql_query("SELECT `did`,`tid`,`title`,`status` FROM `tbltickets` WHERE `id` = '$ticketid'");
$dep_data = mysql_fetch_assoc($query);
$query = mysql_query("SELECT `firstname`,`lastname` FROM `tbladmins` WHERE `id` = '$adminid'");
$sender = mysql_fetch_assoc($query);
$departmentid = $dep_data['did'];
$tid = $dep_data['tid'];
$subject = $dep_data['title'];
$status = $dep_data['status'];

//send email notification
$command = "sendadminemail";
$adminuser = "ADMINAPI";//change this if you change admin username
$values = array();
$values["messagename"] = "Ticket Note Added";
$values["mergefields"] = array(
	"ticket_id" => $ticketid,
	"ticket_tid" => $tid,
	"ticket_message" => $message,
	"subject" => $subject,
	"status" => $status,
	"sender" => $sender['firstname'] . " " . $sender['lastname']
);
$values["type"] = "support";
$values["deptid"] = $departmentid;

$results = localAPI($command,$values,$adminuser);
logModuleCall('API', 'SendAdminEmail', $values, $results);

}

add_hook("TicketAddNote",1,"send_note_ticket");

Link to comment
Share on other sites

You need to create an email template, this really belongs under admin messages, which you cannot create via WHMCS, so you will need to do in via PHPMyAdmin if you want to put it there.

I suppose you could create it as a general message from within WHMCS, and then just edit the 'type' value in tblemailtemplates... you'd still need to do that in phpmyadmin (or similar), but might be slightly easier for those unfamiliar with interacting with the tables directly.

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