@dawntech/blip-tools 0.1.8 → 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/helpers/encode-blip-params.d.ts +1 -0
- package/dist/helpers/encode-blip-params.js +13 -0
- package/dist/index.d.ts +18 -3
- package/dist/index.js +83 -26
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function encodeBlipParams(params: Record<string, unknown>): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function normalizeValue(value) {
|
|
2
|
+
return String(value).replaceAll(' ', '%20');
|
|
3
|
+
}
|
|
4
|
+
export default function encodeBlipParams(params) {
|
|
5
|
+
//This function does not uses any of the standard methods of URI parsing because Blip does not follow any of them
|
|
6
|
+
const parsedParams = [];
|
|
7
|
+
for (const [key, value] of Object.entries(params)) {
|
|
8
|
+
if (value && key) {
|
|
9
|
+
parsedParams.push(`${normalizeValue(key)}=${normalizeValue(value)}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return parsedParams.join('&');
|
|
13
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,11 @@ import { Template } from './types/template.js';
|
|
|
3
3
|
import { Contact } from './types/contact.js';
|
|
4
4
|
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
|
+
import { Ticket } from './types/ticket.js';
|
|
8
|
+
import { CampaignNotification } from './types/campaign-notification.js';
|
|
9
|
+
import { CampaignNotificationStatus } from './types/campaign-notification-status.js';
|
|
10
|
+
export { BlipError, type Ticket, type AttendanceHourContainer, type Contact, type Template };
|
|
7
11
|
export default class Blip {
|
|
8
12
|
api: AxiosInstance;
|
|
9
13
|
constructor(params: BlipConstructor);
|
|
@@ -19,7 +23,10 @@ export default class Blip {
|
|
|
19
23
|
phone: string;
|
|
20
24
|
templateName: string;
|
|
21
25
|
params: string[];
|
|
22
|
-
}): Promise<
|
|
26
|
+
}): Promise<CampaignNotification>;
|
|
27
|
+
getCampaignNotificationStatus({ campaignNotificationId }: {
|
|
28
|
+
campaignNotificationId: string;
|
|
29
|
+
}): Promise<CampaignNotificationStatus[]>;
|
|
23
30
|
getContextVariable({ identity, variableName }: {
|
|
24
31
|
identity: string;
|
|
25
32
|
variableName: string;
|
|
@@ -48,7 +55,7 @@ export default class Blip {
|
|
|
48
55
|
getContact({ identity }: {
|
|
49
56
|
identity: string;
|
|
50
57
|
}): Promise<Contact>;
|
|
51
|
-
getWhatsAppTemplates(): Promise<
|
|
58
|
+
getWhatsAppTemplates(): Promise<Template[]>;
|
|
52
59
|
setContextVariable({ value, variableName, identity, }: {
|
|
53
60
|
variableName: string;
|
|
54
61
|
value: unknown;
|
|
@@ -60,4 +67,12 @@ export default class Blip {
|
|
|
60
67
|
action: string;
|
|
61
68
|
identity?: string;
|
|
62
69
|
}): Promise<void>;
|
|
70
|
+
getAttendanceHourContainer({ attendanceContainerId }: {
|
|
71
|
+
attendanceContainerId: string;
|
|
72
|
+
}): Promise<AttendanceHourContainer>;
|
|
73
|
+
searchTickets({ filter, skip, take }: {
|
|
74
|
+
filter?: string;
|
|
75
|
+
skip?: number;
|
|
76
|
+
take?: number;
|
|
77
|
+
}): Promise<Ticket[]>;
|
|
63
78
|
}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import handleError from './helpers/handle-error.js';
|
|
|
5
5
|
import formatTemplateParams from './helpers/format-template-params.js';
|
|
6
6
|
import validateInstance from './helpers/validate-instance.js';
|
|
7
7
|
import BlipError from './exceptions/blip-error.js';
|
|
8
|
+
import encodeBlipParams from './helpers/encode-blip-params.js';
|
|
8
9
|
export { BlipError };
|
|
9
10
|
export default class Blip {
|
|
10
11
|
api;
|
|
@@ -13,7 +14,7 @@ export default class Blip {
|
|
|
13
14
|
this.api = axios.create({
|
|
14
15
|
baseURL: `https://${params.contract}.http.msging.net`,
|
|
15
16
|
headers: {
|
|
16
|
-
Authorization: `Key ${params.authToken}`,
|
|
17
|
+
Authorization: `Key ${params.authToken.replace('Key ', '')}`,
|
|
17
18
|
},
|
|
18
19
|
timeout: 30000,
|
|
19
20
|
});
|
|
@@ -21,38 +22,57 @@ export default class Blip {
|
|
|
21
22
|
/**
|
|
22
23
|
* Sends a template-based message to any user. For sending messages to clients who are active, use `sendTemplateMessage` instead.
|
|
23
24
|
*/
|
|
24
|
-
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 }) {
|
|
25
64
|
try {
|
|
26
65
|
const response = await this.api.post('/commands', {
|
|
27
66
|
id: randomUUID(),
|
|
28
|
-
to: 'postmaster@
|
|
29
|
-
method: '
|
|
30
|
-
uri:
|
|
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
|
-
messageParams: formatTemplateParams(params),
|
|
44
|
-
},
|
|
45
|
-
message: {
|
|
46
|
-
messageTemplate: templateName,
|
|
47
|
-
messageParams: params.map((_param, index) => String(index + 1)),
|
|
48
|
-
channelType,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
67
|
+
to: 'postmaster@msging.net',
|
|
68
|
+
method: 'get',
|
|
69
|
+
uri: `/notifications?id=${campaignNotificationId}`,
|
|
51
70
|
});
|
|
52
71
|
validateResponse(response);
|
|
72
|
+
return response.data.resource.items;
|
|
53
73
|
}
|
|
54
74
|
catch (error) {
|
|
55
|
-
handleError(error);
|
|
75
|
+
throw handleError(error);
|
|
56
76
|
}
|
|
57
77
|
}
|
|
58
78
|
async getContextVariable({ identity, variableName }) {
|
|
@@ -225,4 +245,41 @@ export default class Blip {
|
|
|
225
245
|
throw handleError(error);
|
|
226
246
|
}
|
|
227
247
|
}
|
|
248
|
+
async getAttendanceHourContainer({ attendanceContainerId }) {
|
|
249
|
+
try {
|
|
250
|
+
const body = {
|
|
251
|
+
id: randomUUID(),
|
|
252
|
+
to: 'postmaster@desk.msging.net',
|
|
253
|
+
method: 'get',
|
|
254
|
+
uri: `/attendance-hour-container/${attendanceContainerId}`,
|
|
255
|
+
};
|
|
256
|
+
const response = await this.api.post('/commands', body);
|
|
257
|
+
validateResponse(response);
|
|
258
|
+
return response.data.resource;
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
throw handleError(error);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async searchTickets({ filter, skip, take }) {
|
|
265
|
+
try {
|
|
266
|
+
const params = {
|
|
267
|
+
$filter: filter,
|
|
268
|
+
$skip: skip,
|
|
269
|
+
$take: take,
|
|
270
|
+
};
|
|
271
|
+
const body = {
|
|
272
|
+
id: randomUUID(),
|
|
273
|
+
to: 'postmaster@desk.msging.net',
|
|
274
|
+
method: 'get',
|
|
275
|
+
uri: `/tickets?${encodeBlipParams(params)}`,
|
|
276
|
+
};
|
|
277
|
+
const response = await this.api.post('/commands', body);
|
|
278
|
+
validateResponse(response);
|
|
279
|
+
return response.data.resource.items;
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
throw handleError(error);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
228
285
|
}
|