Skip to content

Commit d8dd02e

Browse files
authored
Merge pull request #90 from zendesk/update-response-type
chore(whats-app-template): update response type
2 parents ad4428e + 6ee4b27 commit d8dd02e

5 files changed

Lines changed: 21 additions & 16 deletions

File tree

__tests__/services/sunshine-conversation-api-service.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
IServiceConfig,
1212
UserChannelTypes
1313
} from "@models/sunshine-conversation";
14-
import { ICreateTemplate, ICreateTemplateResponse, ITemplate, TemplateStatus } from "@models/whats-app-template";
14+
import { ICreateTemplate, IMessageTemplate, IResponse, ITemplate, TemplateStatus } from "@models/whats-app-template";
1515
import { SunshineConversationApiService } from "@services/sunshine-conversation-api-service";
1616

1717
describe("SunshineConversationApiService", () => {
@@ -295,9 +295,11 @@ describe("SunshineConversationApiService", () => {
295295
category: "category"
296296
};
297297

298-
const response: ICreateTemplateResponse = {
299-
...payload,
300-
messageTemplate: { status: TemplateStatus.APPROVED, id: "id" }
298+
const response: IResponse<IMessageTemplate> = {
299+
responseJSON: {
300+
...payload,
301+
messageTemplate: { status: TemplateStatus.APPROVED, id: "id" }
302+
}
301303
};
302304
client.request.mockResolvedValueOnce(response);
303305

@@ -319,7 +321,7 @@ describe("SunshineConversationApiService", () => {
319321
);
320322

321323
expect(client.request).toHaveBeenCalledWith(options);
322-
expect(template).toBe(response);
324+
expect(template).toBe(response.responseJSON);
323325
});
324326
});
325327

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zendesk/zaf-toolbox",
3-
"version": "0.2.8",
3+
"version": "0.2.9",
44
"description": "A toolbox for ZAF application built with 🩷 by Zendesk Labs",
55
"main": "lib/src/index.js",
66
"types": "lib/src/index.d.ts",

src/models/sunshine-conversation.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,8 @@ export interface ISendNotificationPayload {
417417
metadata?: IMetadata;
418418
}
419419

420-
export interface ISendNotificationResponse {
421-
responseJSON: {
422-
notification: { _id: string };
423-
};
420+
export interface ISendNotification {
421+
notification: { _id: string };
424422
}
425423

426424
// ====

src/models/whats-app-template.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ export interface ITemplatesResponse {
144144
after?: string;
145145
}
146146

147-
export interface ICreateTemplateResponse extends ICreateTemplate {
147+
export interface IResponse<T> {
148+
responseJSON: T;
149+
}
150+
151+
export interface IMessageTemplate extends ICreateTemplate {
148152
messageTemplate: { status: TemplateStatus; id: string };
149153
}
150154

src/services/sunshine-conversation-api-service.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import {
88
ITemplate,
99
ICreateTemplate,
1010
ITemplatesResponse,
11-
ICreateTemplateResponse,
11+
IResponse,
1212
UserChannelTypes,
1313
ISendNotificationPayload,
1414
IIntegration,
1515
ISunshineConversationPageParameters,
1616
ISunshineConversationGetIntegrationsFilters,
1717
IMetadata,
18-
ISendNotificationResponse
18+
IMessageTemplate,
19+
ISendNotification
1920
} from "@models/index";
2021
import { buildUrlParams } from "@utils/build-url-params";
2122
import { INTERNATIONAL_PHONE_NUMBER_REGEX } from "@utils/regex";
@@ -176,13 +177,13 @@ export class SunshineConversationApiService {
176177
public async createWhatsAppTemplate(
177178
whatsAppIntegrationId: string,
178179
createTemplateBody: ICreateTemplate
179-
): Promise<ICreateTemplateResponse> {
180+
): Promise<IMessageTemplate> {
180181
const options = this.createV1Options(
181182
`/apps/${this.settings.appId}/integrations/${whatsAppIntegrationId}/messageTemplates`,
182183
HttpMethod.POST,
183184
createTemplateBody
184185
);
185-
return this.client.request(options);
186+
return (await this.client.request<unknown, IResponse<IMessageTemplate>>(options)).responseJSON;
186187
}
187188

188189
/**
@@ -234,7 +235,7 @@ export class SunshineConversationApiService {
234235
...(metadata && { metadata })
235236
};
236237

237-
const { responseJSON } = await this.client.request<unknown, ISendNotificationResponse>(
238+
const { responseJSON } = await this.client.request<unknown, IResponse<ISendNotification>>(
238239
this.createV1Options(`/apps/${this.settings.appId}/notifications`, HttpMethod.POST, payload)
239240
);
240241

0 commit comments

Comments
 (0)