Skip to content

TwitterBotStreamAction

Nathaniel Kirby edited this page Jan 26, 2014 · 1 revision

You can create a TwitterBotStreamAction via:

var StreamAction = new TwitterBotStreamAction(null, Bot)

The first parameter of the TwitterBotStreamAction constructor is an action function which won't actually be called (inherited from the standard TwitterBotAction constructor), so you don't need to actually pass anything in.

Methods

StreamAction.setStreamPath(streamPath)

Sets the TwitterBotStreamAction's streamPath, by default it's 'statuses/sample' which gives you a sampling of the public Twitter timeline

StreamAction.getStreamPath()

Returns the TwitterBotStreamAction's streamPath

StreamAction.start()

Starts the TwitterBotStreamAction

StreamAction.stop()

Stops the TwitterBotStreamAction

StreamAction.listen(name, match, callback)

StreamAction.listen(listenerName, listenerFunction, function(twitter, action, tweet) {
  // Do something with the tweet
});

The listenerName is a string that identifies the listener. The listenerFunction follows the following format:

listenerFunction = function(tweet) {
  if (something)
    return true;
    
  return false;
}

By returning true, you'll tell the listen() function to execute the passed callback method.

For example:

StreamAction.listen("listening", tweetThatContainsName, function(twitter, action, tweet) {
  Bot.now(Bot.randomWeightedAction("reply actions"), tweet);
});
Clone this wiki locally