@dawntech/blip-tools 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,2 @@
1
1
  import BlipError from './blip-error';
2
- declare const _default: {
3
- BlipError: typeof BlipError;
4
- };
5
- export default _default;
2
+ export { BlipError };
package/dist/index.cjs CHANGED
@@ -40,7 +40,6 @@ function handleError(error) {
40
40
  if (error.response?.data.code) {
41
41
  throw new BlipError(error.response?.data.description, error.response?.data.code);
42
42
  }
43
- throw new BlipError(error.message, 0);
44
43
  }
45
44
  throw error;
46
45
  }
@@ -204,6 +203,14 @@ class BlipAttendance {
204
203
  }
205
204
  }
206
205
 
206
+ function createUri(url, params) {
207
+ const encodedParams = encodeBlipParams(params);
208
+ if (encodedParams) {
209
+ return `${url}?${encodedParams}`;
210
+ }
211
+ return url;
212
+ }
213
+
207
214
  class BlipContact {
208
215
  api;
209
216
  constructor(context) {
@@ -243,6 +250,26 @@ class BlipContact {
243
250
  throw handleError(error);
244
251
  }
245
252
  }
253
+ async search({ filter, skip, take } = {}) {
254
+ const params = {
255
+ $filter: filter,
256
+ $skip: skip,
257
+ $take: take,
258
+ };
259
+ try {
260
+ const response = await this.api.post('/commands', {
261
+ id: crypto.randomUUID(),
262
+ to: 'postmaster@crm.msging.net',
263
+ method: 'get',
264
+ uri: createUri('/contacts', params),
265
+ });
266
+ validateResponse(response);
267
+ return response.data.resource.items;
268
+ }
269
+ catch (error) {
270
+ throw handleError(error);
271
+ }
272
+ }
246
273
  }
247
274
 
