diff --git a/README.md b/README.md index 4626139..86c99ef 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Use this sample app to try the [Threads API](https://developers.facebook.com/doc - **Login and Account:** Sign in with Threads. View your profile details or sign out. - **Publishing:** Publish text, image, video, and carousel posts. -- **Publishing Options:** Add topic tags, link attachments, alt text, and polls. Set the reply audience, add spoilers, or create ghost posts. +- **Publishing Options:** Add topic tags, link attachments, alt text, and polls. Set the reply audience, add spoilers, or create ghost posts. Select **AI-Generated Content** to request an **AI info** label on a post (not available for ghost posts). - **Replies, Quotes, and Reposts:** Reply to, quote, or repost an existing post. - **Post Browsing:** Browse your posts, your replies, and posts that mention you. View post details and conversations. - **Reply Management:** Hide or unhide replies in the direct-replies view. diff --git a/postman/threads-api.postman_collection.json b/postman/threads-api.postman_collection.json index f282d10..8fc07cf 100644 --- a/postman/threads-api.postman_collection.json +++ b/postman/threads-api.postman_collection.json @@ -474,6 +474,12 @@ "description": "The ID of the location being tagged.", "disabled": true }, + { + "key": "is_made_with_ai", + "value": "true", + "description": "Optional boolean. Set to true to request an AI info label. Defaults to false and does not prevent automatic labeling. Not supported for ghost posts.", + "disabled": true + }, { "key": "auto_publish_text", "value": "true", @@ -672,6 +678,12 @@ "description": "The ID of the location being tagged.", "disabled": true }, + { + "key": "is_made_with_ai", + "value": "true", + "description": "Optional boolean. Set to true to request an AI info label. Defaults to false and does not prevent automatic labeling. Not supported for ghost posts.", + "disabled": true + }, { "key": "text_entities", "value": "[{\"entity_type\": \"SPOILER\",\"offset\": 0,\"length\": 4}]", @@ -841,6 +853,12 @@ "description": "The ID of the location being tagged.", "disabled": true }, + { + "key": "is_made_with_ai", + "value": "true", + "description": "Optional boolean. Set to true to request an AI info label. Defaults to false and does not prevent automatic labeling. Not supported for ghost posts.", + "disabled": true + }, { "key": "text_entities", "value": "[{\"entity_type\": \"SPOILER\",\"offset\": 0,\"length\": 4}]", @@ -1330,6 +1348,12 @@ "description": "The ID of the location being tagged.", "disabled": true }, + { + "key": "is_made_with_ai", + "value": "true", + "description": "Optional boolean. Set to true to request an AI info label. Defaults to false and does not prevent automatic labeling. Not supported for ghost posts.", + "disabled": true + }, { "key": "text_entities", "value": "[{\"entity_type\": \"SPOILER\",\"offset\": 0,\"length\": 4}]", diff --git a/public/scripts/upload.js b/public/scripts/upload.js index d08751f..eb00f4c 100644 --- a/public/scripts/upload.js +++ b/public/scripts/upload.js @@ -172,8 +172,13 @@ document.addEventListener('DOMContentLoaded', async () => { 'poll-attachment-options' ); + const aiCheckbox = document.getElementById('is-made-with-ai'); if (ghostPostCheckbox) { ghostPostCheckbox.addEventListener('change', async () => { + if (aiCheckbox) { + aiCheckbox.disabled = ghostPostCheckbox.checked; + if (ghostPostCheckbox.checked) aiCheckbox.checked = false; + } if (locationInput) { locationInput.disabled = ghostPostCheckbox.checked; if (ghostPostCheckbox.checked) locationInput.value = ''; diff --git a/src/index.js b/src/index.js index a25ad95..08ce9f3 100644 --- a/src/index.js +++ b/src/index.js @@ -105,6 +105,7 @@ const PARAMS__DELETE_QUOTA_USAGE = 'delete_quota_usage'; const PARAMS__FIELDS = 'fields'; const PARAMS__HIDE = 'hide'; const PARAMS__INPUT_TOKEN = 'input_token'; +const PARAMS__IS_MADE_WITH_AI = 'is_made_with_ai'; const PARAMS__LIMIT = 'limit'; const PARAMS__LINK_ATTACHMENT = 'link_attachment'; const PARAMS__LOCATION_ID = 'location_id'; @@ -860,6 +861,7 @@ app.post( quotePostId, spoilerMedia, ghostPostMedia, + isMadeWithAI, } = req.body; const pollOptions = [ @@ -965,11 +967,26 @@ app.post( }); } + if (isMadeWithAI !== undefined && isMadeWithAI !== 'on') { + return res.status(400).json({ + error: true, + message: 'Check the AI-Generated Content option and try again.', + }); + } + const discloseAI = isMadeWithAI === 'on'; + if (discloseAI && ghostPostMedia) { + return res.status(400).json({ + error: true, + message: 'Ghost posts cannot request an AI info label.', + }); + } + const params = { [PARAMS__REPLY_CONTROL]: replyControl, [PARAMS__REPLY_TO_ID]: replyToId, }; if (locationID) params[PARAMS__LOCATION_ID] = locationID; + if (discloseAI) params[PARAMS__IS_MADE_WITH_AI] = true; if (linkAttachment) { params[PARAMS__LINK_ATTACHMENT] = linkAttachment; } diff --git a/test/attachment-controls.test.js b/test/attachment-controls.test.js index 35a2042..fc5718e 100644 --- a/test/attachment-controls.test.js +++ b/test/attachment-controls.test.js @@ -35,6 +35,7 @@ test('media hides and disables text attachments, restores drafts, and preserves const pollControl = element(); pollControl.querySelectorAll = () => [...pollInputs, pollButton]; const ghost = element(); + const ai = element('on'); const linkControl = element(); const mediaType = element(); const attachments = element(); @@ -53,6 +54,7 @@ test('media hides and disables text attachments, restores drafts, and preserves '.reply-options-media-control': element(), }; const fields = { + 'is-made-with-ai': ai, 'media-type': mediaType, 'link-attachment': link, 'location-id': element('123'), @@ -132,9 +134,14 @@ test('media hides and disables text attachments, restores drafts, and preserves const location = fields['location-id']; assert.equal(location.value, '123'); assert.equal(location.disabled, false); + assert.equal(ai.checked, false); + assert.equal(ai.disabled, false); + ai.checked = true; ghost.checked = true; await ghost.events.change(); assert.equal(location.value, ''); + assert.equal(ai.checked, false); + assert.equal(ai.disabled, true); assert.equal(location.disabled, true); assertTextAttachments(false); assert.equal(link.value, ''); @@ -147,12 +154,19 @@ test('media hides and disables text attachments, restores drafts, and preserves ghost.checked = false; await ghost.events.change(); assert.equal(location.value, ''); + assert.equal(ai.checked, false); + assert.equal(ai.disabled, false); assert.equal(location.disabled, false); assertTextAttachments(true); const html = pug.renderFile(path.join(__dirname, '../views/upload.pug'), { title: 'Upload', }); + const checkbox = html.match(/]*name="isMadeWithAI"[^>]*>/)?.[0]; + assert.ok(checkbox); + assert.match(checkbox, /type="checkbox"/); + assert.match(checkbox, /value="on"/); + assert.doesNotMatch(checkbox, /\b(?:checked|disabled)\b/); assert.match( html, /