Support integrations

Answer ticket

answerTicket()

Gets executed when a customer answers to an existing ticket in the storefront.

Parameters

Type

Name

Description

Ticket

$ticket

The Ticket object of hostware. The $ticket->ticket_provider_external_id contains the external ticket id.

string

$message

The message

array

$attachments

Array of Symfony attachments

Response

TicketAnsweredResponse() class.

Type

Name

Description

mixed

messageId

The ID of the message. Usually integer or UUID.

array

attachmentFilePaths

Array of file paths in the same order as the input files.

Example Code

public function answerTicket(Ticket $ticket, string $message, array $attachments): TicketAnsweredResponse {
	$threadAttachments = [];
	foreach ($attachments as $attachment) {
		$threadAttachments[] = [
			'fileName' => $attachment->getClientOriginalName(),
			'mimeType' => $attachment->getMimeType(),
			'data' => base64_encode($attachment->getContent()),
		];
	}

	$customerId = $this->getCustomerId($ticket->customer);

	$response = $this->makeRequest("conversations/{$ticket->ticket_provider_external_id}/threads", "POST", [
		'text' => $message,
		'type' => 'customer',
		'customer' => [
			'id' => $customerId,
		],
		"attachments" => $threadAttachments
	]);

	/**
	 * Get the attachment IDs
	 */
	$attachmentResponse = [];
	foreach ($response->_embedded->attachments as $file) {
		$attachmentResponse[] = $file->id;
	}

	return new TicketAnsweredResponse(
		$response->id,
		$attachmentResponse,
	);
}

Testing

You can test this function by answering a ticket as a customer.

Was this helpful?