Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Endpoints/MessagesEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Lettermint\Responses\MessageEventsResponse;
use Lettermint\Responses\MessageListResponse;
use Lettermint\Responses\MessageResponse;
use Lettermint\Responses\ProcessInboundMessageResponse;
use Lettermint\Responses\ScheduledMessageResponse;

class MessagesEndpoint extends Endpoint
Expand All @@ -30,6 +31,11 @@ public function cancel(string $messageId): ScheduledMessageResponse
return $this->hydrate(ScheduledMessageResponse::class, $this->postArray($this->path('/messages/{messageId}/cancel', ['messageId' => $messageId])));
}

public function process(string $messageId): ProcessInboundMessageResponse
{
return $this->hydrate(ProcessInboundMessageResponse::class, $this->postArray($this->path('/messages/{messageId}/process', ['messageId' => $messageId])));
}

public function events(string $messageId, array $query = []): MessageEventsResponse
{
return $this->hydrate(MessageEventsResponse::class, $this->getArray($this->path('/messages/{messageId}/events', ['messageId' => $messageId]), $query));
Expand Down
13 changes: 13 additions & 0 deletions src/Responses/ProcessInboundMessageResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Lettermint\Responses;

use Lettermint\Resource;

/**
* @property array{message_id: string, status: 'queued', webhook_target_count: int} $data
*/
final class ProcessInboundMessageResponse extends Resource
{
//
}
5 changes: 3 additions & 2 deletions src/Types/ApiTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @phpstan-type ApiObject array<string, mixed>
* @phpstan-type CursorPage array{data: list<ApiObject>, path: string|null, per_page: int, next_cursor: string|null, next_page_url: string|null, prev_cursor: string|null, prev_page_url: string|null}
* @phpstan-type MessageStatus 'scheduled'|'pending'|'queued'|'suppressed'|'processed'|'delivered'|'opened'|'clicked'|'soft_bounced'|'hard_bounced'|'spam_complaint'|'failed'|'blocked'|'policy_rejected'|'unsubscribed'|'canceled'
* @phpstan-type MessageStatus 'scheduled'|'pending'|'queued'|'quarantined'|'suppressed'|'processed'|'delivered'|'opened'|'clicked'|'soft_bounced'|'hard_bounced'|'spam_complaint'|'failed'|'blocked'|'policy_rejected'|'unsubscribed'|'canceled'
* @phpstan-type SendMailRequest array{route?: string, from: string, to: non-empty-list<string>, cc?: list<string>, bcc?: list<string>, reply_to?: list<string>, subject: string, scheduled_at?: string, headers?: array<string, string>, metadata?: array<string, string>, tag?: string|null, tags?: list<array{name: string, value: string}>, settings?: array{track_opens?: bool, track_clicks?: bool, tls?: TlsPolicy}|null, html?: string|null, text?: string|null, attachments?: list<array{filename: string, content: string, content_type?: string|null, content_id?: string|null}>}
* @phpstan-type SendBatchMailRequest list<SendMailRequest>
* @phpstan-type TlsPolicy 'opportunistic'|'enforced'
Expand All @@ -26,7 +26,7 @@
* @phpstan-type MessageAttachmentData array{size: int, filename: string, content_id: string|null, content_type: string}
* @phpstan-type MessageData array{id: string, type: MessageType, status: MessageStatus, status_changed_at: string|null, scheduled_at: string|null, tag: string|null, tags: list<array{name: string, value: string}>, from_email: string, from_name: string|null, reply_to: list<string>|null, subject: string|null, to: list<MessageRecipientData>|null, cc: list<MessageRecipientData>|null, bcc: list<MessageRecipientData>|null, attachments: list<MessageAttachmentData>|null, metadata: array<string, string>|null, spam_score?: float|int|null, spam_symbols?: list<SpamSymbol>, route_id: string, created_at: string}
* @phpstan-type MessageEventData array{message_id: string, event: MessageEventType, tag: string|null, tags: list<array{name: string, value: string}>, metadata: array<string, mixed>|null, timestamp: string}
* @phpstan-type MessageEventType 'scheduled'|'rescheduled'|'canceled'|'released'|'queued'|'processed'|'suppressed'|'delivered'|'auto_replied'|'soft_bounced'|'hard_bounced'|'spam_complaint'|'failed'|'blocked'|'policy_rejected'|'unsubscribed'|'opened'|'clicked'|'inbound_received'|'inbound_queued'|'inbound_spam_blocked'|'inbound_processed'|'inbound_retry'
* @phpstan-type MessageEventType 'scheduled'|'rescheduled'|'canceled'|'released'|'queued'|'processed'|'suppressed'|'delivered'|'auto_replied'|'soft_bounced'|'hard_bounced'|'spam_complaint'|'failed'|'blocked'|'policy_rejected'|'unsubscribed'|'opened'|'clicked'|'inbound_received'|'inbound_queued'|'inbound_spam_blocked'|'inbound_released'|'inbound_processed'|'inbound_retry'
* @phpstan-type MessageListData array{id: string, type: MessageType, status: MessageStatus, scheduled_at: string|null, spam_score?: float|int|null, from_email: string, from_name: string|null, subject: string|null, to: list<MessageRecipientData>|null, cc: list<MessageRecipientData>|null, bcc: list<MessageRecipientData>|null, reply_to: list<string>|null, tag: string|null, tags: list<array{name: string, value: string}>, status_changed_at: string|null, created_at: string}
* @phpstan-type MessageRecipientData array{email: string, name: string|null}
* @phpstan-type MessageStatsData array{messages_transactional: int, messages_broadcast: int, messages_inbound: int, deliverability: float|int}
Expand Down Expand Up @@ -96,6 +96,7 @@
* @phpstan-type MessageListResponse array{data: list<MessageListData>, links: list<string>, meta: array{path: string|null, per_page: int, next_cursor: string|null, next_cursor_url: string|null, prev_cursor: string|null, prev_cursor_url: string|null}}
* @phpstan-type MessageResponse MessageData
* @phpstan-type MessageEventsResponse array{data: list<MessageEventData>, links: list<string>, meta: array{path: string|null, per_page: int, next_cursor: string|null, next_cursor_url: string|null, prev_cursor: string|null, prev_cursor_url: string|null}}
* @phpstan-type ProcessInboundMessageResponse array{data: array{message_id: string, status: 'queued', webhook_target_count: int}}
* @phpstan-type ProjectListResponse array{data: list<ProjectListData>, path: string|null, per_page: int, next_cursor: string|null, next_page_url: string|null, prev_cursor: string|null, prev_page_url: string|null}
* @phpstan-type CreateProjectResponse array{data: ProjectData, message: string, api_token: string}
* @phpstan-type ProjectResponse ProjectData
Expand Down
6 changes: 6 additions & 0 deletions tests/Endpoints/MessagesEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
expect($this->endpoint->cancel('message-id')->status)->toBe('canceled');
});

