@@ -20,6 +20,7 @@ const upload = multer();
2020
2121const DEFAULT_THREADS_QUERY_LIMIT = 10 ;
2222
23+ const FIELD__ALT_TEXT = 'alt_text' ;
2324const FIELD__ERROR_MESSAGE = 'error_message' ;
2425const FIELD__FOLLOWERS_COUNT = 'followers_count' ;
2526const FIELD__HIDE_STATUS = 'hide_status' ;
@@ -46,6 +47,7 @@ const MEDIA_TYPE__TEXT = 'TEXT';
4647const MEDIA_TYPE__VIDEO = 'VIDEO' ;
4748
4849const PARAMS__ACCESS_TOKEN = 'access_token' ;
50+ const PARAMS__ALT_TEXT = 'alt_text' ;
4951const PARAMS__CLIENT_ID = 'client_id' ;
5052const PARAMS__CONFIG = 'config' ;
5153const PARAMS__FIELDS = 'fields' ;
@@ -298,7 +300,7 @@ app.get('/upload', loggedInUserChecker, (req, res) => {
298300} ) ;
299301
300302app . post ( '/upload' , upload . array ( ) , async ( req , res ) => {
301- const { text, attachmentType, attachmentUrl, replyControl, replyToId } = req . body ;
303+ const { text, attachmentType, attachmentUrl, attachmentAltText , replyControl, replyToId } = req . body ;
302304 const params = {
303305 [ PARAMS__TEXT ] : text ,
304306 [ PARAMS__REPLY_CONTROL ] : replyControl ,
@@ -311,7 +313,7 @@ app.post('/upload', upload.array(), async (req, res) => {
311313 }
312314 // Single attachment
313315 else if ( attachmentType ?. length === 1 ) {
314- addAttachmentFields ( params , attachmentType [ 0 ] , attachmentUrl [ 0 ] ) ;
316+ addAttachmentFields ( params , attachmentType [ 0 ] , attachmentUrl [ 0 ] , attachmentAltText [ 0 ] ) ;
315317 }
316318 // Multiple attachments
317319 else {
@@ -321,7 +323,7 @@ app.post('/upload', upload.array(), async (req, res) => {
321323 const child = {
322324 is_carousel_item : true ,
323325 } ;
324- addAttachmentFields ( child , type , attachmentUrl [ i ] ) ;
326+ addAttachmentFields ( child , type , attachmentUrl [ i ] , attachmentAltText [ i ] ) ;
325327 params . children . push ( child ) ;
326328 } ) ;
327329 }
@@ -430,7 +432,8 @@ app.get('/threads/:threadId', loggedInUserChecker, async (req, res) => {
430432 FIELD__TIMESTAMP ,
431433 FIELD__IS_REPLY ,
432434 FIELD__USERNAME ,
433- FIELD__REPLY_AUDIENCE
435+ FIELD__REPLY_AUDIENCE ,
436+ FIELD__ALT_TEXT ,
434437 ] . join ( ',' ) ,
435438 } , req . session . access_token ) ;
436439
@@ -458,6 +461,7 @@ app.get('/threads', loggedInUserChecker, async (req, res) => {
458461 FIELD__PERMALINK ,
459462 FIELD__TIMESTAMP ,
460463 FIELD__REPLY_AUDIENCE ,
464+ FIELD__ALT_TEXT ,
461465 ] . join ( ',' ) ,
462466 limit : limit ?? DEFAULT_THREADS_QUERY_LIMIT ,
463467 } ;
@@ -657,13 +661,15 @@ function getInsightsTotalValue(metrics, index) {
657661 * @param {string } attachmentType
658662 * @param {string } url
659663 */
660- function addAttachmentFields ( target , attachmentType , url ) {
664+ function addAttachmentFields ( target , attachmentType , url , altText ) {
661665 if ( attachmentType === 'Image' ) {
662666 target . media_type = MEDIA_TYPE__IMAGE ;
663667 target . image_url = url ;
668+ target . alt_text = altText ;
664669 } else if ( attachmentType === 'Video' ) {
665670 target . media_type = MEDIA_TYPE__VIDEO ;
666671 target . video_url = url ;
672+ target . alt_text = altText ;
667673 }
668674}
669675
@@ -714,6 +720,7 @@ async function showReplies(req, res, isTopLevel) {
714720 FIELD__TIMESTAMP ,
715721 FIELD__USERNAME ,
716722 FIELD__HIDE_STATUS ,
723+ FIELD__ALT_TEXT ,
717724 ] . join ( ',' ) ,
718725 limit : limit ?? DEFAULT_THREADS_QUERY_LIMIT ,
719726 } ;
0 commit comments