-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
117 lines (104 loc) · 3.11 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env node
'use strict'
require('dotenv-safe').config()
// const BatchJobFactory = require('./lib/batch-job-factory')
const Workflow = require('./lib/workflow')
const db = require('./lib/db')
const logger = require('./lib/logger')
const twitter = require('./lib/twitter')
const twitterAccessToken = process.env.TWITTER_ACCESS_TOKEN
const twitterAccessTokenSecret = process.env.TWITTER_ACCESS_TOKEN_SECRET
async function main() {
logger.level = 4
const twitterClient = await twitter.getClient({
logger,
accessToken: twitterAccessToken,
accessTokenSecret: twitterAccessTokenSecret
})
const context = {
db,
logger,
twitterClient
}
const job = new Workflow(
{
params: {
pipeline: [
{
type: 'twitter:get-followers',
label: 'followers',
params: {
maxLimit: 10,
count: 10
}
},
{
type: 'twitter:lookup-users',
label: 'users',
connect: {
userIds: 'followers'
},
transforms: ['sort-users-by-fuzzy-popularity']
}
// {
// type: 'twitter:send-direct-messages',
// connect: {
// users: 'users'
// },
// params: {
// template: `Hey @{{user.screen_name}}, I'm testing an open source Twitter automation tool and you happen to be my lucky test user.\n\nSorry for the spam. https://github.com/saasify-sh/twitter-flock`
// }
// }
]
}
},
context
)
// const job = BatchJobFactory.createBatchJobTwitterGetFollowers({
// params: {
// accessToken: twitterAccessToken,
// accessTokenSecret: twitterAccessTokenSecret,
// maxLimit: 10,
// count: 10
// }
// })
// const job = BatchJobFactory.createBatchJobTwitterLookupUsers({
// params: {
// accessToken: twitterAccessToken,
// accessTokenSecret: twitterAccessTokenSecret,
// batchSize: 2,
// userIds: [
// '895851994346401792',
// '1236214051576766469',
// '948428628957843456',
// '1256076780642934785',
// '477975810',
// '102739305',
// '1263940243616600065',
// '327034465'
// ]
// }
// })
// const job = BatchJobFactory.createBatchJobTwitterSendDirectMessages({
// params: {
// accessToken: twitterAccessToken,
// accessTokenSecret: twitterAccessTokenSecret,
// users: [user],
// template: `Hey @{{user.screen_name}},
// Thanks for following me ☺ Check out https://github.com/saasify-sh/saasify`
// }
// })
// const job = BatchJobFactory.createBatchJobTwitterSendTweets({
// params: {
// accessToken: twitterAccessToken,
// accessTokenSecret: twitterAccessTokenSecret,
// users: [{ screen_name: 'yourUserHere' }],
// template: `Hey @{{user.screen_name}}, thanks for following me!`
// }
// })
await job.run()
console.log(JSON.stringify(job.serialize(), null, 2))
}
main().catch((err) => {
console.error(err)
})