-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweet-fetcher.js
38 lines (34 loc) · 929 Bytes
/
tweet-fetcher.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
/**
* Created by mario (https://github.com/hyprstack) on 03/10/2019.
*/
const {isNil} = require('lodash');
async function getTweets(twitterClient, twitterHandler, numberOfTweets) {
try {
const params = {
q: `to:${twitterHandler}`,
count: numberOfTweets,
include_entities: true,
result_type: 'recent'
};
const {statuses: tweets} = await twitterClient.get(`search/tweets.json`, params);
return tweets.map(tweet => {
const {
retweeted_status,
id_str,
text,
in_reply_to_status_id_str
} = tweet;
return {
tweetId: id_str,
tweetMessage: text,
isReTweetOf: !isNil(retweeted_status) ? {tweetId: retweeted_status.id_str} : null,
isResponseTo: !isNil(in_reply_to_status_id_str) ? {tweetId: in_reply_to_status_id_str} : null
}
});
} catch (e) {
throw e;
}
}
module.exports = {
getTweets
};