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

Not sure how to enter in_reply_to_status_id.

This is a subtle statement that simply does not respond to the tweet mentioned in it.

In_reply_to_status_id is part of the Twitter API that Twit accesses, but can I use it in this context?

Any help would be greatly appreciated.

Here is 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);
      });
    }
  });
});
+4
source share
1 answer

The username identifier string was not parsed correctly. Decision:

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) { 
+4
source

Source: https://habr.com/ru/post/1611256/


All Articles