gpt4 book ai didi

node.js - 如何使用 Twitter API 回复提及

转载 作者:行者123 更新时间:2023-12-02 00:54:01 24 4
gpt4 key购买 nike

我有一个功能正常的 Twitter 机器人。当他们回复我时,它补充了某人,这是当@myTwitterHandle 是推文中的第一件事时。以下代码允许我回复他们:

function tweetEvent(tweet) {

// Who is this in reply to?
var reply_to = tweet.in_reply_to_screen_name;
// Who sent the tweet?
var name = tweet.user.screen_name;
// What is the text?
var txt = tweet.text;

// Ok, if this was in reply to me
// Replace myTwitterHandle with your own twitter handle
console.log(reply_to, name, txt);
if (reply_to === 'myTwitterHandle') {

¦ // Get rid of the @ mention
¦ txt = txt.replace(/@selftwitterhandle/g, '');

¦ // Start a reply back to the sender
¦ var reply = "You mentioned me! @" + name + ' ' + 'You are super cool!';

¦ console.log(reply);
¦ // Post that tweet!
¦ T.post('statuses/update', { status: reply }, tweeted);
}
}

每当有人在推文正文中@提及我时,我只想发送完全相同的回复。我正在使用 Node.js 和 twit api client .

最佳答案

看起来您可能正在引用找到的教程 here

我相信这就是您正在寻找的东西

I just want to send the exact same reply whenever anyone @mentions me somewhere in the body of their tweet.

这个脚本实现了预期的结果:

var stream = T.stream('statuses/filter', { track: ['@myTwitterHandle'] });
stream.on('tweet', tweetEvent);

function tweetEvent(tweet) {

// Who sent the tweet?
var name = tweet.user.screen_name;
// What is the text?
// var txt = tweet.text;
// the status update or tweet ID in which we will reply
var nameID = tweet.id_str;

// Get rid of the @ mention
// var txt = txt.replace(/@myTwitterHandle/g, "");

// Start a reply back to the sender
var reply = "You mentioned me! @" + name + ' ' + 'You are super cool!';
var params = {
status: reply,
in_reply_to_status_id: nameID
};

T.post('statuses/update', params, function(err, data, response) {
if (err !== undefined) {
console.log(err);
} else {
console.log('Tweeted: ' + params.status);
}
})
};

关于node.js - 如何使用 Twitter API 回复提及,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37346041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com