248
275
  class BlipContext {
@@ -313,7 +340,7 @@ class BlipDispatch {
313
340
  /**
314
341
  * Sends a template-based message to any user. For sending messages to clients who are active, use `sendTemplateMessage` instead.
315
342
  */
316
- async sendIndividualActiveCampaign({ campaignName, masterState, flowId, stateId, channelType, phone, templateName, params = [], }) {
343
+ async sendIndividualActiveCampaign({ campaignName, masterState, flowId, stateId, channelType, phone, templateName, params = [], scheduled, }) {
317
344
  const body = {
318
345
  id: crypto.randomUUID(),
319
346
  to: 'postmaster@activecampaign.msging.net',
@@ -328,9 +355,10 @@ class BlipDispatch {
328
355
  flowId,
329
356
  stateId,
330
357
  channelType,
358
+ scheduled: scheduled?.toISOString(),
331
359
  },
332
360
  audience: {
333
- recipient: `+${phone}`,
361
+ recipient: `+${phone.replace('+', '')}`,
334
362
  },
335
363
  message: {
336
364
  messageTemplate: templateName,
@@ -493,14 +521,6 @@ class BlipInteraction {
493
521
  }
494
522
  }
495
523
 
496
- function createUri(url, params) {
497
- const encodedParams = encodeBlipParams(params);
498
- if (encodedParams) {
499
- return `${url}?${encodedParams}`;
500
- }
501
- return url;
502
- }
503
-
504
524
  class BlipTicket {
505
525
  api;
506
526
  constructor(context) {
@@ -582,10 +602,70 @@ class BlipWhatsapp {
582
602
  }
583
603
  }
584
604
 
585
- var index = /*#__PURE__*/Object.freeze({
605
+ class BlipCampaign {
606
+ api;
607
+ constructor(context) {
608
+ this.api = context.api;
609
+ }
610
+ async search({ filter, skip, take } = {}) {
611
+ try {
612
+ const params = {
613
+ $filter: filter,
614
+ $skip: skip,
615
+ $take: take,
616
+ };
617
+ const body = {
618
+ id: crypto.randomUUID(),
619
+ to: 'postmaster@activecampaign.msging.net',
620
+ method: 'get',
621
+ uri: createUri('/campaigns', params),
622
+ };
623
+ const response = await this.api.post('/commands', body);
624
+ validateResponse(response);
625
+ return response.data.resource.items;
626
+ }
627
+ catch (error) {
628
+ throw handleError(error);
629
+ }
630
+ }
631
+ async get(campaignId) {
632
+ try {
633
+ const body = {
634
+ id: crypto.randomUUID(),
635
+ to: 'postmaster@activecampaign.msging.net',
636
+ method: 'get',
637
+ uri: `/campaigns/${campaignId}`,
638
+ };
639
+ const response = await this.api.post('/commands', body);
640
+ validateResponse(response);
641
+ return response.data.resource;
642
+ }
643
+ catch (error) {
644
+ throw handleError(error);
645
+ }
646
+ }
647
+ async deleteCampaign(campaignId) {
648
+ try {
649
+ const body = {
650
+ id: crypto.randomUUID(),
651
+ to: 'postmaster@activecampaign.msging.net',
652
+ method: 'delete',
653
+ uri: `/campaigns/${campaignId}`,
654
+ };
655
+ const response = await this.api.post('/commands', body);
656
+ validateResponse(response);
657
+ }
658
+ catch (error) {
659
+ throw handleError(error);
660
+ }
661
+ }
662
+ }
663
+
664
+ var index$1 = /*#__PURE__*/Object.freeze({
586
665
  __proto__: null,
587
666
  BlipAttendance: BlipAttendance,
588
667
  BlipBucket: BlipBucket,
668
+ BlipCampaign: BlipCampaign,
589
669
  BlipContact: BlipContact,
590
670
  BlipContext: BlipContext,
591
671
  BlipDispatch: BlipDispatch,
@@ -739,6 +819,7 @@ class Blip {
739
819
  whatsapp;
740
820
  monitoring;
741
821
  analytics;
822
+ campaign;
742
823
  constructor(params) {
743
824
  validateInstance(params);
744
825
  this.api = axios.create({
@@ -760,8 +841,15 @@ class Blip {
760
841
  this.whatsapp = new BlipWhatsapp({ api: this.api });
761
842
  this.monitoring = new BlipMonitoring({ api: this.api });
762
843
  this.analytics = new BlipAnalytics({ api: this.api });
844
+ this.campaign = new BlipCampaign({ api: this.api });
763
845
  }
764
846
  }
765
847
 
848
+ var index = /*#__PURE__*/Object.freeze({
849
+ __proto__: null,
850
+ BlipError: BlipError
851
+ });
852
+
766
853
  exports.Blip = Blip;
767
- exports.Modules = index;
854
+ exports.Exceptions = index;
855
+ exports.Modules = index$1;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as Modules from './modules/index';
2
2
  import type * as Types from './types/index';
3
3
  import { Blip } from './modules/blip-main';
4
- export { Types, Blip, Modules };
4
+ import * as Exceptions from './exceptions';
5
+ export { Types, Blip, Modules, Exceptions };
package/dist/index.mjs CHANGED
@@ -38,7 +38,6 @@ function handleError(error) {
38
38
  if (error.response?.data.code) {
39
39
  throw new BlipError(error.response?.data.description, error.response?.data.code);
40
40
  }
41
- throw new BlipError(error.message, 0);
42
41
  }
43
42
  throw error;
44
43
  }
@@ -202,6 +201,14 @@ class BlipAttendance {
202
201
  }
203
202
  }
204
203
 
204
+ function createUri(url, params) {
205
+ const encodedParams = encodeBlipParams(params);
206
+ if (encodedParams) {
207
+ return `${url}?${encodedParams}`;
208
+ }
209
+ return url;
210
+ }
211
+
205
212
  class BlipContact {
206
213
  api;
207
214
  constructor(context) {
@@ -241,6 +248,26 @@ class BlipContact {
241
248
  throw handleError(error);
242
249
  }
243
250
  }
251
+ async search({ filter, skip, take } = {}) {
252
+ const params = {
253
+ $filter: filter,
254
+ $skip: skip,
255
+ $take: take,
256
+ };
257
+ try {
258
+ const response = await this.api.post('/commands', {
259
+ id: randomUUID(),
260
+ to: 'postmaster@crm.msging.net',
261
+ method: 'get',
262
+ uri: createUri('/contacts', params),
263
+ });
264
+ validateResponse(response);
265
+ return response.data.resource.items;
266
+ }
267
+ catch (error) {
268
+ throw handleError(error);
269
+ }
270
+ }
244
271
  }
245
272
 
246
273
  class BlipContext {
@@ -311,7 +338,7 @@ class BlipDispatch {
311
338
  /**
312
339
  * Sends a template-based message to any user. For sending messages to clients who are active, use `sendTemplateMessage` instead.
313
340
  */
314
- async sendIndividualActiveCampaign({ campaignName, masterState, flowId, stateId, channelType, phone, templateName, params = [], }) {
341
+ async sendIndividualActiveCampaign({ campaignName, masterState, flowId, stateId, channelType, phone, templateName, params = [], scheduled, }) {
315
342
  const body = {
316
343
  id: randomUUID(),
317
344
  to: 'postmaster@activecampaign.msging.net',
@@ -326,9 +353,10 @@ class BlipDispatch {
326
353
  flowId,
327
354
  stateId,
328
355
  channelType,
356
+ scheduled: scheduled?.toISOString(),
329
357
  },
330
358
  audience: {
331
- recipient: `+${phone}`,
359
+ recipient: `+${phone.replace('+', '')}`,
332
360
  },
333
361
  message: {
334
362
  messageTemplate: templateName,
@@ -491,14 +519,6 @@ class BlipInteraction {
491
519
  }
492
520
  }
493
521
 
494
- function createUri(url, params) {
495
- const encodedParams = encodeBlipParams(params);
496
- if (encodedParams) {
497
- return `${url}?${encodedParams}`;
498
- }
499
- return url;
500
- }
501
-
502
522
  class BlipTicket {
503
523
  api;
504
524
  constructor(context) {
@@ -580,10 +600,70 @@ class BlipWhatsapp {
580
600
  }
581
601
  }
582
602
 
583
- var index = /*#__PURE__*/Object.freeze({
603
+ class BlipCampaign {
604
+ api;
605
+ constructor(context) {
606
+ this.api = context.api;
607
+ }
608
+ async search({ filter, skip, take } = {}) {
609
+ try {
610
+ const params = {
611
+ $filter: filter,
612
+ $skip: skip,
613
+ $take: take,
614
+ };
615
+ const body = {
616
+ id: randomUUID(),
617
+ to: 'postmaster@activecampaign.msging.net',
618
+ method: 'get',
619
+ uri: createUri('/campaigns', params),
620
+ };
621
+ const response = await this.api.post('/commands', body);
622
+ validateResponse(response);
623
+ return response.data.resource.items;
624
+ }
625
+ catch (error) {
626
+ throw handleError(error);
627
+ }
628
+ }
629
+ async get(campaignId) {
630
+ try {
631
+ const body = {
632
+ id: randomUUID(),
633
+ to: 'postmaster@activecampaign.msging.net',
634
+ method: 'get',
635
+ uri: `/campaigns/${campaignId}`,
636
+ };
637
+ const response = await this.api.post('/commands', body);
638
+ validateResponse(response);
639
+ return response.data.resource;
640
+ }
641
+ catch (error) {
642
+ throw handleError(error);
643
+ }
644
+ }
645
+ async deleteCampaign(campaignId) {
646
+ try {
647
+ const body = {
648
+ id: randomUUID(),
649
+ to: 'postmaster@activecampaign.msging.net',
650
+ method: 'delete',
651
+ uri: `/campaigns/${campaignId}`,
652
+ };
653
+ const response = await this.api.post('/commands', body);
654
+ validateResponse(response);
655
+ }
656
+ catch (error) {
657
+ throw handleError(error);
658
+ }
659
+ }
660
+ }
661
+
662
+ var index$1 = /*#__PURE__*/Object.freeze({
584
663
  __proto__: null,
585
664
  BlipAttendance: BlipAttendance,
586
665
  BlipBucket: BlipBucket,
666
+ BlipCampaign: BlipCampaign,
587
667
  BlipContact: BlipContact,
588
668
  BlipContext: BlipContext,
589
669
  BlipDispatch: BlipDispatch,
@@ -737,6 +817,7 @@ class Blip {
737
817
  whatsapp;
738
818
  monitoring;
739
819
  analytics;
820
+ campaign;
740
821
  constructor(params) {
741
822
  validateInstance(params);
742
823
  this.api = axios.create({
@@ -758,7 +839,13 @@ class Blip {
758
839
  this.whatsapp = new BlipWhatsapp({ api: this.api });
759
840
  this.monitoring = new BlipMonitoring({ api: this.api });
760
841
  this.analytics = new BlipAnalytics({ api: this.api });
842
+ this.campaign = new BlipCampaign({ api: this.api });
761
843
  }
762
844
  }
763
845
 
764
- export { Blip, index as Modules };
846
+ var index = /*#__PURE__*/Object.freeze({
847
+ __proto__: null,
848
+ BlipError: BlipError
849
+ });
850
+
851
+ export { Blip, index as Exceptions, index$1 as Modules };
@@ -0,0 +1,15 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { Campaign } from '../types';
3
+ export default class BlipCampaign {
4
+ private api;
5
+ constructor(context: {
6
+ api: AxiosInstance;
7
+ });
8
+ search({ filter, skip, take }?: {
9
+ filter?: string;
10
+ skip?: number;
11
+ take?: number;
12
+ }): Promise<Campaign[]>;
13
+ get(campaignId: string): Promise<Campaign>;
14
+ deleteCampaign(campaignId: string): Promise<void>;
15
+ }
@@ -12,4 +12,9 @@ export default class BlipContact {
12
12
  get({ identity }: {
13
13
  identity: string;
14
14
  }): Promise<Contact>;
15
+ search({ filter, skip, take }?: {
16
+ filter?: string;
17
+ skip?: number;
18
+ take?: number;
19
+ }): Promise<Contact[]>;
15
20
  }
@@ -10,15 +10,16 @@ export default class BlipDispatch {
10
10
  /**
11
11
  * Sends a template-based message to any user. For sending messages to clients who are active, use `sendTemplateMessage` instead.
12
12
  */
13
- sendIndividualActiveCampaign({ campaignName, masterState, flowId, stateId, channelType, phone, templateName, params, }: {
13
+ sendIndividualActiveCampaign({ campaignName, masterState, flowId, stateId, channelType, phone, templateName, params, scheduled, }: {
14
14
  campaignName: string;
15
15
  masterState: string;
16
16
  flowId: string;
17
17
  stateId: string;
18
- channelType: string;
18
+ channelType: 'whatsapp' | string;
19
19
  phone: string;
20
20
  templateName: string;
21
- params: string[];
21
+ params?: string[];
22
+ scheduled?: Date;
22
23
  }): Promise<CampaignNotification>;
23
24
  getCampaignNotificationStatus({ campaignNotificationId }: {
24
25
  campaignNotificationId: string;
@@ -11,6 +11,7 @@ import BlipWhatsapp from './blip-whatsapp';
11
11
  import BlipContact from './blip-contact';
12
12
  import BlipMonitoring from './blip-monitoring';
13
13
  import BlipAnalytics from './blip-analytics';
14
+ import BlipCampaign from './blip-campaign';
14
15
  export declare class Blip {
15
16
  private api;
16
17
  bucket: BlipBucket;
@@ -25,5 +26,6 @@ export declare class Blip {
25
26
  whatsapp: BlipWhatsapp;
26
27
  monitoring: BlipMonitoring;
27
28
  analytics: BlipAnalytics;
29
+ campaign: BlipCampaign;
28
30
  constructor(params: BlipConstructor);
29
31
  }
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { TicketSearchResult } from '../types/ticket-search-result';
2
+ import { Ticket } from '../types';
3
3
  export default class BlipTicket {
4
4
  private api;
5
5
  constructor(context: {
@@ -9,6 +9,6 @@ export default class BlipTicket {
9
9
  filter?: string;
10
10
  skip?: number;
11
11
  take?: number;
12
- }): Promise<import("../types/ticket-search-result").Ticket[]>;
13
- getTicket(ticketId: string): Promise<TicketSearchResult>;
12
+ }): Promise<Ticket[]>;
13
+ getTicket(ticketId: string): Promise<Ticket>;
14
14
  }
@@ -8,4 +8,5 @@ import BlipEvent from './blip-event';
8
8
  import BlipInteraction from './blip-interaction';
9
9
  import BlipTicket from './blip-ticket';
10
10
  import BlipWhatsapp from './blip-whatsapp';
11
- export { BlipMedia, BlipBucket, BlipAttendance, BlipContact, BlipContext, BlipDispatch, BlipEvent, BlipInteraction, BlipTicket, BlipWhatsapp, };
11
+ import BlipCampaign from './blip-campaign';
12
+ export { BlipMedia, BlipBucket, BlipAttendance, BlipContact, BlipContext, BlipDispatch, BlipEvent, BlipInteraction, BlipTicket, BlipWhatsapp, BlipCampaign, };
@@ -0,0 +1,14 @@
1
+ export interface Campaign {
2
+ id: string;
3
+ name: string;
4
+ campaignType: string;
5
+ masterState: string;
6
+ flowId: string;
7
+ stateId: string;
8
+ status: string;
9
+ created: string;
10
+ scheduled: string;
11
+ isToUseLiteApi: boolean;
12
+ channelType: string;
13
+ canSendWithOpenTicket: boolean;
14
+ }
@@ -12,6 +12,7 @@ export interface CampaignRequestBody {
12
12
  flowId: string;
13
13
  stateId: string;
14
14
  channelType: string;
15
+ scheduled?: string;
15
16
  };
16
17
  audience: {
17
18
  recipient: string;
@@ -5,4 +5,6 @@ export interface Contact {
5
5
  phoneNumber: string;
6
6
  extras: Record<string, string>;
7
7
  source: string;
8
+ group?: string;
9
+ email?: string;
8
10
  }
@@ -2,8 +2,9 @@ import { AttendanceHourContainer } from './attendance-hour-container';
2
2
  import { BlipConstructor } from './blip-constructor';
3
3
  import { BlipRequestBody, BlipResponse, BlipArrayBody } from './blip';
4
4
  import { Parameter, Component, Template } from './template';
5
- import { TicketSearchResult } from './ticket-search-result';
6
5
  import { Ticket } from './ticket';
7
6
  import { MonitoredTickets, MonitoredTicketMetrics, MonitoredAttendantStatusMetrics } from './monitoring';
8
7
  import { TicketAnalyticsReport, TicketAnalyticsTimings } from './analytics';
9
- export { AttendanceHourContainer, BlipConstructor, BlipRequestBody, BlipResponse, BlipArrayBody, Parameter, Component, Template, TicketAnalyticsReport, MonitoredTickets, MonitoredTicketMetrics, MonitoredAttendantStatusMetrics, TicketSearchResult, TicketAnalyticsTimings, Ticket, };
8
+ import { Campaign } from './campaign';
9
+ import { Contact } from './contact';
10
+ export { AttendanceHourContainer, BlipConstructor, BlipRequestBody, BlipResponse, BlipArrayBody, Parameter, Component, Template, TicketAnalyticsReport, MonitoredTickets, MonitoredTicketMetrics, MonitoredAttendantStatusMetrics, TicketAnalyticsTimings, Ticket, Campaign, Contact, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dawntech/blip-tools",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Node package for Blip API",
5
5
  "exports": {
6
6
  ".": {
@@ -1,21 +0,0 @@
1
- export interface TicketSearchResult {
2
- total: number;
3
- itemType: string;
4
- items: Ticket[];
5
- }
6
- export interface Ticket {
7
- closed: boolean;
8
- customerDomain: string;
9
- customerIdentity: string;
10
- externalId: string;
11
- id: string;
12
- ownerIdentity: string;
13
- priority: number;
14
- provider: string;
15
- rating: number;
16
- sequentialId: number;
17
- status: string;
18
- storageDate: string;
19
- team: string;
20
- unreadMessages: number;
21
- }