UXWill
UXWill

Reputation: 199

I'm trying to reply to a tweet using Twit on Node.js

Not sure how to input the in_reply_to_status_id.

It's tweeting out fine, just not replying to the tweet with the mention in it.

The in_reply_to_status_id is part of the Twitter API, which Twit accesses, but can I use this in this context?

Any help would be greatly appreciated.

Here's the code:

var stream = T.stream('statuses/filter', { track: '@example'});

io.on('connection', function (socket) {
  socket.on('chat message', function (msg) {
    console.log('message: ' + msg);
    P.post('statuses/update', { status: '@example' + ' ' + msg}, function (err, data, response) {
      socket.emit('info', data.text);
      socket.emit('userPic', data.user.profile_image_url);
      console.log(data.user.profile_image_url);
    });
  });

  stream.start();

  stream.on('tweet', function (tweet) {
    console.log(tweet);
    // console.log('listening to tweets');

    if (tweet.text.indexOf('@example') > -1) {
      console.log("there is a tweet");
      var number = Date.now();
      var reply = replies[Math.floor(Math.random() * replies.length)];
      var name = '@' + tweet.user.screen_name;
      T.post('statuses/update', {in_reply_to_status_id: [name], status: reply + ' ' + number + ' ' + name}, function (err, data, response) {
        console.log(reply + number);
        socket.emit('reply', data.text);
      });
    }
  });
});

Upvotes: 5

Views: 2614

Answers (1)

UXWill
UXWill

Reputation: 199

The user name ID string was not being parsed correctly. The solution:

var nameID = tweet.id_str;

var name = tweet.user.screen_name;

T.post('statuses/update', {in_reply_to_status_id: nameID, status: reply + ' ' + number + ' @' + name}, function(err, data, response) { 

Upvotes: 6

Related Questions