rettiwt-api 2.5.3 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/documentation.yml +2 -2
- package/.github/workflows/publish.yml +1 -1
- package/README.md +1 -0
- package/dist/commands/Tweet.js +72 -22
- package/dist/commands/Tweet.js.map +1 -1
- package/dist/helper/JsonUtils.d.ts +0 -7
- package/dist/helper/JsonUtils.js +1 -16
- package/dist/helper/JsonUtils.js.map +1 -1
- package/dist/models/data/Tweet.d.ts +1 -1
- package/dist/models/data/Tweet.js +1 -5
- package/dist/models/data/Tweet.js.map +1 -1
- package/dist/services/public/TweetService.d.ts +48 -1
- package/dist/services/public/TweetService.js +128 -2
- package/dist/services/public/TweetService.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/Tweet.ts +46 -23
- package/src/helper/JsonUtils.ts +0 -18
- package/src/models/data/Tweet.ts +2 -7
- package/src/services/public/TweetService.ts +86 -2
package/README.md
CHANGED
|
@@ -268,6 +268,7 @@ So far, the following operations are supported:
|
|
|
268
268
|
- [Retweeting/reposting a tweet](https://rishikant181.github.io/Rettiwt-API/classes/TweetService.html#retweet)
|
|
269
269
|
- [Getting the list of users who retweeted/reposted a given tweet](https://rishikant181.github.io/Rettiwt-API/classes/TweetService.html#retweeters)
|
|
270
270
|
- [Searching for the list of tweets that match a given filter](https://rishikant181.github.io/Rettiwt-API/classes/TweetService.html#search)
|
|
271
|
+
- [Streaming filtered tweets in pseudo-realtime](https://rishikant181.github.io/Rettiwt-API/classes/TweetService.html#stream)
|
|
271
272
|
- [Posting a new tweet](https://rishikant181.github.io/Rettiwt-API/classes/TweetService.html#tweet)
|
|
272
273
|
|
|
273
274
|
### Users
|
package/dist/commands/Tweet.js
CHANGED
|
@@ -35,6 +35,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
39
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
40
|
+
var m = o[Symbol.asyncIterator], i;
|
|
41
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
42
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
43
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
44
|
+
};
|
|
38
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
46
|
// PACKAGES
|
|
40
47
|
var commander_1 = require("commander");
|
|
@@ -74,14 +81,14 @@ function createTweetCommand(rettiwt) {
|
|
|
74
81
|
.description('Fetch the list of tweets that match the given filter options')
|
|
75
82
|
.argument('[count]', 'The number of tweets to fetch')
|
|
76
83
|
.argument('[cursor]', 'The cursor to the batch of tweets to fetch')
|
|
77
|
-
.option('-f, --from <string>',
|
|
78
|
-
.option('-t, --to <string>',
|
|
79
|
-
.option('-w, --words <string>',
|
|
84
|
+
.option('-f, --from <string>', 'Matches the tweets made by the comma-separated list of given users')
|
|
85
|
+
.option('-t, --to <string>', 'Matches the tweets made to the comma-separated list of given users')
|
|
86
|
+
.option('-w, --words <string>', 'Matches the tweets containing the given comma-separated list of words')
|
|
80
87
|
.option('-p, --phrase <string>', 'Matches the tweets containing the exact phrase')
|
|
81
|
-
.option('--optional-words <string>',
|
|
82
|
-
.option('--exclude-words <string>',
|
|
83
|
-
.option('-h, --hashtags <string>',
|
|
84
|
-
.option('-m, --mentions <string>',
|
|
88
|
+
.option('--optional-words <string>', 'Matches the tweets containing any of the given comma-separated list of words')
|
|
89
|
+
.option('--exclude-words <string>', 'Matches the tweets that do not contain any of the give comma-separated list of words')
|
|
90
|
+
.option('-h, --hashtags <string>', 'Matches the tweets containing the given comma-separated list of hashtags')
|
|
91
|
+
.option('-m, --mentions <string>', 'Matches the tweets that mention the given comma-separated list of usernames')
|
|
85
92
|
.option('-r, --min-replies <number>', 'Matches the tweets that have a minimum of given number of replies')
|
|
86
93
|
.option('-l, --min-likes <number>', 'Matches the tweets that have a minimum of given number of likes')
|
|
87
94
|
.option('-x, --min-retweets <number>', 'Matches the tweets that have a minimum of given number of retweets')
|
|
@@ -90,15 +97,55 @@ function createTweetCommand(rettiwt) {
|
|
|
90
97
|
.option('--exclude-replies', 'Matches the tweets that are not replies')
|
|
91
98
|
.option('-s, --start <string>', 'Matches the tweets made since the given date (valid date string)')
|
|
92
99
|
.option('-e, --end <string>', 'Matches the tweets made upto the given date (valid date string)')
|
|
100
|
+
.option('--stream', 'Stream the filtered tweets in pseudo-realtime')
|
|
101
|
+
.option('-i, --interval <number>', 'The polling interval (in ms) to use for streaming. Default is 60000')
|
|
93
102
|
.action(function (count, cursor, options) { return __awaiter(_this, void 0, void 0, function () {
|
|
94
|
-
var tweets;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
103
|
+
var _a, _b, _c, tweet_1, e_1_1, tweets;
|
|
104
|
+
var _d, e_1, _e, _f;
|
|
105
|
+
return __generator(this, function (_g) {
|
|
106
|
+
switch (_g.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
if (!(options === null || options === void 0 ? void 0 : options.stream)) return [3 /*break*/, 13];
|
|
109
|
+
_g.label = 1;
|
|
98
110
|
case 1:
|
|
99
|
-
|
|
111
|
+
_g.trys.push([1, 6, 7, 12]);
|
|
112
|
+
_a = true, _b = __asyncValues(rettiwt.tweet.stream(new TweetSearchOptions(options).toTweetFilter(), options === null || options === void 0 ? void 0 : options.interval));
|
|
113
|
+
_g.label = 2;
|
|
114
|
+
case 2: return [4 /*yield*/, _b.next()];
|
|
115
|
+
case 3:
|
|
116
|
+
if (!(_c = _g.sent(), _d = _c.done, !_d)) return [3 /*break*/, 5];
|
|
117
|
+
_f = _c.value;
|
|
118
|
+
_a = false;
|
|
119
|
+
tweet_1 = _f;
|
|
120
|
+
(0, CliUtils_1.output)(tweet_1);
|
|
121
|
+
_g.label = 4;
|
|
122
|
+
case 4:
|
|
123
|
+
_a = true;
|
|
124
|
+
return [3 /*break*/, 2];
|
|
125
|
+
case 5: return [3 /*break*/, 12];
|
|
126
|
+
case 6:
|
|
127
|
+
e_1_1 = _g.sent();
|
|
128
|
+
e_1 = { error: e_1_1 };
|
|
129
|
+
return [3 /*break*/, 12];
|
|
130
|
+
case 7:
|
|
131
|
+
_g.trys.push([7, , 10, 11]);
|
|
132
|
+
if (!(!_a && !_d && (_e = _b.return))) return [3 /*break*/, 9];
|
|
133
|
+
return [4 /*yield*/, _e.call(_b)];
|
|
134
|
+
case 8:
|
|
135
|
+
_g.sent();
|
|
136
|
+
_g.label = 9;
|
|
137
|
+
case 9: return [3 /*break*/, 11];
|
|
138
|
+
case 10:
|
|
139
|
+
if (e_1) throw e_1.error;
|
|
140
|
+
return [7 /*endfinally*/];
|
|
141
|
+
case 11: return [7 /*endfinally*/];
|
|
142
|
+
case 12: return [3 /*break*/, 15];
|
|
143
|
+
case 13: return [4 /*yield*/, rettiwt.tweet.search(new TweetSearchOptions(options).toTweetFilter(), count ? parseInt(count) : undefined, cursor)];
|
|
144
|
+
case 14:
|
|
145
|
+
tweets = _g.sent();
|
|
100
146
|
(0, CliUtils_1.output)(tweets);
|
|
101
|
-
|
|
147
|
+
_g.label = 15;
|
|
148
|
+
case 15: return [2 /*return*/];
|
|
102
149
|
}
|
|
103
150
|
});
|
|
104
151
|
}); });
|
|
@@ -164,12 +211,13 @@ function createTweetCommand(rettiwt) {
|
|
|
164
211
|
.command('post')
|
|
165
212
|
.description('Post a tweet (text only)')
|
|
166
213
|
.argument('<text>', 'The text to post as a tweet')
|
|
167
|
-
.option('-m, --media [string]',
|
|
214
|
+
.option('-m, --media [string]', 'Comma-separated list of path(s) to the media item(s) to be posted')
|
|
215
|
+
.option('-r, --reply [string]', 'The id of the tweet to which the reply is to be made, if the tweet is to be a reply')
|
|
168
216
|
.action(function (text, options) { return __awaiter(_this, void 0, void 0, function () {
|
|
169
217
|
var result;
|
|
170
218
|
return __generator(this, function (_a) {
|
|
171
219
|
switch (_a.label) {
|
|
172
|
-
case 0: return [4 /*yield*/, rettiwt.tweet.tweet(text, (options === null || options === void 0 ? void 0 : options.media) ? options === null || options === void 0 ? void 0 : options.media.split('
|
|
220
|
+
case 0: return [4 /*yield*/, rettiwt.tweet.tweet(text, (options === null || options === void 0 ? void 0 : options.media) ? options === null || options === void 0 ? void 0 : options.media.split(',').map(function (item) { return ({ path: item }); }) : undefined, options === null || options === void 0 ? void 0 : options.reply)];
|
|
173
221
|
case 1:
|
|
174
222
|
result = _a.sent();
|
|
175
223
|
(0, CliUtils_1.output)(result);
|
|
@@ -243,6 +291,8 @@ var TweetSearchOptions = /** @class */ (function () {
|
|
|
243
291
|
this.excludeReplies = options === null || options === void 0 ? void 0 : options.excludeReplies;
|
|
244
292
|
this.start = options === null || options === void 0 ? void 0 : options.start;
|
|
245
293
|
this.end = options === null || options === void 0 ? void 0 : options.end;
|
|
294
|
+
this.stream = options === null || options === void 0 ? void 0 : options.stream;
|
|
295
|
+
this.interval = options === null || options === void 0 ? void 0 : options.interval;
|
|
246
296
|
}
|
|
247
297
|
/**
|
|
248
298
|
* Converts the filter options to a format recognizable by rettiwt-api.
|
|
@@ -251,14 +301,14 @@ var TweetSearchOptions = /** @class */ (function () {
|
|
|
251
301
|
*/
|
|
252
302
|
TweetSearchOptions.prototype.toTweetFilter = function () {
|
|
253
303
|
return new rettiwt_core_1.TweetFilter({
|
|
254
|
-
fromUsers: this.from ? this.from.split('
|
|
255
|
-
toUsers: this.to ? this.to.split('
|
|
256
|
-
includeWords: this.words ? this.words.split('
|
|
304
|
+
fromUsers: this.from ? this.from.split(',') : undefined,
|
|
305
|
+
toUsers: this.to ? this.to.split(',') : undefined,
|
|
306
|
+
includeWords: this.words ? this.words.split(',') : undefined,
|
|
257
307
|
includePhrase: this.phrase,
|
|
258
|
-
optionalWords: this.optionalWords ? this.optionalWords.split('
|
|
259
|
-
excludeWords: this.excludeWords ? this.excludeWords.split('
|
|
260
|
-
hashtags: this.hashtags ? this.hashtags.split('
|
|
261
|
-
mentions: this.mentions ? this.mentions.split('
|
|
308
|
+
optionalWords: this.optionalWords ? this.optionalWords.split(',') : undefined,
|
|
309
|
+
excludeWords: this.excludeWords ? this.excludeWords.split(',') : undefined,
|
|
310
|
+
hashtags: this.hashtags ? this.hashtags.split(',') : undefined,
|
|
311
|
+
mentions: this.mentions ? this.mentions.split(',') : undefined,
|
|
262
312
|
minReplies: this.minReplies,
|
|
263
313
|
minLikes: this.minLikes,
|
|
264
314
|
minRetweets: this.minRetweets,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tweet.js","sourceRoot":"","sources":["../../src/commands/Tweet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Tweet.js","sourceRoot":"","sources":["../../src/commands/Tweet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,WAAW;AACX,uCAAmD;AAEnD,6CAA2C;AAE3C,UAAU;AACV,+CAA4C;AAE5C;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,OAAgB;IAA5C,iBAgJC;IA/IA,+BAA+B;IAC/B,IAAM,KAAK,GAAG,IAAA,yBAAa,EAAC,OAAO,CAAC,CAAC,WAAW,CAAC,qCAAqC,CAAC,CAAC;IAExF,UAAU;IACV,KAAK;SACH,OAAO,CAAC,SAAS,CAAC;SAClB,WAAW,CAAC,8CAA8C,CAAC;SAC3D,QAAQ,CAAC,MAAM,EAAE,qDAAqD,CAAC;SACvE,MAAM,CAAC,UAAO,EAAU;;;;wBACR,qBAAM,OAAO,CAAC,KAAK,CAAC,O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QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;YAC9D,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,CAAC,IAAI,CAAC,YAAY;YACzB,OAAO,EAAE,CAAC,IAAI,CAAC,cAAc;YAC7B,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS;YACxD,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;SAClD,CAAC,CAAC;IACJ,CAAC;IACF,yBAAC;AAAD,CAAC,AAvED,IAuEC;AAED,kBAAe,kBAAkB,CAAC"}
|
|
@@ -9,13 +9,6 @@
|
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
11
|
export declare function findByFilter<T>(data: NonNullable<unknown>, key: string, value: string): T[];
|
|
12
|
-
/**
|
|
13
|
-
* @param text - The text to be normalized.
|
|
14
|
-
* @returns The text after being formatted to remove unnecessary characters.
|
|
15
|
-
*
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
export declare function normalizeText(text: string): string;
|
|
19
12
|
/**
|
|
20
13
|
* Searches for the key which has the given value in the given object.
|
|
21
14
|
*
|
package/dist/helper/JsonUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findKeyByValue = exports.
|
|
3
|
+
exports.findKeyByValue = exports.findByFilter = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Search for all the sub-objects (even deep-nested ones) that have the given key-value pair(filter).
|
|
6
6
|
*
|
|
@@ -47,21 +47,6 @@ function findByFilter(data, key, value) {
|
|
|
47
47
|
return res;
|
|
48
48
|
}
|
|
49
49
|
exports.findByFilter = findByFilter;
|
|
50
|
-
/**
|
|
51
|
-
* @param text - The text to be normalized.
|
|
52
|
-
* @returns The text after being formatted to remove unnecessary characters.
|
|
53
|
-
*
|
|
54
|
-
* @internal
|
|
55
|
-
*/
|
|
56
|
-
function normalizeText(text) {
|
|
57
|
-
var normalizedText = ''; // To store the normalized text
|
|
58
|
-
// Removing unnecessary full stops, and other characters
|
|
59
|
-
normalizedText = text.replace(/\n/g, '.').replace(/[.]+[\s+.\s+]+/g, '. ');
|
|
60
|
-
// Adding full-stop to the end if does not exist already
|
|
61
|
-
normalizedText = normalizedText.endsWith('.') ? normalizedText : normalizedText + '.';
|
|
62
|
-
return normalizedText;
|
|
63
|
-
}
|
|
64
|
-
exports.normalizeText = normalizeText;
|
|
65
50
|
/**
|
|
66
51
|
* Searches for the key which has the given value in the given object.
|
|
67
52
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonUtils.js","sourceRoot":"","sources":["../../src/helper/JsonUtils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAAI,IAA0B,EAAE,GAAW,EAAE,KAAa;IACrF;;OAEG;IACH,IAAI,GAAG,GAAQ,EAAE,CAAC;IAElB;;OAEG;IACH,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACxB;;;;;WAKG;QACH,GAAG,GAAG,GAAG,CAAC,MAAM,OAAV,GAAG,EAAW,IAAI,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,YAAY,CAAI,IAA4B,EAAE,GAAG,EAAE,KAAK,CAAC,EAAzD,CAAyD,CAAC,CAAC,CAAC;KACnG;IACD,2BAA2B;SACtB,IA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C/E,GAAG,CAAC,IAAI,CAAC,IAAS,CAAC,CAAC;SACpB;QAED;;WAEG;QACH,KAAoB,UAAoB,EAApB,KAAA,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAApB,cAAoB,EAApB,IAAoB,EAAE;YAA/B,IAAA,WAAK,EAAF,CAAC,QAAA;YACd,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAI,CAAyB,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;SACzE;KACD;IAED,OAAO,GAAG,CAAC;AACZ,CAAC;AApCD,oCAoCC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,IAA0B,EAAE,KAAa;IACvE,wDAAwD;IACxD,IAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,UAAC,EAAK;YAAF,CAAC,QAAA;QAAM,OAAA,CAAC,IAAI,KAAK;IAAV,CAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAErE,sBAAsB;IACtB,IAAI,MAAM,EAAE;QACX,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;KACjB;IACD,uBAAuB;SAClB;QACJ,OAAO,SAAS,CAAC;KACjB;AACF,CAAC;AAZD,wCAYC"}
|
|
@@ -20,7 +20,7 @@ export declare class Tweet {
|
|
|
20
20
|
quoted: string;
|
|
21
21
|
/** The full text content of the tweet. */
|
|
22
22
|
fullText: string;
|
|
23
|
-
/** The rest id of the
|
|
23
|
+
/** The rest id of the tweet to which the tweet is a reply. */
|
|
24
24
|
replyTo: string;
|
|
25
25
|
/** The language in which the tweet is written. */
|
|
26
26
|
lang: string;
|
|
@@ -5,8 +5,6 @@ exports.TweetMedia = exports.TweetEntities = exports.Tweet = void 0;
|
|
|
5
5
|
var rettiwt_core_1 = require("rettiwt-core");
|
|
6
6
|
// MODELS
|
|
7
7
|
var User_1 = require("./User");
|
|
8
|
-
// PARSERS
|
|
9
|
-
var JsonUtils_1 = require("../../helper/JsonUtils");
|
|
10
8
|
/**
|
|
11
9
|
* The details of a single Tweet.
|
|
12
10
|
*
|
|
@@ -26,9 +24,7 @@ var Tweet = /** @class */ (function () {
|
|
|
26
24
|
this.entities = new TweetEntities(tweet.legacy.entities);
|
|
27
25
|
this.media = (_b = (_a = tweet.legacy.extended_entities) === null || _a === void 0 ? void 0 : _a.media) === null || _b === void 0 ? void 0 : _b.map(function (media) { return new TweetMedia(media); });
|
|
28
26
|
this.quoted = tweet.legacy.quoted_status_id_str;
|
|
29
|
-
this.fullText = tweet.note_tweet
|
|
30
|
-
? tweet.note_tweet.note_tweet_results.result.text
|
|
31
|
-
: (0, JsonUtils_1.normalizeText)(tweet.legacy.full_text);
|
|
27
|
+
this.fullText = tweet.note_tweet ? tweet.note_tweet.note_tweet_results.result.text : tweet.legacy.full_text;
|
|
32
28
|
this.replyTo = tweet.legacy.in_reply_to_status_id_str;
|
|
33
29
|
this.lang = tweet.legacy.lang;
|
|
34
30
|
this.quoteCount = tweet.legacy.quote_count;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tweet.js","sourceRoot":"","sources":["../../../src/models/data/Tweet.ts"],"names":[],"mappings":";;;AAAA,WAAW;AACX,6CAKsB;AAEtB,SAAS;AACT,+BAA8B;AAE9B
|
|
1
|
+
{"version":3,"file":"Tweet.js","sourceRoot":"","sources":["../../../src/models/data/Tweet.ts"],"names":[],"mappings":";;;AAAA,WAAW;AACX,6CAKsB;AAEtB,SAAS;AACT,+BAA8B;AAE9B;;;;GAIG;AACH;IA8CC;;;;OAIG;IACH,eAAmB,KAAgB;;QAClC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,IAAI,WAAI,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QACxD,IAAI,CAAC,Q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ACnB,IAAI,KAAK,CAAC,IAAI,IAAI,yBAAU,CAAC,GAAG,EAAE;YACtC,IAAI,CAAC,GAAG,GAAG,MAAA,KAAK,CAAC,UAAU,0CAAE,QAAQ,CAAC,CAAC,EAAE,GAAa,CAAC;SACvD;QACD,0BAA0B;aACrB;YACJ,2CAA2C;YAC3C,IAAI,aAAW,GAAW,CAAC,CAAC;YAE5B;;eAEG;YACH,MAAA,KAAK,CAAC,UAAU,0CAAE,QAAQ,CAAC,OAAO,CAAC,UAAC,OAAO;gBAC1C,IAAI,OAAO,CAAC,OAAO,GAAG,aAAW,EAAE;oBAClC,aAAW,GAAG,OAAO,CAAC,OAAO,CAAC;oBAC9B,KAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;iBACvB;YACF,CAAC,CAAC,CAAC;SACH;IACF,CAAC;IACF,iBAAC;AAAD,CAAC,AAvCD,IAuCC;AAvCY,gCAAU"}
|
|
@@ -73,6 +73,36 @@ export declare class TweetService extends FetcherService {
|
|
|
73
73
|
* @public
|
|
74
74
|
*/
|
|
75
75
|
search(query: TweetFilter, count?: number, cursor?: string): Promise<CursoredData<Tweet>>;
|
|
76
|
+
/**
|
|
77
|
+
* Stream tweets in pseudo real-time using a filter.
|
|
78
|
+
*
|
|
79
|
+
* @param filter - The filter to be used for searching the tweets.
|
|
80
|
+
* @param pollingIntervalMs - The interval in milliseconds to poll for new tweets. Default interval is 60000 ms.
|
|
81
|
+
* @returns An async generator that yields matching tweets as they are found.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```
|
|
85
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
86
|
+
*
|
|
87
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
88
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
89
|
+
*
|
|
90
|
+
* // Streaming all upcoming tweets from user 'user1'
|
|
91
|
+
* async () => {
|
|
92
|
+
* try {
|
|
93
|
+
* for await (const tweet of rettiwt.tweet.stream({ fromUsers: ['user1'] }, 1000)) {
|
|
94
|
+
* console.log(tweet.fullText);
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
* catch (err) {
|
|
98
|
+
* console.log(err);
|
|
99
|
+
* }
|
|
100
|
+
* }();
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
stream(filter: TweetFilter, pollingInterval?: number): AsyncGenerator<Tweet>;
|
|
76
106
|
/**
|
|
77
107
|
* Get the tweets from the tweet list with the given id.
|
|
78
108
|
*
|
|
@@ -198,9 +228,26 @@ export declare class TweetService extends FetcherService {
|
|
|
198
228
|
* });
|
|
199
229
|
* ```
|
|
200
230
|
*
|
|
231
|
+
* @example Posting a reply to a tweet
|
|
232
|
+
* ```
|
|
233
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
234
|
+
*
|
|
235
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
236
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
237
|
+
*
|
|
238
|
+
* // Posting a simple text reply, to a tweet with id "1234567890"
|
|
239
|
+
* rettiwt.tweet.tweet('Hello!', undefined, "1234567890")
|
|
240
|
+
* .then(res => {
|
|
241
|
+
* console.log(res);
|
|
242
|
+
* })
|
|
243
|
+
* .catch(err => {
|
|
244
|
+
* console.log(err);
|
|
245
|
+
* });
|
|
246
|
+
* ```
|
|
247
|
+
*
|
|
201
248
|
* @public
|
|
202
249
|
*/
|
|
203
|
-
tweet(text: string, media?: TweetMediaArgs[]): Promise<boolean>;
|
|
250
|
+
tweet(text: string, media?: TweetMediaArgs[], replyTo?: string): Promise<boolean>;
|
|
204
251
|
/**
|
|
205
252
|
* Favorite the tweet with the given id.
|
|
206
253
|
*
|
|
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
17
28
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
29
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
30
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -50,6 +61,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
50
61
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
62
|
}
|
|
52
63
|
};
|
|
64
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
65
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
66
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
67
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
68
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
69
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
70
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
71
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
72
|
+
function fulfill(value) { resume("next", value); }
|
|
73
|
+
function reject(value) { resume("throw", value); }
|
|
74
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
75
|
+
};
|
|
53
76
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
77
|
exports.TweetService = void 0;
|
|
55
78
|
// PACKAGES
|
|
@@ -158,6 +181,90 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
158
181
|
});
|
|
159
182
|
});
|
|
160
183
|
};
|
|
184
|
+
/**
|
|
185
|
+
* Stream tweets in pseudo real-time using a filter.
|
|
186
|
+
*
|
|
187
|
+
* @param filter - The filter to be used for searching the tweets.
|
|
188
|
+
* @param pollingIntervalMs - The interval in milliseconds to poll for new tweets. Default interval is 60000 ms.
|
|
189
|
+
* @returns An async generator that yields matching tweets as they are found.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```
|
|
193
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
194
|
+
*
|
|
195
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
196
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
197
|
+
*
|
|
198
|
+
* // Streaming all upcoming tweets from user 'user1'
|
|
199
|
+
* async () => {
|
|
200
|
+
* try {
|
|
201
|
+
* for await (const tweet of rettiwt.tweet.stream({ fromUsers: ['user1'] }, 1000)) {
|
|
202
|
+
* console.log(tweet.fullText);
|
|
203
|
+
* }
|
|
204
|
+
* }
|
|
205
|
+
* catch (err) {
|
|
206
|
+
* console.log(err);
|
|
207
|
+
* }
|
|
208
|
+
* }();
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @public
|
|
212
|
+
*/
|
|
213
|
+
TweetService.prototype.stream = function (filter, pollingInterval) {
|
|
214
|
+
if (pollingInterval === void 0) { pollingInterval = 60000; }
|
|
215
|
+
return __asyncGenerator(this, arguments, function stream_1() {
|
|
216
|
+
var startDate, cursor, sinceId, nextSinceId, tweets, _i, _a, tweet;
|
|
217
|
+
return __generator(this, function (_b) {
|
|
218
|
+
switch (_b.label) {
|
|
219
|
+
case 0:
|
|
220
|
+
startDate = new Date();
|
|
221
|
+
cursor = undefined;
|
|
222
|
+
sinceId = undefined;
|
|
223
|
+
nextSinceId = undefined;
|
|
224
|
+
_b.label = 1;
|
|
225
|
+
case 1:
|
|
226
|
+
if (!true) return [3 /*break*/, 9];
|
|
227
|
+
// Pause execution for the specified polling interval before proceeding to the next iteration
|
|
228
|
+
return [4 /*yield*/, __await(new Promise(function (resolve) { return setTimeout(resolve, pollingInterval); }))];
|
|
229
|
+
case 2:
|
|
230
|
+
// Pause execution for the specified polling interval before proceeding to the next iteration
|
|
231
|
+
_b.sent();
|
|
232
|
+
return [4 /*yield*/, __await(this.search(__assign(__assign({}, filter), { startDate: startDate, sinceId: sinceId }), undefined, cursor))];
|
|
233
|
+
case 3:
|
|
234
|
+
tweets = _b.sent();
|
|
235
|
+
_i = 0, _a = tweets.list;
|
|
236
|
+
_b.label = 4;
|
|
237
|
+
case 4:
|
|
238
|
+
if (!(_i < _a.length)) return [3 /*break*/, 8];
|
|
239
|
+
tweet = _a[_i];
|
|
240
|
+
return [4 /*yield*/, __await(tweet)];
|
|
241
|
+
case 5: return [4 /*yield*/, _b.sent()];
|
|
242
|
+
case 6:
|
|
243
|
+
_b.sent();
|
|
244
|
+
_b.label = 7;
|
|
245
|
+
case 7:
|
|
246
|
+
_i++;
|
|
247
|
+
return [3 /*break*/, 4];
|
|
248
|
+
case 8:
|
|
249
|
+
// Store the most recent tweet ID from this batch
|
|
250
|
+
if (tweets.list.length > 0 && cursor === undefined) {
|
|
251
|
+
nextSinceId = tweets.list[0].id;
|
|
252
|
+
}
|
|
253
|
+
// If there are more tweets to fetch, adjust the cursor value
|
|
254
|
+
if (tweets.list.length > 0 && tweets.next) {
|
|
255
|
+
cursor = tweets.next.value;
|
|
256
|
+
}
|
|
257
|
+
// Else, start the next iteration from this batch's most recent tweet
|
|
258
|
+
else {
|
|
259
|
+
sinceId = nextSinceId;
|
|
260
|
+
cursor = undefined;
|
|
261
|
+
}
|
|
262
|
+
return [3 /*break*/, 1];
|
|
263
|
+
case 9: return [2 /*return*/];
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
};
|
|
161
268
|
/**
|
|
162
269
|
* Get the tweets from the tweet list with the given id.
|
|
163
270
|
*
|
|
@@ -333,9 +440,26 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
333
440
|
* });
|
|
334
441
|
* ```
|
|
335
442
|
*
|
|
443
|
+
* @example Posting a reply to a tweet
|
|
444
|
+
* ```
|
|
445
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
446
|
+
*
|
|
447
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
448
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
449
|
+
*
|
|
450
|
+
* // Posting a simple text reply, to a tweet with id "1234567890"
|
|
451
|
+
* rettiwt.tweet.tweet('Hello!', undefined, "1234567890")
|
|
452
|
+
* .then(res => {
|
|
453
|
+
* console.log(res);
|
|
454
|
+
* })
|
|
455
|
+
* .catch(err => {
|
|
456
|
+
* console.log(err);
|
|
457
|
+
* });
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
336
460
|
* @public
|
|
337
461
|
*/
|
|
338
|
-
TweetService.prototype.tweet = function (text, media) {
|
|
462
|
+
TweetService.prototype.tweet = function (text, media, replyTo) {
|
|
339
463
|
return __awaiter(this, void 0, void 0, function () {
|
|
340
464
|
var tweet, uploadedMedia, _i, _a, item, id, data;
|
|
341
465
|
return __generator(this, function (_b) {
|
|
@@ -358,7 +482,9 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
358
482
|
case 3:
|
|
359
483
|
_i++;
|
|
360
484
|
return [3 /*break*/, 1];
|
|
361
|
-
case 4: return [4 /*yield*/, this.post(rettiwt_core_1.EResourceType.CREATE_TWEET, {
|
|
485
|
+
case 4: return [4 /*yield*/, this.post(rettiwt_core_1.EResourceType.CREATE_TWEET, {
|
|
486
|
+
tweet: { text: text, media: uploadedMedia, replyTo: replyTo },
|
|
487
|
+
})];
|
|
362
488
|
case 5:
|
|
363
489
|
data = _b.sent();
|
|
364
490
|
return [2 /*return*/, data];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TweetService.js","sourceRoot":"","sources":["../../../src/services/public/TweetService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TweetService.js","sourceRoot":"","sources":["../../../src/services/public/TweetService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,WAAW;AACX,6CAAqE;AAErE,WAAW;AACX,6DAA4D;AAS5D,yDAAwE;AAExE;;;;GAIG;AACH;IAAkC,gCAAc;IAC/C;;;;OAIG;IACH,sBAAmB,MAAuB;eACzC,kBAAM,MAAM,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACU,8BAAO,GAApB,UAAqB,EAAU;;;;;4BAEjB,qBAAM,IAAI,CAAC,KAAK,CAAQ,4BAAa,CAAC,aAAa,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAA;;wBAAvE,IAAI,GAAG,SAAgE;wBAE7E,sBAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAC;;;;KACpB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACU,6BAAM,GAAnB,UAAoB,KAAkB,EAAE,KAAc,EAAE,MAAe;;;;;4BAEzD,qBAAM,IAAI,CAAC,KAAK,CAAQ,4BAAa,CAAC,YAAY,EAAE;4BAChE,MAAM,EAAE,KAAK;4BACb,KAAK,EAAE,KAAK;4BACZ,MAAM,EAAE,MAAM;yBACd,CAAC,EAAA;;wBAJI,IAAI,GAAG,SAIX;wBAEF,oDAAoD;wBACpD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAA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CAAC,cAAc,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAA;;wBAArE,IAAI,GAAG,SAA8D;wBAE3E,sBAAO,IAAI,EAAC;;;;KACZ;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACU,8BAAO,GAApB,UAAqB,OAAe;;;;;4BAEtB,qBAAM,IAAI,CAAC,IAAI,CAAC,4BAAa,CAAC,cAAc,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAA;;wBAArE,IAAI,GAAG,SAA8D;wBAE3E,sBAAO,IAAI,EAAC;;;;KACZ;IACF,mBAAC;AAAD,CAAC,AAhaD,CAAkC,+BAAc,GAga/C;AAhaY,oCAAY"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rettiwt-api",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"description": "An API for fetching data from TwitterAPI, without any rate limits!",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"commander": "11.1.0",
|
|
35
35
|
"https-proxy-agent": "7.0.2",
|
|
36
36
|
"rettiwt-auth": "2.1.0",
|
|
37
|
-
"rettiwt-core": "3.
|
|
37
|
+
"rettiwt-core": "3.4.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "20.4.1",
|
package/src/commands/Tweet.ts
CHANGED
|
@@ -32,22 +32,22 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
|
|
|
32
32
|
.description('Fetch the list of tweets that match the given filter options')
|
|
33
33
|
.argument('[count]', 'The number of tweets to fetch')
|
|
34
34
|
.argument('[cursor]', 'The cursor to the batch of tweets to fetch')
|
|
35
|
-
.option('-f, --from <string>',
|
|
36
|
-
.option('-t, --to <string>',
|
|
37
|
-
.option('-w, --words <string>',
|
|
35
|
+
.option('-f, --from <string>', 'Matches the tweets made by the comma-separated list of given users')
|
|
36
|
+
.option('-t, --to <string>', 'Matches the tweets made to the comma-separated list of given users')
|
|
37
|
+
.option('-w, --words <string>', 'Matches the tweets containing the given comma-separated list of words')
|
|
38
38
|
.option('-p, --phrase <string>', 'Matches the tweets containing the exact phrase')
|
|
39
39
|
.option(
|
|
40
40
|
'--optional-words <string>',
|
|
41
|
-
|
|
41
|
+
'Matches the tweets containing any of the given comma-separated list of words',
|
|
42
42
|
)
|
|
43
43
|
.option(
|
|
44
44
|
'--exclude-words <string>',
|
|
45
|
-
|
|
45
|
+
'Matches the tweets that do not contain any of the give comma-separated list of words',
|
|
46
46
|
)
|
|
47
|
-
.option('-h, --hashtags <string>',
|
|
47
|
+
.option('-h, --hashtags <string>', 'Matches the tweets containing the given comma-separated list of hashtags')
|
|
48
48
|
.option(
|
|
49
49
|
'-m, --mentions <string>',
|
|
50
|
-
|
|
50
|
+
'Matches the tweets that mention the given comma-separated list of usernames',
|
|
51
51
|
)
|
|
52
52
|
.option('-r, --min-replies <number>', 'Matches the tweets that have a minimum of given number of replies')
|
|
53
53
|
.option('-l, --min-likes <number>', 'Matches the tweets that have a minimum of given number of likes')
|
|
@@ -57,13 +57,27 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
|
|
|
57
57
|
.option('--exclude-replies', 'Matches the tweets that are not replies')
|
|
58
58
|
.option('-s, --start <string>', 'Matches the tweets made since the given date (valid date string)')
|
|
59
59
|
.option('-e, --end <string>', 'Matches the tweets made upto the given date (valid date string)')
|
|
60
|
+
.option('--stream', 'Stream the filtered tweets in pseudo-realtime')
|
|
61
|
+
.option('-i, --interval <number>', 'The polling interval (in ms) to use for streaming. Default is 60000')
|
|
60
62
|
.action(async (count?: string, cursor?: string, options?: TweetSearchOptions) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
// If search results are to be streamed
|
|
64
|
+
if (options?.stream) {
|
|
65
|
+
for await (const tweet of rettiwt.tweet.stream(
|
|
66
|
+
new TweetSearchOptions(options).toTweetFilter(),
|
|
67
|
+
options?.interval,
|
|
68
|
+
)) {
|
|
69
|
+
output(tweet);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// If a normal search is to be done
|
|
73
|
+
else {
|
|
74
|
+
const tweets = await rettiwt.tweet.search(
|
|
75
|
+
new TweetSearchOptions(options).toTweetFilter(),
|
|
76
|
+
count ? parseInt(count) : undefined,
|
|
77
|
+
cursor,
|
|
78
|
+
);
|
|
79
|
+
output(tweets);
|
|
80
|
+
}
|
|
67
81
|
});
|
|
68
82
|
|
|
69
83
|
// List
|
|
@@ -107,11 +121,16 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
|
|
|
107
121
|
.command('post')
|
|
108
122
|
.description('Post a tweet (text only)')
|
|
109
123
|
.argument('<text>', 'The text to post as a tweet')
|
|
110
|
-
.option('-m, --media [string]',
|
|
111
|
-
.
|
|
124
|
+
.option('-m, --media [string]', 'Comma-separated list of path(s) to the media item(s) to be posted')
|
|
125
|
+
.option(
|
|
126
|
+
'-r, --reply [string]',
|
|
127
|
+
'The id of the tweet to which the reply is to be made, if the tweet is to be a reply',
|
|
128
|
+
)
|
|
129
|
+
.action(async (text: string, options?: { media?: string; reply?: string }) => {
|
|
112
130
|
const result = await rettiwt.tweet.tweet(
|
|
113
131
|
text,
|
|
114
|
-
options?.media ? options?.media.split('
|
|
132
|
+
options?.media ? options?.media.split(',').map((item) => ({ path: item })) : undefined,
|
|
133
|
+
options?.reply,
|
|
115
134
|
);
|
|
116
135
|
output(result);
|
|
117
136
|
});
|
|
@@ -161,6 +180,8 @@ class TweetSearchOptions {
|
|
|
161
180
|
public excludeReplies?: boolean = false;
|
|
162
181
|
public start?: string;
|
|
163
182
|
public end?: string;
|
|
183
|
+
public stream?: boolean;
|
|
184
|
+
public interval?: number;
|
|
164
185
|
|
|
165
186
|
/**
|
|
166
187
|
* Initializes a new object from the given options.
|
|
@@ -184,6 +205,8 @@ class TweetSearchOptions {
|
|
|
184
205
|
this.excludeReplies = options?.excludeReplies;
|
|
185
206
|
this.start = options?.start;
|
|
186
207
|
this.end = options?.end;
|
|
208
|
+
this.stream = options?.stream;
|
|
209
|
+
this.interval = options?.interval;
|
|
187
210
|
}
|
|
188
211
|
|
|
189
212
|
/**
|
|
@@ -193,14 +216,14 @@ class TweetSearchOptions {
|
|
|
193
216
|
*/
|
|
194
217
|
public toTweetFilter(): TweetFilter {
|
|
195
218
|
return new TweetFilter({
|
|
196
|
-
fromUsers: this.from ? this.from.split('
|
|
197
|
-
toUsers: this.to ? this.to.split('
|
|
198
|
-
includeWords: this.words ? this.words.split('
|
|
219
|
+
fromUsers: this.from ? this.from.split(',') : undefined,
|
|
220
|
+
toUsers: this.to ? this.to.split(',') : undefined,
|
|
221
|
+
includeWords: this.words ? this.words.split(',') : undefined,
|
|
199
222
|
includePhrase: this.phrase,
|
|
200
|
-
optionalWords: this.optionalWords ? this.optionalWords.split('
|
|
201
|
-
excludeWords: this.excludeWords ? this.excludeWords.split('
|
|
202
|
-
hashtags: this.hashtags ? this.hashtags.split('
|
|
203
|
-
mentions: this.mentions ? this.mentions.split('
|
|
223
|
+
optionalWords: this.optionalWords ? this.optionalWords.split(',') : undefined,
|
|
224
|
+
excludeWords: this.excludeWords ? this.excludeWords.split(',') : undefined,
|
|
225
|
+
hashtags: this.hashtags ? this.hashtags.split(',') : undefined,
|
|
226
|
+
mentions: this.mentions ? this.mentions.split(',') : undefined,
|
|
204
227
|
minReplies: this.minReplies,
|
|
205
228
|
minLikes: this.minLikes,
|
|
206
229
|
minRetweets: this.minRetweets,
|
package/src/helper/JsonUtils.ts
CHANGED
|
@@ -46,24 +46,6 @@ export function findByFilter<T>(data: NonNullable<unknown>, key: string, value:
|
|
|
46
46
|
return res;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
/**
|
|
50
|
-
* @param text - The text to be normalized.
|
|
51
|
-
* @returns The text after being formatted to remove unnecessary characters.
|
|
52
|
-
*
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
export function normalizeText(text: string): string {
|
|
56
|
-
let normalizedText: string = ''; // To store the normalized text
|
|
57
|
-
|
|
58
|
-
// Removing unnecessary full stops, and other characters
|
|
59
|
-
normalizedText = text.replace(/\n/g, '.').replace(/[.]+[\s+.\s+]+/g, '. ');
|
|
60
|
-
|
|
61
|
-
// Adding full-stop to the end if does not exist already
|
|
62
|
-
normalizedText = normalizedText.endsWith('.') ? normalizedText : normalizedText + '.';
|
|
63
|
-
|
|
64
|
-
return normalizedText;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
49
|
/**
|
|
68
50
|
* Searches for the key which has the given value in the given object.
|
|
69
51
|
*
|
package/src/models/data/Tweet.ts
CHANGED
|
@@ -9,9 +9,6 @@ import {
|
|
|
9
9
|
// MODELS
|
|
10
10
|
import { User } from './User';
|
|
11
11
|
|
|
12
|
-
// PARSERS
|
|
13
|
-
import { normalizeText } from '../../helper/JsonUtils';
|
|
14
|
-
|
|
15
12
|
/**
|
|
16
13
|
* The details of a single Tweet.
|
|
17
14
|
*
|
|
@@ -39,7 +36,7 @@ export class Tweet {
|
|
|
39
36
|
/** The full text content of the tweet. */
|
|
40
37
|
public fullText: string;
|
|
41
38
|
|
|
42
|
-
/** The rest id of the
|
|
39
|
+
/** The rest id of the tweet to which the tweet is a reply. */
|
|
43
40
|
public replyTo: string;
|
|
44
41
|
|
|
45
42
|
/** The language in which the tweet is written. */
|
|
@@ -75,9 +72,7 @@ export class Tweet {
|
|
|
75
72
|
this.entities = new TweetEntities(tweet.legacy.entities);
|
|
76
73
|
this.media = tweet.legacy.extended_entities?.media?.map((media) => new TweetMedia(media));
|
|
77
74
|
this.quoted = tweet.legacy.quoted_status_id_str;
|
|
78
|
-
this.fullText = tweet.note_tweet
|
|
79
|
-
? tweet.note_tweet.note_tweet_results.result.text
|
|
80
|
-
: normalizeText(tweet.legacy.full_text);
|
|
75
|
+
this.fullText = tweet.note_tweet ? tweet.note_tweet.note_tweet_results.result.text : tweet.legacy.full_text;
|
|
81
76
|
this.replyTo = tweet.legacy.in_reply_to_status_id_str;
|
|
82
77
|
this.lang = tweet.legacy.lang;
|
|
83
78
|
this.quoteCount = tweet.legacy.quote_count;
|
|
@@ -103,6 +103,71 @@ export class TweetService extends FetcherService {
|
|
|
103
103
|
return data;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Stream tweets in pseudo real-time using a filter.
|
|
108
|
+
*
|
|
109
|
+
* @param filter - The filter to be used for searching the tweets.
|
|
110
|
+
* @param pollingIntervalMs - The interval in milliseconds to poll for new tweets. Default interval is 60000 ms.
|
|
111
|
+
* @returns An async generator that yields matching tweets as they are found.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```
|
|
115
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
116
|
+
*
|
|
117
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
118
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
119
|
+
*
|
|
120
|
+
* // Streaming all upcoming tweets from user 'user1'
|
|
121
|
+
* async () => {
|
|
122
|
+
* try {
|
|
123
|
+
* for await (const tweet of rettiwt.tweet.stream({ fromUsers: ['user1'] }, 1000)) {
|
|
124
|
+
* console.log(tweet.fullText);
|
|
125
|
+
* }
|
|
126
|
+
* }
|
|
127
|
+
* catch (err) {
|
|
128
|
+
* console.log(err);
|
|
129
|
+
* }
|
|
130
|
+
* }();
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
public async *stream(filter: TweetFilter, pollingInterval: number = 60000): AsyncGenerator<Tweet> {
|
|
136
|
+
const startDate = new Date();
|
|
137
|
+
|
|
138
|
+
let cursor: string | undefined = undefined;
|
|
139
|
+
let sinceId: string | undefined = undefined;
|
|
140
|
+
let nextSinceId: string | undefined = undefined;
|
|
141
|
+
|
|
142
|
+
while (true) {
|
|
143
|
+
// Pause execution for the specified polling interval before proceeding to the next iteration
|
|
144
|
+
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
145
|
+
|
|
146
|
+
// Search for tweets
|
|
147
|
+
const tweets = await this.search({ ...filter, startDate: startDate, sinceId: sinceId }, undefined, cursor);
|
|
148
|
+
|
|
149
|
+
// Yield the matching tweets
|
|
150
|
+
for (const tweet of tweets.list) {
|
|
151
|
+
yield tweet;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Store the most recent tweet ID from this batch
|
|
155
|
+
if (tweets.list.length > 0 && cursor === undefined) {
|
|
156
|
+
nextSinceId = tweets.list[0].id;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// If there are more tweets to fetch, adjust the cursor value
|
|
160
|
+
if (tweets.list.length > 0 && tweets.next) {
|
|
161
|
+
cursor = tweets.next.value;
|
|
162
|
+
}
|
|
163
|
+
// Else, start the next iteration from this batch's most recent tweet
|
|
164
|
+
else {
|
|
165
|
+
sinceId = nextSinceId;
|
|
166
|
+
cursor = undefined;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
106
171
|
/**
|
|
107
172
|
* Get the tweets from the tweet list with the given id.
|
|
108
173
|
*
|
|
@@ -261,9 +326,26 @@ export class TweetService extends FetcherService {
|
|
|
261
326
|
* });
|
|
262
327
|
* ```
|
|
263
328
|
*
|
|
329
|
+
* @example Posting a reply to a tweet
|
|
330
|
+
* ```
|
|
331
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
332
|
+
*
|
|
333
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
334
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
335
|
+
*
|
|
336
|
+
* // Posting a simple text reply, to a tweet with id "1234567890"
|
|
337
|
+
* rettiwt.tweet.tweet('Hello!', undefined, "1234567890")
|
|
338
|
+
* .then(res => {
|
|
339
|
+
* console.log(res);
|
|
340
|
+
* })
|
|
341
|
+
* .catch(err => {
|
|
342
|
+
* console.log(err);
|
|
343
|
+
* });
|
|
344
|
+
* ```
|
|
345
|
+
*
|
|
264
346
|
* @public
|
|
265
347
|
*/
|
|
266
|
-
public async tweet(text: string, media?: TweetMediaArgs[]): Promise<boolean> {
|
|
348
|
+
public async tweet(text: string, media?: TweetMediaArgs[], replyTo?: string): Promise<boolean> {
|
|
267
349
|
// Converting JSON args to object
|
|
268
350
|
const tweet: TweetArgs = new TweetArgs({ text: text, media: media });
|
|
269
351
|
|
|
@@ -282,7 +364,9 @@ export class TweetService extends FetcherService {
|
|
|
282
364
|
}
|
|
283
365
|
|
|
284
366
|
// Posting the tweet
|
|
285
|
-
const data = await this.post(EResourceType.CREATE_TWEET, {
|
|
367
|
+
const data = await this.post(EResourceType.CREATE_TWEET, {
|
|
368
|
+
tweet: { text: text, media: uploadedMedia, replyTo: replyTo },
|
|
369
|
+
});
|
|
286
370
|
|
|
287
371
|
return data;
|
|
288
372
|
}
|