ttezel / twit

Twitter API Client for node (REST & Streaming API)
4.31k stars 570 forks source link

How to add a comment to retweet #511

Open wilburforce83 opened 5 years ago

wilburforce83 commented 5 years ago

Hi I was wondering if I could get an exmaple of how to add a comment on a retweet:

 T.post('statuses/retweet/' + retweetId, {}, tweeted)
      }

I'mnotsurehowto add the parameter and message inside this?

many thanks!!!

friaca commented 5 years ago

I was having the same issue. The solution I came up with was:

  1. Get full tweet URL by its ID.
  2. Create a normal tweet with whatever you want the comment to be.
  3. At the end of the tweet, append the URL of the tweet you want to retweet.
    tweet: function (status, callback = this.stdCallback) {
        var params = {
            status: status
        }

        twit.post('statuses/update', params, callback)
    }

    getFullTweetURL: function (idTweet) {
        var params = {
            id: idTweet
        }

        return new Promise((resolve, reject) => {
            function callback(err, data, response) {
                if (err) {
                    console.log(`Algo deu errado!\n\n${err}`);
                    reject(err);
                }
                else {
                    var url = `https://twitter.com/${data.user.screen_name}/status/${idTweet}`
                    return resolve(url);
                }
            }

            twit.get('statuses/show', params, callback);
        })
    },

    quoteTweet: function (idTweet) {
        this.getFullTweetURL(idTweet).then(url => {
            var param = `🤙🏻 eh nois mano ${url}`
            this.tweet(param);
        })
    },