-
Notifications
You must be signed in to change notification settings - Fork 0
/
SocialMediaApi.js
58 lines (44 loc) · 1.38 KB
/
SocialMediaApi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// node SocialMediaApi.js
const Twit = require('twit');
const Discord = require('discord.js');
const express = require('express');
const { consumer_key, consumer_secret, access_token, access_token_secret, discordWebhookUrl } = require('./config.json');
const discordClient = new Discord.WebhookClient({ url: discordWebhookUrl });
const app = express();
const twitterClient = new Twit({
consumer_key,
consumer_secret,
access_token,
access_token_secret,
});
app.use(express.json());
app.post('/webhook/twitter', (req, res) => {
const tweet = req.body;
const tweetContent = tweet.text;
// Send the tweet content to Discord
discordClient.send(tweetContent);
res.sendStatus(200);
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});
// Get the latest tweet
function getLatestTweet() {
const params = {
screen_name: 'LightslicerGP', // Replace with your Twitter username
count: 1, // Number of tweets to retrieve
tweet_mode: 'extended',
};
twitterClient.get('statuses/user_timeline', params, (err, data) => {
if (err) {
console.error('Error retrieving latest tweet:', err);
return;
}
const latestTweet = data[0];
const tweetContent = latestTweet.full_text;
// Send the latest tweet content to Discord
discordClient.send(tweetContent);
});
}
// Call the function to get the latest tweet
getLatestTweet();