@dawntech/blip-tools 0.1.9 → 0.1.10

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.
package/dist/index.d.ts CHANGED
@@ -5,6 +5,8 @@ import { BlipConstructor } from './types/blip-constructor.js';
5
5
  import BlipError from './exceptions/blip-error.js';
6
6
  import { AttendanceHourContainer } from './types/attendance-hour-container.js';
7
7
  import { Ticket } from './types/ticket.js';
8
+ import { CampaignNotification } from './types/campaign-notification.js';
9
+ import { CampaignNotificationStatus } from './types/campaign-notification-status.js';
8
10
  export { BlipError, type Ticket, type AttendanceHourContainer, type Contact, type Template };
9
11
  export default class Blip {
10
12
  api: AxiosInstance;
@@ -21,7 +23,10 @@ export default class Blip {
21
23
  phone: string;
22
24
  templateName: string;
23
25
  params: string[];
24
- }): Promise<void>;
26
+ }): Promise<CampaignNotification>;
27
+ getCampaignNotificationStatus({ campaignNotificationId }: {
28
+ campaignNotificationId: string;
29
+ }): Promise<CampaignNotificationStatus[]>;
25
30
  getContextVariable({ identity, variableName }: {
26
31
  identity: string;
27
32
  variableName: string;
@@ -50,7 +55,7 @@ export default class Blip {
50
55
  getContact({ identity }: {
51
56
  identity: string;
52
57
  }): Promise<Contact>;
53
- getWhatsAppTemplates(): Promise<Contact>;
58
+ getWhatsAppTemplates(): Promise<Template[]>;
54
59
  setContextVariable({ value, variableName, identity, }: {
55
60
  variableName: string;
56
61
  value: unknown;
package/dist/index.js CHANGED
@@ -22,38 +22,57 @@ export default class Blip {
22
22
  /**
23
23
  * Sends a template-based message to any user. For sending messages to clients who are active, use `sendTemplateMessage` instead.
24
24
  */
25
- async sendIndividualActiveCampaign({ campaignName, masterState, flowId, stateId, channelType, phone, templateName, params, }) {
25
+ async sendIndividualActiveCampaign({ campaignName, masterState, flowId, stateId, channelType, phone, templateName, params = [], }) {
26
+ const body = {
27
+ id: randomUUID(),
28
+ to: 'postmaster@activecampaign.msging.net',
29
+ method: 'set',
30
+ uri: '/campaign/full',
31
+ type: 'application/vnd.iris.activecampaign.full-campaign+json',
32
+ resource: {
33
+ campaign: {
34
+ name: campaignName,
35
+ campaignType: 'Individual',
36
+ masterState,
37
+ flowId,
38
+ stateId,
39
+ channelType,
40
+ },
41
+ audience: {
42
+ recipient: `+${phone}`,
43
+ },
44
+ message: {
45
+ messageTemplate: templateName,
46
+ channelType,
47
+ },
48
+ },
49
+ };
50
+ if (params.length > 0) {
51
+ body.resource.audience.messageParams = formatTemplateParams(params);
52
+ body.resource.message.messageParams = params.map((_param, index) => String(index + 1));
53
+ }
54
+ try {
55
+ const response = await this.api.post('/commands', body);
56
+ validateResponse(response);
57
+ return response.data.resource;
58
+ }
59
+ catch (error) {
60
+ throw handleError(error);
61
+ }
62
+ }
63
+ async getCampaignNotificationStatus({ campaignNotificationId }) {
26
64
  try {
27
65
  const response = await this.api.post('/commands', {
28
66
  id: randomUUID(),
29
- to: 'postmaster@activecampaign.msging.net',
30
- method: 'set',
31
- uri: '/campaign/full',
32
- type: 'application/vnd.iris.activecampaign.full-campaign+json',
33
- resource: {
34
- campaign: {
35
- name: campaignName,
36
- campaignType: 'Individual',
37
- masterState,
38
- flowId,
39
- stateId,
40
- channelType,
41
- },
42
- audience: {
43
- recipient: `+${phone}`,
44
- messageParams: formatTemplateParams(params),
45
- },
46
- message: {
47
- messageTemplate: templateName,
48
- messageParams: params.map((_param, index) => String(index + 1)),
49
- channelType,
50
- },
51
- },
67
+ to: 'postmaster@msging.net',
68
+ method: 'get',
69
+ uri: `/notifications?id=${campaignNotificationId}`,
52
70
  });
53
71
  validateResponse(response);
72
+ return response.data.resource.items;
54
73
  }
55
74
  catch (error) {
56
- handleError(error);
75
+ throw handleError(error);
57
76
  }
58
77
  }
59
78
  async getContextVariable({ identity, variableName }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dawntech/blip-tools",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Node package for Blip API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",