Developer hooks
Wrangler calls ExpressionEngine extension hooks when tickets change, so another add-on can post to Slack, update a CRM, or add rules of its own without editing Wrangler.
| Hook | Arguments | When |
|---|---|---|
wrangler_ticket_created |
$ticket, $message |
A ticket was opened, from the form or in code. |
wrangler_message_added |
$ticket, $message |
Any message was added: customer, staff, internal note or system. Check $message->is_internal and $message->author_type. |
wrangler_ticket_updated |
$ticket, $changes |
Status, priority, queue, assignee or subject changed. $changes is ['status' => ['pending', 'open'], ...]. |
wrangler_ticket_deleted |
$snapshot |
A ticket was deleted. The ticket is gone, so this is an array: ticket_id, site_id, reference, subject, status, requester_name, requester_email. |
$ticket is a wrangler:Ticket model and $message a wrangler:TicketMessage model.
Every hook fires after the change is saved, from every path that makes it: the control
panel, the front-end forms, emailed replies, the auto-close sweep, and your own code calling the
service. A customer reply that reopens a ticket fires wrangler_ticket_updated and then
wrangler_message_added.
If an extension throws, Wrangler writes it to the developer log and carries on. A broken integration does not stop a customer filing a ticket.
Example
class Support_slack_ext
{
public $version = '1.0.0';
public function activate_extension()
{
ee('Model')->make('Extension', [
'class' => __CLASS__,
'method' => 'onCreated',
'hook' => 'wrangler_ticket_created',
'settings' => '',
'version' => $this->version,
'enabled' => 'y',
])->save();
}
public function onCreated($ticket, $message)
{
// $ticket->reference, $ticket->subject, $ticket->requester_email ...
}
}
Working with tickets in code
Every change goes through one service, which keeps the history and fires the hooks:
$service = ee('wrangler:TicketService');
$ticket = $service->createTicket([
'subject' => 'Order did not arrive',
'message' => 'Ordered last week…',
'guest_name' => 'Jane Doe',
'guest_email' => 'jane@example.com',
'meta' => ['order_number' => 'FH-1042'],
]);
$service->addMessage($ticket->getId(), ['message' => 'Following up', 'author_type' => 'staff']);
$service->updateTicket($ticket->getId(), ['status' => 'pending']);
The service sends no email. To notify, call ee('wrangler:Notifier') yourself, as the control
panel and the front end do.