@dawntech/blip-tools 0.3.1 → 0.4.0
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/exceptions/index.d.ts +5 -0
- package/dist/helpers/validate-instance.d.ts +1 -1
- package/dist/index.cjs +619 -0
- package/dist/index.d.ts +4 -110
- package/dist/{index.js → index.mjs} +423 -149
- package/dist/modules/blip-attendance.d.ts +11 -0
- package/dist/modules/blip-bucket.d.ts +3 -1
- package/dist/modules/blip-contact.d.ts +15 -0
- package/dist/modules/blip-context.d.ts +19 -0
- package/dist/modules/blip-dispatch.d.ts +63 -0
- package/dist/modules/blip-event.d.ts +12 -0
- package/dist/modules/blip-interaction.d.ts +13 -0
- package/dist/modules/blip-main.d.ts +25 -0
- package/dist/modules/blip-media.d.ts +3 -1
- package/dist/modules/blip-ticket.d.ts +12 -0
- package/dist/modules/blip-whatsapp.d.ts +10 -0
- package/dist/modules/index.d.ts +11 -0
- package/dist/types/attendance-hour-container.d.ts +25 -0
- package/dist/types/blip-constructor.d.ts +4 -0
- package/dist/types/blip.d.ts +26 -0
- package/dist/types/campaign-notification-status.d.ts +21 -0
- package/dist/types/campaign-notification.d.ts +14 -0
- package/dist/types/campaing-request.d.ts +26 -0
- package/dist/types/contact.d.ts +8 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/template.d.ts +18 -0
- package/dist/types/ticket-search-result.d.ts +6 -0
- package/dist/types/ticket.d.ts +17 -0
- package/package.json +20 -5
- package/dist/exceptions/blip-error.js +0 -7
- package/dist/helpers/encode-blip-params.js +0 -11
- package/dist/helpers/encode-strings.js +0 -3
- package/dist/helpers/format-template-params.js +0 -6
- package/dist/helpers/handle-error.js +0 -14
- package/dist/helpers/validate-instance.js +0 -9
- package/dist/helpers/validate-response.js +0 -6
- package/dist/modules/blip-bucket.js +0 -88
- package/dist/modules/blip-media.js +0 -55
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { CampaignNotification } from '../types/campaign-notification';
|
|
3
|
+
import { CampaignNotificationStatus } from '../types/campaign-notification-status';
|
|
4
|
+
import { Template } from '../types/template';
|
|
5
|
+
export default class BlipDispatch {
|
|
6
|
+
private api;
|
|
7
|
+
constructor(context: {
|
|
8
|
+
api: AxiosInstance;
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Sends a template-based message to any user. For sending messages to clients who are active, use `sendTemplateMessage` instead.
|
|
12
|
+
*/
|
|
13
|
+
sendIndividualActiveCampaign({ campaignName, masterState, flowId, stateId, channelType, phone, templateName, params, }: {
|
|
14
|
+
campaignName: string;
|
|
15
|
+
masterState: string;
|
|
16
|
+
flowId: string;
|
|
17
|
+
stateId: string;
|
|
18
|
+
channelType: string;
|
|
19
|
+
phone: string;
|
|
20
|
+
templateName: string;
|
|
21
|
+
params: string[];
|
|
22
|
+
}): Promise<CampaignNotification>;
|
|
23
|
+
getCampaignNotificationStatus({ campaignNotificationId }: {
|
|
24
|
+
campaignNotificationId: string;
|
|
25
|
+
}): Promise<CampaignNotificationStatus[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Sends a template-based message to an active user. For sending messages to clients who have never interacted or are inactive, use `sendTemplate` instead.
|
|
28
|
+
*/
|
|
29
|
+
sendTemplateMessage({ identity, template, metadata, }: {
|
|
30
|
+
identity: string;
|
|
31
|
+
template: Template;
|
|
32
|
+
metadata?: string;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Sends a simple text message to an active user. For sending messages to clients who have never interacted or are inactive, use `sendTemplate` instead.
|
|
36
|
+
*/
|
|
37
|
+
sendSimpleMessage({ identity, content, metadata }: {
|
|
38
|
+
identity: string;
|
|
39
|
+
content: string;
|
|
40
|
+
metadata?: string;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Sends a text message to an active user with a midia. For sending messages to clients who have never interacted or are inactive, use `sendTemplate` instead.
|
|
44
|
+
*/
|
|
45
|
+
sendMediaMessage({ identity, text, metadata, uri, type, title, aspectRatio, size, previewUri, }: {
|
|
46
|
+
type?: string;
|
|
47
|
+
uri: string;
|
|
48
|
+
identity: string;
|
|
49
|
+
text: string;
|
|
50
|
+
metadata?: string;
|
|
51
|
+
title: string;
|
|
52
|
+
aspectRatio?: string;
|
|
53
|
+
size?: number;
|
|
54
|
+
previewUri?: string;
|
|
55
|
+
previewType?: string;
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
sendMessageWithButtons({ identity, message, buttons, metadata, }: {
|
|
58
|
+
identity: string;
|
|
59
|
+
message: string;
|
|
60
|
+
buttons: string[];
|
|
61
|
+
metadata?: string;
|
|
62
|
+
}): Promise<void>;
|
|
63
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
export default class BlipEvent {
|
|
3
|
+
private api;
|
|
4
|
+
constructor(context: {
|
|
5
|
+
api: AxiosInstance;
|
|
6
|
+
});
|
|
7
|
+
createTrackEvent({ category, action, identity }: {
|
|
8
|
+
category: string;
|
|
9
|
+
action: string;
|
|
10
|
+
identity?: string;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import BlipContext from './blip-context';
|
|
2
|
+
export default class BlipInteraction {
|
|
3
|
+
private blipContext;
|
|
4
|
+
constructor(context: {
|
|
5
|
+
blipContext: BlipContext;
|
|
6
|
+
});
|
|
7
|
+
moveUser({ identity, botIdentity, botFlowId, botStateId, }: {
|
|
8
|
+
identity: string;
|
|
9
|
+
botIdentity: string;
|
|
10
|
+
botFlowId: string;
|
|
11
|
+
botStateId: string;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import BlipBucket from './blip-bucket';
|
|
2
|
+
import BlipMedia from './blip-media';
|
|
3
|
+
import type { BlipConstructor } from '../types/blip-constructor';
|
|
4
|
+
import BlipAttendance from './blip-attendance';
|
|
5
|
+
import BlipContext from './blip-context';
|
|
6
|
+
import BlipDispatch from './blip-dispatch';
|
|
7
|
+
import BlipEvent from './blip-event';
|
|
8
|
+
import BlipInteraction from './blip-interaction';
|
|
9
|
+
import BlipTicket from './blip-ticket';
|
|
10
|
+
import BlipWhatsapp from './blip-whatsapp';
|
|
11
|
+
import BlipContact from './blip-contact';
|
|
12
|
+
export declare class Blip {
|
|
13
|
+
private api;
|
|
14
|
+
bucket: BlipBucket;
|
|
15
|
+
media: BlipMedia;
|
|
16
|
+
attendance: BlipAttendance;
|
|
17
|
+
contact: BlipContact;
|
|
18
|
+
context: BlipContext;
|
|
19
|
+
dispatch: BlipDispatch;
|
|
20
|
+
event: BlipEvent;
|
|
21
|
+
interaction: BlipInteraction;
|
|
22
|
+
ticket: BlipTicket;
|
|
23
|
+
whatsapp: BlipWhatsapp;
|
|
24
|
+
constructor(params: BlipConstructor);
|
|
25
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
2
|
export default class BlipMedia {
|
|
3
3
|
private api;
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(context: {
|
|
5
|
+
api: AxiosInstance;
|
|
6
|
+
});
|
|
5
7
|
/**
|
|
6
8
|
* Uploads an media file to Blip storage to be used later when sending messages
|
|
7
9
|
* @param content A Blob containing a image, PDF or video
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
export default class BlipTicket {
|
|
3
|
+
private api;
|
|
4
|
+
constructor(context: {
|
|
5
|
+
api: AxiosInstance;
|
|
6
|
+
});
|
|
7
|
+
search({ filter, skip, take }: {
|
|
8
|
+
filter?: string;
|
|
9
|
+
skip?: number;
|
|
10
|
+
take?: number;
|
|
11
|
+
}): Promise<import("../types").Ticket[]>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { Template } from '../types/template';
|
|
3
|
+
export default class BlipWhatsapp {
|
|
4
|
+
private api;
|
|
5
|
+
constructor(context: {
|
|
6
|
+
api: AxiosInstance;
|
|
7
|
+
});
|
|
8
|
+
getTemplates(): Promise<Template[]>;
|
|
9
|
+
getIdentity(phone: string): Promise<string>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import BlipBucket from './blip-bucket';
|
|
2
|
+
import BlipMedia from './blip-media';
|
|
3
|
+
import BlipAttendance from './blip-attendance';
|
|
4
|
+
import BlipContact from './blip-contact';
|
|
5
|
+
import BlipContext from './blip-context';
|
|
6
|
+
import BlipDispatch from './blip-dispatch';
|
|
7
|
+
import BlipEvent from './blip-event';
|
|
8
|
+
import BlipInteraction from './blip-interaction';
|
|
9
|
+
import BlipTicket from './blip-ticket';
|
|
10
|
+
import BlipWhatsapp from './blip-whatsapp';
|
|
11
|
+
export { BlipMedia, BlipBucket, BlipAttendance, BlipContact, BlipContext, BlipDispatch, BlipEvent, BlipInteraction, BlipTicket, BlipWhatsapp, };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface AttendanceHourContainer {
|
|
2
|
+
attendanceHour: {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
isMain: boolean;
|
|
7
|
+
ownerIdentity: string;
|
|
8
|
+
storageDate: string;
|
|
9
|
+
modifyDate: string;
|
|
10
|
+
timeZoneId: string;
|
|
11
|
+
};
|
|
12
|
+
attendanceHourScheduleItems: {
|
|
13
|
+
id: string;
|
|
14
|
+
startTime: string;
|
|
15
|
+
endTime: string;
|
|
16
|
+
dayOfWeek: string;
|
|
17
|
+
}[];
|
|
18
|
+
attendanceHourOffItems: {
|
|
19
|
+
id: string;
|
|
20
|
+
reason: string;
|
|
21
|
+
startDate: string;
|
|
22
|
+
endDate: string;
|
|
23
|
+
}[];
|
|
24
|
+
queues: [];
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface BlipRequestBody {
|
|
2
|
+
id: string;
|
|
3
|
+
to?: string;
|
|
4
|
+
method: string;
|
|
5
|
+
uri: string;
|
|
6
|
+
type?: string;
|
|
7
|
+
resource?: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface BlipResponse<T> {
|
|
10
|
+
type: string;
|
|
11
|
+
resource: T;
|
|
12
|
+
method: string;
|
|
13
|
+
status: string;
|
|
14
|
+
id: string;
|
|
15
|
+
from: string;
|
|
16
|
+
to: string;
|
|
17
|
+
metadata: {
|
|
18
|
+
traceparent: string;
|
|
19
|
+
'#command.uri': string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface BlipArrayBody<T> {
|
|
23
|
+
total: number;
|
|
24
|
+
itemType: string;
|
|
25
|
+
items: T[];
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface CampaignNotificationStatus {
|
|
2
|
+
event: string;
|
|
3
|
+
reason: {
|
|
4
|
+
code: number;
|
|
5
|
+
description: string;
|
|
6
|
+
};
|
|
7
|
+
id: string;
|
|
8
|
+
from: string;
|
|
9
|
+
to: string;
|
|
10
|
+
metadata: {
|
|
11
|
+
traceparent: string;
|
|
12
|
+
'#envelope.timestamp': string;
|
|
13
|
+
'#wa.timestamp'?: string;
|
|
14
|
+
'#message.uniqueId': string;
|
|
15
|
+
'#wa.conversation.origin.type'?: string;
|
|
16
|
+
'#wa.conversation.id'?: string;
|
|
17
|
+
'#message.to'?: string;
|
|
18
|
+
'#message.from'?: string;
|
|
19
|
+
'#envelope.storageDate': string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CampaignNotification {
|
|
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
|
+
tags: string[];
|
|
11
|
+
isToUseLiteApi: boolean;
|
|
12
|
+
channelType: string;
|
|
13
|
+
canSendWithOpenTicket: boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface CampaignRequestBody {
|
|
2
|
+
id: string;
|
|
3
|
+
to: string;
|
|
4
|
+
method: string;
|
|
5
|
+
uri: string;
|
|
6
|
+
type: string;
|
|
7
|
+
resource: {
|
|
8
|
+
campaign: {
|
|
9
|
+
name: string;
|
|
10
|
+
campaignType: string;
|
|
11
|
+
masterState: string;
|
|
12
|
+
flowId: string;
|
|
13
|
+
stateId: string;
|
|
14
|
+
channelType: string;
|
|
15
|
+
};
|
|
16
|
+
audience: {
|
|
17
|
+
recipient: string;
|
|
18
|
+
messageParams?: Record<string, string>;
|
|
19
|
+
};
|
|
20
|
+
message: {
|
|
21
|
+
messageTemplate: string;
|
|
22
|
+
messageParams?: string[];
|
|
23
|
+
channelType: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AttendanceHourContainer } from './attendance-hour-container';
|
|
2
|
+
import { BlipConstructor } from './blip-constructor';
|
|
3
|
+
import { BlipRequestBody, BlipResponse, BlipArrayBody } from './blip';
|
|
4
|
+
import { Parameter, Component, Template } from './template';
|
|
5
|
+
import { TicketSearchResult } from './ticket-search-result';
|
|
6
|
+
import { Ticket } from './ticket';
|
|
7
|
+
export { AttendanceHourContainer, BlipConstructor, BlipRequestBody, BlipResponse, BlipArrayBody, Parameter, Component, Template, TicketSearchResult, Ticket, };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface Parameter {
|
|
2
|
+
type: 'text';
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
export interface Component {
|
|
6
|
+
type: 'body' | 'button';
|
|
7
|
+
sub_type?: 'url';
|
|
8
|
+
index?: number;
|
|
9
|
+
parameters: Parameter[];
|
|
10
|
+
}
|
|
11
|
+
export interface Template {
|
|
12
|
+
name: string;
|
|
13
|
+
language: {
|
|
14
|
+
code: string;
|
|
15
|
+
policy: string;
|
|
16
|
+
};
|
|
17
|
+
components: Component[] | string[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface Ticket {
|
|
2
|
+
id: string;
|
|
3
|
+
sequentialId: number;
|
|
4
|
+
ownerIdentity: string;
|
|
5
|
+
customerIdentity: string;
|
|
6
|
+
customerDomain: string;
|
|
7
|
+
provider: string;
|
|
8
|
+
status: string;
|
|
9
|
+
storageDate: string;
|
|
10
|
+
externalId: string;
|
|
11
|
+
rating: number;
|
|
12
|
+
team: string;
|
|
13
|
+
unreadMessages: number;
|
|
14
|
+
closed: boolean;
|
|
15
|
+
priority: number;
|
|
16
|
+
CampaignId?: string;
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dawntech/blip-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Node package for Blip API",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"import": {
|
|
8
|
+
"default": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"require": {
|
|
12
|
+
"default": "./dist/index.cjs",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"./types": {
|
|
17
|
+
"types": "./dist/types/index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
8
20
|
"type": "module",
|
|
9
21
|
"scripts": {
|
|
10
|
-
"build": "
|
|
22
|
+
"build": "rollup --config rollup.config.js",
|
|
11
23
|
"lint": "eslint . --ignore-pattern 'dist/*'",
|
|
12
24
|
"lint:fix": "eslint . --fix --ignore-pattern 'dist/*'",
|
|
13
25
|
"format": "prettier --check 'src/**/*.ts'",
|
|
@@ -30,10 +42,13 @@
|
|
|
30
42
|
"license": "MIT",
|
|
31
43
|
"devDependencies": {
|
|
32
44
|
"@eslint/js": "^9.22.0",
|
|
45
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
33
46
|
"@types/node": "^22.13.10",
|
|
34
47
|
"@typescript-eslint/eslint-plugin": "^8.26.0",
|
|
35
48
|
"eslint": "^9.22.0",
|
|
36
49
|
"prettier": "^3.5.3",
|
|
50
|
+
"rollup": "^4.50.2",
|
|
51
|
+
"tslib": "^2.8.1",
|
|
37
52
|
"typescript": "^5.8.2",
|
|
38
53
|
"typescript-eslint": "^8.26.0"
|
|
39
54
|
},
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import encodeString from './encode-strings.js';
|
|
2
|
-
export default function encodeBlipParams(params) {
|
|
3
|
-
//This function does not uses any of the standard methods of URI parsing because Blip does not follow any of them
|
|
4
|
-
const parsedParams = [];
|
|
5
|
-
for (const [key, value] of Object.entries(params)) {
|
|
6
|
-
if (value && key) {
|
|
7
|
-
parsedParams.push(`${encodeString(key)}=${encodeString(value)}`);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
return parsedParams.join('&');
|
|
11
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AxiosError } from 'axios';
|
|
2
|
-
import BlipError from '../exceptions/blip-error.js';
|
|
3
|
-
export default function handleError(error) {
|
|
4
|
-
if (error instanceof BlipError) {
|
|
5
|
-
throw error;
|
|
6
|
-
}
|
|
7
|
-
if (error instanceof AxiosError) {
|
|
8
|
-
if (error.response?.data.code) {
|
|
9
|
-
throw new BlipError(error.response?.data.description, error.response?.data.code);
|
|
10
|
-
}
|
|
11
|
-
throw new BlipError(error.message, 0);
|
|
12
|
-
}
|
|
13
|
-
throw error;
|
|
14
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import BlipError from '../exceptions/blip-error.js';
|
|
2
|
-
export default function validateInstance(params) {
|
|
3
|
-
if (!params.contract) {
|
|
4
|
-
throw new BlipError('A contract must be specified.');
|
|
5
|
-
}
|
|
6
|
-
if (!params.authToken) {
|
|
7
|
-
throw new BlipError('An authToken must be provided.');
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import encodeString from '../helpers/encode-strings.js';
|
|
2
|
-
import { randomUUID } from 'crypto';
|
|
3
|
-
import encodeBlipParams from '../helpers/encode-blip-params.js';
|
|
4
|
-
import validateResponse from '../helpers/validate-response.js';
|
|
5
|
-
import handleError from '../helpers/handle-error.js';
|
|
6
|
-
export default class BlipBucket {
|
|
7
|
-
api;
|
|
8
|
-
constructor(api) {
|
|
9
|
-
this.api = api;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
Stores JSON content in a bucket provided by Blip. The content can be updaded or retrieved using the same id used in the update.
|
|
13
|
-
You can optionally provide a expiration time (in milliseconds) to delete the document after a certain amount of time.
|
|
14
|
-
*/
|
|
15
|
-
async storeContentInBucket(id, content, opts) {
|
|
16
|
-
try {
|
|
17
|
-
let uri = `/buckets/${encodeString(id)}`;
|
|
18
|
-
const params = {};
|
|
19
|
-
if (opts?.expiresInMs) {
|
|
20
|
-
params.expiration = opts?.expiresInMs;
|
|
21
|
-
uri += `?${encodeBlipParams(params)}`;
|
|
22
|
-
}
|
|
23
|
-
const body = {
|
|
24
|
-
id: randomUUID(),
|
|
25
|
-
method: 'set',
|
|
26
|
-
type: 'application/json',
|
|
27
|
-
uri,
|
|
28
|
-
resource: content,
|
|
29
|
-
};
|
|
30
|
-
const response = await this.api.post('/commands', body);
|
|
31
|
-
validateResponse(response);
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
throw handleError(error);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
Retrieves a document from the Blip bucket.
|
|
39
|
-
*/
|
|
40
|
-
async getContentFromBucket(id) {
|
|
41
|
-
try {
|
|
42
|
-
const body = {
|
|
43
|
-
id: randomUUID(),
|
|
44
|
-
method: 'get',
|
|
45
|
-
uri: `/buckets/${encodeString(id)}`,
|
|
46
|
-
};
|
|
47
|
-
const response = await this.api.post('/commands', body);
|
|
48
|
-
validateResponse(response);
|
|
49
|
-
return response.data.resource;
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
throw handleError(error);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async getAllContentIdsFromBucket() {
|
|
56
|
-
try {
|
|
57
|
-
const body = {
|
|
58
|
-
id: randomUUID(),
|
|
59
|
-
method: 'get',
|
|
60
|
-
uri: `/buckets`,
|
|
61
|
-
};
|
|
62
|
-
const response = await this.api.post('/commands', body);
|
|
63
|
-
validateResponse(response);
|
|
64
|
-
return response.data.resource.items;
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
throw handleError(error);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
Deletes a JSON document from the Blip bucket.
|
|
72
|
-
*/
|
|
73
|
-
async deleteContentFromBucket(id) {
|
|
74
|
-
try {
|
|
75
|
-
const body = {
|
|
76
|
-
id: randomUUID(),
|
|
77
|
-
method: 'delete',
|
|
78
|
-
uri: `/buckets/${encodeString(id)}`,
|
|
79
|
-
to: 'postmaster@msging.net',
|
|
80
|
-
};
|
|
81
|
-
const response = await this.api.post('/commands', body);
|
|
82
|
-
validateResponse(response);
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
throw handleError(error);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { randomUUID } from 'crypto';
|
|
3
|
-
import validateResponse from '../helpers/validate-response.js';
|
|
4
|
-
import handleError from '../helpers/handle-error.js';
|
|
5
|
-
export default class BlipMedia {
|
|
6
|
-
api;
|
|
7
|
-
constructor(api) {
|
|
8
|
-
this.api = api;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Uploads an media file to Blip storage to be used later when sending messages
|
|
12
|
-
* @param content A Blob containing a image, PDF or video
|
|
13
|
-
* @returns A public URL
|
|
14
|
-
*/
|
|
15
|
-
async uploadMedia(content) {
|
|
16
|
-
try {
|
|
17
|
-
const response = await this.api.post('/commands', {
|
|
18
|
-
id: randomUUID(),
|
|
19
|
-
to: 'postmaster@media.msging.net',
|
|
20
|
-
method: 'get',
|
|
21
|
-
uri: '/upload-media-uri',
|
|
22
|
-
});
|
|
23
|
-
validateResponse(response);
|
|
24
|
-
const uploadResponse = await axios.post(response.data.resource, content, {
|
|
25
|
-
headers: { 'Content-Type': 'application/octet-stream' },
|
|
26
|
-
});
|
|
27
|
-
return uploadResponse.data.mediaUri;
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
throw handleError(error);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Generates a new public URI to access blip chat media. Blip medias have expiration dates so you need to generate new ones to access the data.
|
|
35
|
-
* @param expiredMediaUri Blip media expired URI
|
|
36
|
-
* @returns A new public URI
|
|
37
|
-
*/
|
|
38
|
-
async refreshMediaUri(expiredMediaUri) {
|
|
39
|
-
try {
|
|
40
|
-
const response = await this.api.post('/commands', {
|
|
41
|
-
id: randomUUID(),
|
|
42
|
-
to: 'postmaster@media.msging.net',
|
|
43
|
-
method: 'set',
|
|
44
|
-
type: 'text/plain',
|
|
45
|
-
uri: '/refresh-media-uri',
|
|
46
|
-
resource: expiredMediaUri,
|
|
47
|
-
});
|
|
48
|
-
validateResponse(response);
|
|
49
|
-
return response.data.resource;
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
throw handleError(error);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|