nodejs-insta-private-api-mqtt 1.3.13 → 1.3.14
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/README.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Dear users,
|
|
2
|
-
First of all, when handling view-once images or videos, please make sure to save the received media in a folder such as /storage/emulated/0/Pictures/, or depending on your device's path. The photos and videos are saved correctly on your phone, but the library currently has some issues with uploading them back to Instagram. This will be resolved as soon as possible.
|
|
3
2
|
I post many versions of the project because Instagram changes the protocol almost daily, if you like this project leave a star on github https://github.com/Kunboruto20/nodejs-insta-private-api.git
|
|
4
3
|
|
|
5
4
|
|
|
@@ -263,42 +262,50 @@ startBot().catch(console.error);
|
|
|
263
262
|
|
|
264
263
|
---
|
|
265
264
|
|
|
266
|
-
## 🖼️
|
|
265
|
+
## 🖼️ FIXED: Send Media via MQTT (v5.70.0)
|
|
267
266
|
|
|
268
|
-
You can now send photos
|
|
267
|
+
The upload issue has been fully resolved. You can now send photos and videos directly through the MQTT protocol. The library now handles raw buffers correctly, matching the Instagram internal protocol for zero "Upload Failed" errors.
|
|
269
268
|
|
|
270
|
-
### Send
|
|
271
|
-
```javascript
|
|
272
|
-
const { IgApiClient, RealtimeClient, sendmedia } = require('nodejs-insta-private-api-mqtt');
|
|
273
|
-
const fs = require('fs');
|
|
269
|
+
### Send Media via MQTT (v5.70.0)
|
|
274
270
|
|
|
275
|
-
|
|
276
|
-
const ig = new IgApiClient();
|
|
277
|
-
// ... login logic ...
|
|
271
|
+
You can now send photos, videos, voice messages, and more directly through the MQTT protocol. The library handles the upload and linking automatically.
|
|
278
272
|
|
|
279
|
-
|
|
280
|
-
|
|
273
|
+
#### 📷 Send a Photo
|
|
274
|
+
```javascript
|
|
275
|
+
const photoBuffer = fs.readFileSync('./image.jpg');
|
|
276
|
+
const upload = await ig.publish.photo({ file: photoBuffer });
|
|
281
277
|
|
|
282
|
-
|
|
278
|
+
await realtime.directCommands.sendMedia({
|
|
279
|
+
threadId: 'THREAD_ID',
|
|
280
|
+
mediaId: upload.upload_id,
|
|
281
|
+
uploadId: upload.upload_id
|
|
282
|
+
});
|
|
283
|
+
```
|
|
283
284
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
285
|
+
#### 🎥 Send a Video
|
|
286
|
+
```javascript
|
|
287
|
+
const videoBuffer = fs.readFileSync('./video.mp4');
|
|
288
|
+
const upload = await ig.publish.video({
|
|
289
|
+
video: videoBuffer,
|
|
290
|
+
duration: 10000, // ms
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
await realtime.directCommands.sendMedia({
|
|
294
|
+
threadId: 'THREAD_ID',
|
|
295
|
+
mediaId: upload.upload_id,
|
|
296
|
+
uploadId: upload.upload_id
|
|
297
|
+
});
|
|
292
298
|
```
|
|
293
299
|
|
|
294
|
-
|
|
300
|
+
#### 🎤 Send Voice Message
|
|
295
301
|
```javascript
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
+
const audioBuffer = fs.readFileSync('./voice.mp4');
|
|
303
|
+
const upload = await ig.publish.audio({ file: audioBuffer });
|
|
304
|
+
|
|
305
|
+
await realtime.directCommands.sendMedia({
|
|
306
|
+
threadId: 'THREAD_ID',
|
|
307
|
+
mediaId: upload.upload_id,
|
|
308
|
+
uploadId: upload.upload_id
|
|
302
309
|
});
|
|
303
310
|
```
|
|
304
311
|
|
|
@@ -962,7 +969,7 @@ const {
|
|
|
962
969
|
RealtimeClient,
|
|
963
970
|
downloadContentFromMessage,
|
|
964
971
|
isViewOnceMedia
|
|
965
|
-
} = require('nodejs-insta-private-api');
|
|
972
|
+
} = require('nodejs-insta-private-api-mqtt');
|
|
966
973
|
const fs = require('fs');
|
|
967
974
|
|
|
968
975
|
const ig = new IgApiClient();
|
|
@@ -1014,7 +1021,8 @@ realtime.on('message', async (data) => {
|
|
|
1014
1021
|
const {
|
|
1015
1022
|
downloadMediaBuffer,
|
|
1016
1023
|
hasMedia,
|
|
1017
|
-
getMediaType
|
|
1024
|
+
getMediaType,
|
|
1025
|
+
MEDIA_TYPES
|
|
1018
1026
|
} = require('nodejs-insta-private-api-mqtt');
|
|
1019
1027
|
|
|
1020
1028
|
realtime.on('message', async (data) => {
|
|
@@ -1203,7 +1211,7 @@ startMediaBot().catch(console.error);
|
|
|
1203
1211
|
### MEDIA_TYPES Constants
|
|
1204
1212
|
|
|
1205
1213
|
```javascript
|
|
1206
|
-
const { MEDIA_TYPES } = require('nodejs-insta-private-api');
|
|
1214
|
+
const { MEDIA_TYPES } = require('nodejs-insta-private-api-mqtt');
|
|
1207
1215
|
|
|
1208
1216
|
MEDIA_TYPES.IMAGE // Regular photo
|
|
1209
1217
|
MEDIA_TYPES.VIDEO // Regular video
|
|
@@ -504,8 +504,8 @@ class EnhancedDirectCommands {
|
|
|
504
504
|
/**
|
|
505
505
|
* Send media (image/video) via MQTT
|
|
506
506
|
*/
|
|
507
|
-
async sendMedia({ text, mediaId, threadId, clientContext }) {
|
|
508
|
-
this.enhancedDebug(`Sending media ${mediaId} to ${threadId} via MQTT`);
|
|
507
|
+
async sendMedia({ text, mediaId, threadId, clientContext, uploadId }) {
|
|
508
|
+
this.enhancedDebug(`Sending media ${mediaId} (uploadId: ${uploadId}) to ${threadId} via MQTT`);
|
|
509
509
|
|
|
510
510
|
try {
|
|
511
511
|
const mqtt = this.realtimeClient.mqtt || this.realtimeClient._mqtt;
|
|
@@ -519,16 +519,20 @@ class EnhancedDirectCommands {
|
|
|
519
519
|
thread_id: threadId,
|
|
520
520
|
item_type: 'media',
|
|
521
521
|
media_id: mediaId,
|
|
522
|
+
upload_id: uploadId || mediaId,
|
|
522
523
|
text: text || '',
|
|
523
524
|
timestamp: Date.now(),
|
|
524
525
|
client_context: ctx,
|
|
525
526
|
};
|
|
526
527
|
|
|
528
|
+
// Log payload for debugging
|
|
529
|
+
this.enhancedDebug(`Payload: ${JSON.stringify(command)}`);
|
|
530
|
+
|
|
527
531
|
const json = JSON.stringify(command);
|
|
528
532
|
const { compressDeflate } = shared_1;
|
|
529
533
|
const payload = await compressDeflate(json);
|
|
530
534
|
|
|
531
|
-
this.enhancedDebug(`Publishing media to MQTT`);
|
|
535
|
+
this.enhancedDebug(`Publishing media to MQTT topic ${constants_1.Topics.SEND_MESSAGE.id}`);
|
|
532
536
|
const result = await mqtt.publish({
|
|
533
537
|
topic: constants_1.Topics.SEND_MESSAGE.id,
|
|
534
538
|
qosLevel: 1,
|
|
@@ -16,14 +16,11 @@ class UploadRepository extends Repository {
|
|
|
16
16
|
|
|
17
17
|
const ruploadParams = this.createPhotoRuploadParams(options, uploadId);
|
|
18
18
|
|
|
19
|
-
const formData = new FormData();
|
|
20
|
-
formData.append('photo', options.file, { filename: 'photo.jpg' });
|
|
21
|
-
|
|
22
19
|
const response = await this.client.request.send({
|
|
23
20
|
url: `/rupload_igphoto/${name}`,
|
|
24
21
|
method: 'POST',
|
|
25
22
|
headers: {
|
|
26
|
-
'
|
|
23
|
+
'X_FB_PHOTO_WATERFALL_ID': waterfallId,
|
|
27
24
|
'X-Entity-Type': 'image/jpeg',
|
|
28
25
|
'Offset': '0',
|
|
29
26
|
'X-Instagram-Rupload-Params': JSON.stringify(ruploadParams),
|
|
@@ -32,9 +29,8 @@ class UploadRepository extends Repository {
|
|
|
32
29
|
'Content-Type': 'application/octet-stream',
|
|
33
30
|
'Content-Length': options.file.length.toString(),
|
|
34
31
|
'Accept-Encoding': 'gzip',
|
|
35
|
-
...formData.getHeaders(),
|
|
36
32
|
},
|
|
37
|
-
|
|
33
|
+
body: options.file,
|
|
38
34
|
});
|
|
39
35
|
|
|
40
36
|
return response.body;
|
|
@@ -51,7 +47,7 @@ class UploadRepository extends Repository {
|
|
|
51
47
|
url: `/rupload_igvideo/${name}`,
|
|
52
48
|
method: 'POST',
|
|
53
49
|
headers: {
|
|
54
|
-
'
|
|
50
|
+
'X_FB_VIDEO_WATERFALL_ID': waterfallId,
|
|
55
51
|
'X-Entity-Type': 'video/mp4',
|
|
56
52
|
'Offset': options.offset || '0',
|
|
57
53
|
'X-Instagram-Rupload-Params': JSON.stringify(ruploadParams),
|
|
@@ -61,7 +57,7 @@ class UploadRepository extends Repository {
|
|
|
61
57
|
'Content-Length': options.video.length.toString(),
|
|
62
58
|
'Accept-Encoding': 'gzip',
|
|
63
59
|
},
|
|
64
|
-
|
|
60
|
+
body: options.video,
|
|
65
61
|
});
|
|
66
62
|
|
|
67
63
|
return response.body;
|
|
@@ -80,7 +76,7 @@ class UploadRepository extends Repository {
|
|
|
80
76
|
image_compression: JSON.stringify({
|
|
81
77
|
lib_name: 'moz',
|
|
82
78
|
lib_version: '3.1.m',
|
|
83
|
-
quality: '
|
|
79
|
+
quality: '80',
|
|
84
80
|
}),
|
|
85
81
|
};
|
|
86
82
|
}
|
|
@@ -36,21 +36,13 @@ async function sendPhoto(session, opts = {}) {
|
|
|
36
36
|
|
|
37
37
|
// 2) If RealtimeClient is provided and connected, use MQTT
|
|
38
38
|
if (realtimeClient) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// or we can instantiate it if not present.
|
|
43
|
-
|
|
44
|
-
// Check if .direct exists and has sendMedia
|
|
45
|
-
if (realtimeClient.direct && typeof realtimeClient.direct.sendMedia === 'function') {
|
|
46
|
-
return await realtimeClient.direct.sendMedia({
|
|
39
|
+
const commands = realtimeClient.directCommands || realtimeClient.direct;
|
|
40
|
+
if (commands && typeof commands.sendMedia === 'function') {
|
|
41
|
+
return await commands.sendMedia({
|
|
47
42
|
text: caption,
|
|
48
43
|
mediaId: upload_id,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// MQTT is best for existing threads.
|
|
52
|
-
// If userId is provided, we might need to create thread via REST first?
|
|
53
|
-
// For now, assume threadId is preferred for MQTT.
|
|
44
|
+
uploadId: upload_id, // Pass upload_id to MQTT
|
|
45
|
+
threadId: threadId || userId,
|
|
54
46
|
});
|
|
55
47
|
}
|
|
56
48
|
}
|
|
@@ -55,10 +55,10 @@ async function uploadPhoto(session, photoBuffer, options = {}) {
|
|
|
55
55
|
|
|
56
56
|
// Headers expected by Instagram rupload (matched with instagram-private-api)
|
|
57
57
|
const headers = {
|
|
58
|
-
'X-Instagram-Rupload-Params': JSON.stringify(ruploadParams),
|
|
59
58
|
'X_FB_PHOTO_WATERFALL_ID': uuidv4(),
|
|
60
|
-
'X-Entity-Type': 'image/jpeg',
|
|
59
|
+
'X-Entity-Type': 'image/jpeg',
|
|
61
60
|
'Offset': '0',
|
|
61
|
+
'X-Instagram-Rupload-Params': JSON.stringify(ruploadParams),
|
|
62
62
|
'X-Entity-Name': name,
|
|
63
63
|
'X-Entity-Length': String(contentLength),
|
|
64
64
|
'Content-Type': 'application/octet-stream',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodejs-insta-private-api-mqtt",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.14",
|
|
4
4
|
"description": "Complete Instagram MQTT protocol with FULL iOS + Android support. 33 device presets (21 iOS + 12 Android). iPhone 16/15/14/13/12, iPad Pro, Samsung, Pixel, Huawei. Real-time DM messaging, view-once media extraction, sub-500ms latency.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|