generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1773 from ishowvel/development
feat: make twitter client be optional
- Loading branch information
Showing
3 changed files
with
33 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import { twitterClient } from "./twitter"; | ||
|
||
export async function deleteTweet(id: string) { | ||
try { | ||
const { data } = await twitterClient.v2.deleteTweet(id); | ||
if (data?.deleted) { | ||
console.log(`Successfully deleted tweet, id: ${id}`); | ||
} else { | ||
console.log(`Could not delete tweet, id ${id}`); | ||
if (twitterClient) { | ||
try { | ||
const { data } = await twitterClient.v2.deleteTweet(id); | ||
if (data?.deleted) { | ||
console.log(`Successfully deleted tweet, id: ${id}`); | ||
} else { | ||
console.log(`Could not delete tweet, id ${id}`); | ||
} | ||
} catch (error) { | ||
console.error("Error deleting tweet", error); | ||
} | ||
} catch (error) { | ||
console.error("Error deleting tweet", error); | ||
} else { | ||
console.log("Skipping deleting a tweet due to missing env variables"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { twitterClient } from "./twitter"; | ||
|
||
export async function postTweet(status: string) { | ||
try { | ||
const { data } = await twitterClient.v2.tweet(status); | ||
console.log(`Tweet posted successfully, id: ${data.id}, text: ${data.text}`); | ||
return data; | ||
} catch (error) { | ||
console.error("Error posting tweet", error); | ||
if (twitterClient) { | ||
try { | ||
const { data } = await twitterClient.v2.tweet(status); | ||
console.log(`Tweet posted successfully, id: ${data.id}, text: ${data.text}`); | ||
return data; | ||
} catch (error) { | ||
console.error("Error posting tweet", error); | ||
} | ||
} else { | ||
console.log("Skipping posting a tweet due to missing env variables"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters