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 #2

Merged
merged 2 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Emitted when a direct message is sent to the user. Unfortunately, Twitter has no
stream.on('direct_message', function (directMsg) {
//...
})
```


## event: 'user_event'

Expand Down
25 changes: 25 additions & 0 deletions examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Example for a DM response when a user follows
```javascript

// Setting 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.
};
```