-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.js
47 lines (40 loc) · 1.09 KB
/
rules.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
import needle from "needle";
import dotenv from 'dotenv'
dotenv.config()
const token = process.env.TWITTER_BEARER_TOKEN;
const options = {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
}
};
// Create Rule(s)
const body = JSON.stringify({
"add": [
{
"value": "@GenesysTheBot #GenesysTheBot -has:links",
"tag": "tweets that mention the bot"
}
]
});
needle('post', 'https://api.twitter.com/2/tweets/search/stream/rules', options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
// Get Rules
needle('get', 'https://api.twitter.com/2/tweets/search/stream/rules', options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
// Delete Rule(s)
const deleteBody = JSON.stringify({
"delete": {
"ids": [
"1595909425763872768"
]
}
});
needle('post', 'https://api.twitter.com/2/tweets/search/stream/rules', deleteBody, options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});