import type { ApiClient } from '../../core' import { BaseCrudApi } from '../../core' import type { AutoPauseModePayload, Campaign, CampaignStats, CreateCampaignPayload, ExportCampaignResultPayload, ExportTemplateCsvPayload, HsmLimit, SetIntervalPayload, UpdateCampaignPayload, } from './types' export class CampaignsApi extends BaseCrudApi< Campaign, CreateCampaignPayload, UpdateCampaignPayload > { constructor(client: ApiClient) { super(client, '/campaigns') this.sendById = this.sendById.bind(this) this.pauseById = this.pauseById.bind(this) this.resumeById = this.resumeById.bind(this) this.duplicateById = this.duplicateById.bind(this) this.getStatsById = this.getStatsById.bind(this) this.setIntervalById = this.setIntervalById.bind(this) this.getContactCount = this.getContactCount.bind(this) this.setAutoPauseMode = this.setAutoPauseMode.bind(this) this.exportCampaignResult = this.exportCampaignResult.bind(this) this.exportTemplateCsv = this.exportTemplateCsv.bind(this) this.getHsmLimit = this.getHsmLimit.bind(this) } /** Starts sending messages for the given campaign. */ sendById(id: string): Promise { return this.client.post(`${this.basePath}/${id}/send`) } /** Pauses a campaign that is currently sending. */ pauseById(id: string): Promise { return this.client.post(`${this.basePath}/${id}/pause`) } /** Resumes a previously paused campaign. */ resumeById(id: string): Promise { return this.client.post(`${this.basePath}/${id}/resume`) } /** Creates a copy of an existing campaign. */ duplicateById(id: string): Promise { return this.client.post(`${this.basePath}/${id}/duplicate`) } /** Returns send/delivery/view statistics for a campaign. */ getStatsById(id: string): Promise { return this.client.get(`${this.basePath}/${id}/stats`) } /** Updates the min/max send interval for a campaign. */ setIntervalById(id: string, data: SetIntervalPayload): Promise { return this.client.post(`${this.basePath}/${id}/interval`, data) } /** Returns the total number of contacts targeted by a campaign. */ getContactCount(id: string): Promise { return this.client.get(`${this.basePath}/${id}/contactCount`) } /** Configures the auto-pause behavior for campaigns. */ setAutoPauseMode(data: AutoPauseModePayload): Promise { return this.client.put(`${this.basePath}/autoPauseMode`, data) } /** Exports campaign send results as a CSV file. */ exportCampaignResult(data: ExportCampaignResultPayload): Promise { return this.client.post(`${this.basePath}/export/csv`, data) } /** Exports a CSV template for importing contacts into an HSM campaign. */ exportTemplateCsv(data: ExportTemplateCsvPayload): Promise { return this.client.post(`${this.basePath}/exportTemplate`, data) } /** Returns the HSM message usage and limit for an account. */ getHsmLimit(accountId: string): Promise { return this.client.get(`/whatsapp-business-templates/${accountId}/hsmLimit`) } }