-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendTweetWithImage.js
More file actions
45 lines (42 loc) · 1.24 KB
/
Copy pathsendTweetWithImage.js
File metadata and controls
45 lines (42 loc) · 1.24 KB
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
const wordfilter = require('wordfilter');
function tweetOK(phrase) {
if (!wordfilter.blacklisted(phrase) && phrase !== undefined && phrase !== "" && tweetLengthOK(phrase)){
return true;
} else {
return false;
}
}
function tweetLengthOK(phrase) {
if (phrase.length <= 130){
return true;
} else {
return false;
}
}
function SendTweetWithImage(twitClient, text, image, callback){
const uploadParams = {
media_data: image.toString('base64')
};
//This silly nonsense only accepts a file path...
//twitClient.postMediaChunked(uploadParams, function(err, data, response){
twitClient.post('media/upload', uploadParams, function(err, data, response){
if (err != null) {
console.log('upload failed')
console.log(err);
if(callback) callback(err);
return;
}
const tweet = {
status: text,
media_ids: [data.media_id_string]
};
twitClient.post('statuses/update', tweet, function(err, data, response){
if (err!=null){
console.log('tweet failed');
console.log(err);
if(callback) callback(err);
}
});
});
}
module.exports = SendTweetWithImage;