# Answer ticket

## answerTicket()

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

### Parameters

<table><thead><tr><th width="142">Type</th><th width="166">Name</th><th>Description</th></tr></thead><tbody><tr><td>Ticket</td><td>$ticket</td><td>The Ticket object of hostware. The $ticket->ticket_provider_external_id contains the external ticket id.</td></tr><tr><td>string</td><td>$message</td><td>The message</td></tr><tr><td>array</td><td>$attachments</td><td>Array of Symfony attachments</td></tr></tbody></table>

### Response

TicketAnsweredResponse() class.&#x20;

<table><thead><tr><th width="142">Type</th><th width="166">Name</th><th>Description</th></tr></thead><tbody><tr><td>mixed</td><td>messageId</td><td>The ID of the message. Usually integer or UUID.</td></tr><tr><td>array</td><td>attachmentFilePaths</td><td>Array of file paths in the same order as the input files.</td></tr></tbody></table>

### Example Code

```php
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.
