diff --git a/__tests__/services/sunshine-conversation-api-service.spec.ts b/__tests__/services/sunshine-conversation-api-service.spec.ts index e142c12..572bf07 100644 --- a/__tests__/services/sunshine-conversation-api-service.spec.ts +++ b/__tests__/services/sunshine-conversation-api-service.spec.ts @@ -11,7 +11,7 @@ import { IServiceConfig, UserChannelTypes } from "@models/sunshine-conversation"; -import { ICreateTemplate, ICreateTemplateResponse, ITemplate, TemplateStatus } from "@models/whats-app-template"; +import { ICreateTemplate, IMessageTemplate, IResponse, ITemplate, TemplateStatus } from "@models/whats-app-template"; import { SunshineConversationApiService } from "@services/sunshine-conversation-api-service"; describe("SunshineConversationApiService", () => { @@ -295,9 +295,11 @@ describe("SunshineConversationApiService", () => { category: "category" }; - const response: ICreateTemplateResponse = { - ...payload, - messageTemplate: { status: TemplateStatus.APPROVED, id: "id" } + const response: IResponse = { + responseJSON: { + ...payload, + messageTemplate: { status: TemplateStatus.APPROVED, id: "id" } + } }; client.request.mockResolvedValueOnce(response); @@ -319,7 +321,7 @@ describe("SunshineConversationApiService", () => { ); expect(client.request).toHaveBeenCalledWith(options); - expect(template).toBe(response); + expect(template).toBe(response.responseJSON); }); }); diff --git a/package.json b/package.json index 15498f0..91ff15d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@zendesk/zaf-toolbox", - "version": "0.2.8", + "version": "0.2.9", "description": "A toolbox for ZAF application built with 🩷 by Zendesk Labs", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", diff --git a/src/models/sunshine-conversation.ts b/src/models/sunshine-conversation.ts index 23cd630..1767e08 100644 --- a/src/models/sunshine-conversation.ts +++ b/src/models/sunshine-conversation.ts @@ -417,10 +417,8 @@ export interface ISendNotificationPayload { metadata?: IMetadata; } -export interface ISendNotificationResponse { - responseJSON: { - notification: { _id: string }; - }; +export interface ISendNotification { + notification: { _id: string }; } // ==== diff --git a/src/models/whats-app-template.ts b/src/models/whats-app-template.ts index e0201c1..fbbc831 100644 --- a/src/models/whats-app-template.ts +++ b/src/models/whats-app-template.ts @@ -144,7 +144,11 @@ export interface ITemplatesResponse { after?: string; } -export interface ICreateTemplateResponse extends ICreateTemplate { +export interface IResponse { + responseJSON: T; +} + +export interface IMessageTemplate extends ICreateTemplate { messageTemplate: { status: TemplateStatus; id: string }; } diff --git a/src/services/sunshine-conversation-api-service.ts b/src/services/sunshine-conversation-api-service.ts index d77f91c..b0c0d52 100644 --- a/src/services/sunshine-conversation-api-service.ts +++ b/src/services/sunshine-conversation-api-service.ts @@ -8,14 +8,15 @@ import { ITemplate, ICreateTemplate, ITemplatesResponse, - ICreateTemplateResponse, + IResponse, UserChannelTypes, ISendNotificationPayload, IIntegration, ISunshineConversationPageParameters, ISunshineConversationGetIntegrationsFilters, IMetadata, - ISendNotificationResponse + IMessageTemplate, + ISendNotification } from "@models/index"; import { buildUrlParams } from "@utils/build-url-params"; import { INTERNATIONAL_PHONE_NUMBER_REGEX } from "@utils/regex"; @@ -176,13 +177,13 @@ export class SunshineConversationApiService { public async createWhatsAppTemplate( whatsAppIntegrationId: string, createTemplateBody: ICreateTemplate - ): Promise { + ): Promise { const options = this.createV1Options( `/apps/${this.settings.appId}/integrations/${whatsAppIntegrationId}/messageTemplates`, HttpMethod.POST, createTemplateBody ); - return this.client.request(options); + return (await this.client.request>(options)).responseJSON; } /** @@ -234,7 +235,7 @@ export class SunshineConversationApiService { ...(metadata && { metadata }) }; - const { responseJSON } = await this.client.request( + const { responseJSON } = await this.client.request>( this.createV1Options(`/apps/${this.settings.appId}/notifications`, HttpMethod.POST, payload) );