Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yjose committed Apr 29, 2018
0 parents commit 921e407
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 0 deletions.
46 changes: 46 additions & 0 deletions AutoDM.js
@@ -0,0 +1,46 @@
const T = require("./Twit.js");
const my_user_name = require("./config").userName;
const timeout = 1000 * 60 * 5; // timeout to send the message 5 min

const AutoDM = () => {
const stream = T.stream("user");
console.log("Start Sending Auto Direct Message 🚀🚀🚀");
stream.on("follow", user => {
console.log(" 🎉🎉🎉🎉 New Follower 🎉🎉🎉🎉🎉 ");
const { screen_name, name } = user.source;

const obj = {
screen_name,
text: GenerateMessage(name)
};
// the follow stream track if I follow author person too.
if (screen_name != my_user_name) {
setTimeout(() => {
T.post("direct_messages/new", obj)
.catch(err => {
console.error("error", err.stack);
})
.then(result => {
console.log(`Message sent successfully To ${screen_name} 💪💪`);
});
}, timeout);
}
});
};

const GenerateMessage = name => {
const days = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
];
const d = new Date();
const dayName = days[d.getDay()];
return (text = ` Hi ${name} Thanks for being a part of my social media network. I'am the @PicsrushE founder,A new Online Image Editor completely with web technologies,I'm also a reactjs developer and medium blogger.\n Happy to discuss anytime 😊 \n Happy ${dayName} 😊😊 `);
};

module.exports = AutoDM;
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Youssouf EL AZIZI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions Procfile
@@ -0,0 +1 @@
worker: node index.js
17 changes: 17 additions & 0 deletions README.md
@@ -0,0 +1,17 @@
# twitter-bot

Node js twitter bot to send auto direct message

## how it works

* start the project
* fork the project
* customize you auto direct message
* create a simple heroku account
* create a twitter app
* go to https://apps.twitter.com/ and click to the boutton "Create New App"
* go to the setting section and give the app accesse to send messages by "read, Write and Access direct messages"
* go to tab key and Access Tokens and click the "generate Acess Token buotton" in the page bottom.
* Now copy all your key `Consumer Key` `Consumer Secret` `Access Token` and `Access Token Secret` we will need it later !!
* set all env variables from your heroku dashboard > twitter_bot > Settings
* go to resources section and activate the worker Dyno and disable the web dyno
5 changes: 5 additions & 0 deletions Twit.js
@@ -0,0 +1,5 @@
const Twit = require("twit");
const config = require("./config");
const T = new Twit(config.twitterApp);

module.exports = T;
12 changes: 12 additions & 0 deletions config.js
@@ -0,0 +1,12 @@
const twitterApp = {
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRET,
access_token: process.env.ACCESS_TOKEN,
access_token_secret: process.env.ACCESS_TOKEN_SECRET,
timeout_ms: 60 * 1000 // optional HTTP request timeout to apply to all requests.
};

module.exports = {
twitterApp,
userName: process.env.USERNAME
};
5 changes: 5 additions & 0 deletions index.js
@@ -0,0 +1,5 @@
const AutoDM = require("./AutoDM.js");

console.log("App started successfully 🙌🙌");

AutoDM();
14 changes: 14 additions & 0 deletions package.json
@@ -0,0 +1,14 @@
{
"name": "twitter_bot",
"version": "1.0.0",
"description": "Node js twitter bot to send auto direct message",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "Youssouf El AZIZI",
"license": "ISC",
"dependencies": {
"twit": "^2.2.9"
}
}

0 comments on commit 921e407

Please sign in to comment.