Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an Direct message example for Twit API readme docs #384

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,32 @@ stream.on('direct_message', function (directMsg) {
//...
})
```
Example for a DM response when a user follows
```javascript

// Settig up a user stream
var stream = T.stream('user');

function followed(eventMsg) {
console.log('Follow event!');
var name = eventMsg.source.name;
var screenName = eventMsg.source.screen_name;

// Anytime Someone follows me
stream.on('follow', followed);

// the post request for direct messages > need to add a function to handle errors

setTimeout(function() { // wait 60 sec before sending direct message.
console.log("Direct Message sent");
T.post("direct_messages/new", {
screen_name: screenName,
text: 'Thanks for following' + ' ' + screenName + '! ' + ' What you want to be sent to a new follower '
});
}, 1000*10); // will respond via direct message 10 seconds after a user follows.
};
```


## event: 'user_event'

Expand Down