@@ -9,6 +9,7 @@ import { makeId } from '@gitroom/nestjs-libraries/services/make.is';
9
9
import { timer } from '@gitroom/helpers/utils/timer' ;
10
10
import dayjs from 'dayjs' ;
11
11
import { SocialAbstract } from '@gitroom/nestjs-libraries/integrations/social.abstract' ;
12
+ import { InstagramDto } from '@gitroom/nestjs-libraries/dtos/posts/providers-settings/instagram.dto' ;
12
13
13
14
export class InstagramProvider
14
15
extends SocialAbstract
@@ -203,10 +204,11 @@ export class InstagramProvider
203
204
async post (
204
205
id : string ,
205
206
accessToken : string ,
206
- postDetails : PostDetails [ ]
207
+ postDetails : PostDetails < InstagramDto > [ ]
207
208
) : Promise < PostResponse [ ] > {
208
209
const [ firstPost , ...theRest ] = postDetails ;
209
-
210
+ console . log ( 'in progress' ) ;
211
+ const isStory = firstPost . settings . post_type === 'story' ;
210
212
const medias = await Promise . all (
211
213
firstPost ?. media ?. map ( async ( m ) => {
212
214
const caption =
@@ -218,18 +220,34 @@ export class InstagramProvider
218
220
const mediaType =
219
221
m . url . indexOf ( '.mp4' ) > - 1
220
222
? firstPost ?. media ?. length === 1
221
- ? `video_url=${ m . url } &media_type=REELS`
223
+ ? isStory
224
+ ? `video_url=${ m . url } &media_type=STORIES`
225
+ : `video_url=${ m . url } &media_type=REELS`
226
+ : isStory
227
+ ? `video_url=${ m . url } &media_type=STORIES`
222
228
: `video_url=${ m . url } &media_type=VIDEO`
229
+ : isStory
230
+ ? `image_url=${ m . url } &media_type=STORIES`
223
231
: `image_url=${ m . url } ` ;
232
+ console . log ( 'in progress1' ) ;
233
+
234
+ const collaborators =
235
+ firstPost ?. settings ?. collaborators ?. length && ! isStory
236
+ ? `&collaborators=${ JSON . stringify (
237
+ firstPost ?. settings ?. collaborators . map ( ( p ) => p . label )
238
+ ) } `
239
+ : `` ;
224
240
241
+ console . log ( collaborators ) ;
225
242
const { id : photoId } = await (
226
243
await this . fetch (
227
- `https://graph.facebook.com/v20.0/${ id } /media?${ mediaType } ${ isCarousel } &access_token=${ accessToken } ${ caption } ` ,
244
+ `https://graph.facebook.com/v20.0/${ id } /media?${ mediaType } ${ isCarousel } ${ collaborators } &access_token=${ accessToken } ${ caption } ` ,
228
245
{
229
246
method : 'POST' ,
230
247
}
231
248
)
232
249
) . json ( ) ;
250
+ console . log ( 'in progress2' ) ;
233
251
234
252
let status = 'IN_PROGRESS' ;
235
253
while ( status === 'IN_PROGRESS' ) {
@@ -241,6 +259,7 @@ export class InstagramProvider
241
259
await timer ( 3000 ) ;
242
260
status = status_code ;
243
261
}
262
+ console . log ( 'in progress3' ) ;
244
263
245
264
return photoId ;
246
265
} ) || [ ]
@@ -376,4 +395,12 @@ export class InstagramProvider
376
395
} ) ) || [ ]
377
396
) ;
378
397
}
398
+
399
+ music ( accessToken : string , data : { q : string } ) {
400
+ return this . fetch (
401
+ `https://graph.facebook.com/v20.0/music/search?q=${ encodeURIComponent (
402
+ data . q
403
+ ) } &access_token=${ accessToken } `
404
+ ) ;
405
+ }
379
406
}
0 commit comments