@@ -55,6 +55,7 @@ const MEDIA_TYPE__TEXT = 'TEXT';
5555const MEDIA_TYPE__VIDEO = 'VIDEO' ;
5656
5757const PARAMS__ACCESS_TOKEN = 'access_token' ;
58+ const PARAMS__AUTO_PUBLISH_TEXT = 'auto_publish_text' ;
5859const PARAMS__ALT_TEXT = 'alt_text' ;
5960const PARAMS__CLIENT_ID = 'client_id' ;
6061const PARAMS__CONFIG = 'config' ;
@@ -370,6 +371,7 @@ app.post('/upload', upload.array(), async (req, res) => {
370371 replyControl,
371372 replyToId,
372373 linkAttachment,
374+ autoPublishText,
373375 pollOptionA,
374376 pollOptionB,
375377 pollOptionC,
@@ -419,6 +421,10 @@ app.post('/upload', upload.array(), async (req, res) => {
419421 } ) ;
420422 }
421423
424+ if ( autoPublishText === 'on' && params . media_type === MEDIA_TYPE__TEXT ) {
425+ params [ PARAMS__AUTO_PUBLISH_TEXT ] = true ;
426+ }
427+
422428 if ( params . media_type === MEDIA_TYPE__CAROUSEL ) {
423429 const createChildPromises = params . children . map ( child => (
424430 axios . post (
@@ -446,10 +452,18 @@ app.post('/upload', upload.array(), async (req, res) => {
446452 const postThreadsUrl = buildGraphAPIURL ( `me/threads` , params , req . session . access_token ) ;
447453 try {
448454 const postResponse = await axios . post ( postThreadsUrl , { } , { httpsAgent : agent } ) ;
449- const containerId = postResponse . data . id ;
450- res . json ( {
451- id : containerId ,
452- } ) ;
455+ const id = postResponse . data . id ;
456+ if ( autoPublishText === 'on' && params . media_type === MEDIA_TYPE__TEXT ) {
457+ // If auto_publish_text is on, the returned ID is the published Threads ID.
458+ return res . json ( {
459+ redirectUrl : `/threads/${ id } `
460+ } ) ;
461+ } else {
462+ // Otherwise, the returned ID is the container ID.
463+ return res . json ( {
464+ id : id ,
465+ } ) ;
466+ }
453467 }
454468 catch ( e ) {
455469 console . error ( e . message ) ;
0 commit comments