如何使用Twitter API回应提及

时间:2016-05-20 11:52:29

标签: node.js serverside-javascript twitter-streaming-api

我有一个功能强大的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

1 个答案:

答案 0 :(得分:1)

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

教程

我相信这是你可能正在寻找的东西

  

我只想在任何人 <xsd:key name="States"> <xsd:selector xpath="state"/> <xsd:field xpath="@id"/> </xsd:key> <xsd:key name="States_i"> <xsd:selector xpath="initial"/> <xsd:field xpath="@id"/> </xsd:key> <xsd:keyref name="TransitionsToState" refer="States"> <xsd:selector xpath="state/transition"/> <xsd:field xpath="."/> </xsd:keyref> 时发送完全相同的回复   他们的推文正文中的某个地方。

此脚本实现了所需的结果:

@mentions