@dawntech/blip-tools 0.1.9 → 0.1.11
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 +12 -2
- package/dist/index.js +62 -25
- package/package.json +1 -1
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<
|
|
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;
|
|
@@ -43,6 +48,11 @@ export default class Blip {
|
|
|
43
48
|
identity: string;
|
|
44
49
|
content: string;
|
|
45
50
|
}): Promise<void>;
|
|
51
|
+
sendMessageWithButtons({ identity, message, buttons, }: {
|
|
52
|
+
identity: string;
|
|
53
|
+
message: string;
|
|
54
|
+
buttons: string[];
|
|
55
|
+
}): Promise<void>;
|
|
46
56
|
updateContact({ identity, contactData }: {
|
|
47
57
|
identity: string;
|
|
48
58
|
contactData: Record<string, unknown>;
|
|
@@ -50,7 +60,7 @@ export default class Blip {
|
|
|
50
60
|
getContact({ identity }: {
|
|
51
61
|
identity: string;
|
|
52
62
|
}): Promise<Contact>;
|
|
53
|
-
getWhatsAppTemplates(): Promise<
|
|
63
|
+
getWhatsAppTemplates(): Promise<Template[]>;
|
|
54
64
|
setContextVariable({ value, variableName, identity, }: {
|
|
55
65
|
variableName: string;
|
|
56
66
|
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@
|
|
30
|
-
method: '
|
|
31
|
-
uri:
|
|
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 }) {
|
|
@@ -123,6 +142,24 @@ export default class Blip {
|
|
|
123
142
|
handleError(error);
|
|
124
143
|
}
|
|
125
144
|
}
|
|
145
|
+
async sendMessageWithButtons({ identity, message, buttons, }) {
|
|
146
|
+
try {
|
|
147
|
+
const response = await this.api.post('/messages', {
|
|
148
|
+
id: randomUUID(),
|
|
149
|
+
to: identity,
|
|
150
|
+
type: 'application/vnd.lime.select+json',
|
|
151
|
+
content: {
|
|
152
|
+
scope: buttons.length <= 3 ? 'immediate' : null,
|
|
153
|
+
text: message,
|
|
154
|
+
options: buttons.map((button, index) => ({ order: index + 1, text: button })),
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
validateResponse(response);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
handleError(error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
126
163
|
async updateContact({ identity, contactData }) {
|
|
127
164
|
try {
|
|
128
165
|
const response = await this.api.post('/commands', {
|