@dawntech/blip-tools 0.3.1 → 0.5.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 +673 -0
- package/dist/index.d.ts +4 -110
- package/dist/{index.js → index.mjs} +451 -123
- 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 +27 -0
- package/dist/modules/blip-media.d.ts +3 -1
- package/dist/modules/blip-monitoring.d.ts +11 -0
- 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/monitoring.d.ts +27 -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
|
@@ -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
|
-
}
|