diff --git a/README.md b/README.md index fe242b74..4d5e75fd 100644 --- a/README.md +++ b/README.md @@ -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' diff --git a/examples.md b/examples.md new file mode 100644 index 00000000..d21d67e0 --- /dev/null +++ b/examples.md @@ -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. +}; +``` \ No newline at end of file