ntwitter icon indicating copy to clipboard operation
ntwitter copied to clipboard

Reply to a tweet

Open anthonywebb opened this issue 12 years ago • 3 comments

I see in the readme there is an example of how to publish a status update.

Is there any way to have a tweet look like a reply to a tweet from your stream, instead of just a plan status update?

anthonywebb avatar Mar 15 '12 23:03 anthonywebb

Yep, similar thought. Implementing this would be great.

dezinezync avatar Mar 21 '12 19:03 dezinezync

Hey @anthonywebb and @dezinezync,

This is actually achievable right now.

If you look at the code that makes up updateStatus, you'll see it actually takes a second parameter that is an Object of keys/values corresponding to the Twitter Rest API (look at status and include_entities - they're enabled by default here).

So, we actually would just need to pass in the in_reply_to_status_id key and an ID of an existing status. To get that, we just need to set a local var to the tweet.id_str, and then we can use that var as the value of the in_reply_to_status_id value. From there, we just use that object as our second parameter in updateStatus, and move our callback to the third param.

So, for example:


twit.stream('/status/filter', function(stream) {
    stream.on('data', function (tweet) {
        var reply_id = tweet.id_str; 
        twit.updateStatus(
            "@connor hey how's it going?"
         , {in_reply_to_status_id: reply_id}
         , function(err, data) {
             if (err) { console.log (err) }
           }
        )
    }
}

^5's, Connor

connor avatar Apr 10 '12 23:04 connor

+1 @connor - Worked for me!

Marak avatar Aug 31 '12 14:08 Marak