Skip to content

Commit

Permalink
Merge pull request #28 from gabearro/fix-preview
Browse files Browse the repository at this point in the history
Adds the possibility to hide link previews
  • Loading branch information
wtfsayo authored Jan 5, 2025
2 parents 0fa3988 + 8292cd2 commit 454b144
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
15 changes: 11 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"tough-cookie": "^4.1.2",
"twitter-api-v2": "^1.18.2",
"undici": "^7.1.1",
"undici-types": "^7.2.0",
"ws": "^8.18.0"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,14 @@ export class Scraper {
text: string,
replyToTweetId?: string,
mediaData?: { data: Buffer; mediaType: string }[],
hideLinkPreview?: boolean,
) {
return await createCreateTweetRequest(
text,
this.auth,
replyToTweetId,
mediaData,
hideLinkPreview,
);
}

Expand Down
5 changes: 5 additions & 0 deletions src/tweets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ export async function createCreateTweetRequest(
auth: TwitterAuth,
tweetId?: string,
mediaData?: { data: Buffer; mediaType: string }[],
hideLinkPreview = false,
) {
const onboardingTaskUrl = 'https://api.twitter.com/1.1/onboarding/task.json';

Expand Down Expand Up @@ -476,6 +477,10 @@ export async function createCreateTweetRequest(
semantic_annotation_ids: [],
};

if (hideLinkPreview) {
variables["card_uri"] = "tombstone://card"
}

if (mediaData && mediaData.length > 0) {
const mediaIds = await Promise.all(
mediaData.map(({ data, mediaType }) =>
Expand Down

0 comments on commit 454b144

Please sign in to comment.