test('it processes a quarantined inbound message', function () {
$this->httpClient->shouldReceive('post')->once()->with('/v1/messages/message-id/process', [], [])->andReturn(['data' => ['message_id' => 'message-id', 'status' => 'queued', 'webhook_target_count' => 1]]);

expect($this->endpoint->process('message-id')->data['status'])->toBe('queued');
});

test('it retrieves message events', function () {
$query = ['include_machine_events' => true];
$this->httpClient->shouldReceive('get')->once()->with('/v1/messages/message-id/events', $query)->andReturn(['data' => []]);
Expand Down
3 changes: 2 additions & 1 deletion tests/SdkCoverageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
['team', 'message.show', MessagesEndpoint::class, 'retrieve'],
['team', 'rescheduleMessage', MessagesEndpoint::class, 'reschedule'],
['team', 'cancelScheduledMessage', MessagesEndpoint::class, 'cancel'],
['team', 'processInboundMessage', MessagesEndpoint::class, 'process'],
['team', 'message.events', MessagesEndpoint::class, 'events'],
['team', 'message.source', MessagesEndpoint::class, 'source'],
['team', 'message.html', MessagesEndpoint::class, 'html'],
Expand Down Expand Up @@ -67,7 +68,7 @@
['team', 'webhook.showDelivery', WebhooksEndpoint::class, 'delivery'],
];

expect($operations)->toHaveCount(52);
expect($operations)->toHaveCount(53);

$missing = [];

Expand Down