From f3ce6629dc4b0a2cdbb38f3309f6671216c9ef96 Mon Sep 17 00:00:00 2001 From: Michael Pimentel Date: Fri, 20 Oct 2017 08:03:48 -0700 Subject: [PATCH 1/2] dm example for twitter api --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index fe242b74..b8c8cca7 100644 --- a/README.md +++ b/README.md @@ -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' From fa83df40482df2892423567a0934f65ff1832b45 Mon Sep 17 00:00:00 2001 From: Michael Pimentel Date: Tue, 29 May 2018 20:55:56 -0700 Subject: [PATCH 2/2] added an examples.md file with example to create a user stream --- README.md | 26 -------------------------- examples.md | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 26 deletions(-) create mode 100644 examples.md diff --git a/README.md b/README.md index b8c8cca7..4d5e75fd 100644 --- a/README.md +++ b/README.md @@ -406,32 +406,6 @@ Emitted when a direct message is sent to the user. Unfortunately, Twitter has no 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' 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