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
31 changes: 31 additions & 0 deletions src/__tests__/lib/api/resources/Webhooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,37 @@ describe("lib/api/resources/Webhooks: ", () => {
}
}
});

it("creates an inbound_receiving webhook linked to an inbox.", async () => {
const inboundParams = {
url: "https://example.com/mailtrap/webhooks",
webhook_type: "inbound_receiving" as const,
payload_format: "json" as const,
inbound_inbox_id: 1,
};
const inboundResponseData = {
data: {
id: 3,
url: "https://example.com/mailtrap/webhooks",
active: true,
webhook_type: "inbound_receiving",
payload_format: "json",
inbound_inbox_id: 1,
signing_secret: "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
},
};
const endpoint = `${GENERAL_ENDPOINT}/api/accounts/${accountId}/webhooks`;
const expectedBody = { webhook: inboundParams };

expect.assertions(3);

mock.onPost(endpoint, expectedBody).reply(200, inboundResponseData);
const result = await webhooksAPI.create(inboundParams);

expect(mock.history.post[0].url).toEqual(endpoint);
expect(JSON.parse(mock.history.post[0].data)).toEqual(expectedBody);
expect(result).toEqual(inboundResponseData);
});
});

describe("get(): ", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/api/resources/Webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export default class WebhooksApi {
}

/**
* Update an existing webhook. Only `url`, `active`, `payload_format`, and
* `event_types` can be changed; `webhook_type`, `sending_stream`, and
* `domain_id` are immutable after creation.
* Update an existing webhook. Only `url`, `active`, `payload_format`,
* `event_types`, and `inbound_inbox_id` can be changed; `webhook_type`,
* `sending_stream`, and `domain_id` are immutable after creation.
*/
public async update(id: number, params: UpdateWebhookParams) {
const url = `${this.webhooksURL}/${id}`;
Expand Down
9 changes: 8 additions & 1 deletion src/types/api/webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export type WebhookType = "email_sending" | "audit_log";
export type WebhookType =
| "email_sending"
| "campaigns"
| "audit_log"
| "inbound_receiving";

export type PayloadFormat = "json" | "jsonlines";

Expand All @@ -23,6 +27,7 @@ export type Webhook = {
payload_format: PayloadFormat;
sending_stream?: SendingStream | null;
domain_id?: number | null;
inbound_inbox_id?: number | null;
event_types?: WebhookEventType[];
};

Expand All @@ -42,6 +47,7 @@ export type CreateWebhookParams = {
sending_stream?: SendingStream;
event_types?: WebhookEventType[];
domain_id?: number;
inbound_inbox_id?: number;
};

export type WebhookWithSigningSecret = Webhook & {
Expand All @@ -57,6 +63,7 @@ export type UpdateWebhookParams = {
active?: boolean;
payload_format?: PayloadFormat;
event_types?: WebhookEventType[];
inbound_inbox_id?: number;
};

export type UpdateWebhookResponse = {
Expand Down
Loading