-
Notifications
You must be signed in to change notification settings - Fork 9
TwitterBot
The TwitterBot object contains all the information about your TwitterBot, as well as holds onto the actions, streaming and scheduling for your Twitter Bot
var TwitterBot = require("node-twitterbot").TwitterBot
After that, the TwitterBot constructor either needs an object containing the configuration for the Twitter Bot
var Bot = new TwitterBot({
"consumer_secret": "consumer_secret",
"consumer_key": "consumer_key",
"access_token": "access_token",
"access_token_secret": "access_token_secret"
});
... or a path to a config JSON file.
var Bot = new TwitterBot("path-to-config.json");
Bot.tweet(text, callback)
Posts a tweet with the text set to a string value you wish to post.
Bot.addAction(actionName, callback)
Creates an action with name actionName. This name can be used to schedule or execute actions down the road. The callback method for all actions is as follows:
Bot.addAction("name", function(twitter, action, tweet) {
});
Where twitter
is the Bot's Twit object, the action
object is the TwitterBotAction object generated by the addAction() method itself, and tweet
is any tweet data passed available.
removeAction(actionName)
Removes an action with name=actionName
Bot.allActions(groupName)
Returns the names of all actions owned by the TwitterBot. If you pass in a groupName
, it will only return the names of actions belonging to groupName
Bot.actionWithName(actionName)
Returns the TwitterBotAction whose name is actionName
, or null if not found.
Bot.randomAction(groupName)
Returns the name of a random action. If you pass in groupName
, the random action will only be one owned by that group.
Bot.randomWeightedAction(groupName)
If you have added weights (to add predictability to randomness), this will return a random action name according to the weights and, optionally, groupName
Bot.startStreaming()
Starts streaming the Twitter timeline. Any streaming listeners added to the TwitterBot will get a chance to match the Tweet.
Bot.stopStreaming()
Stops the TwitterBot's streaming.
Bot.listen(name, match, action)
Creates a listener for the TwitterBot's streaming.
Bot.listen(listenerName, listenerFunction, function(twitter, action, tweet) {
// Do something with the tweet
});
Where listenerFunction returns true when passed a tweet that matches it's criteria, passing the tweet into the third function. This is ideal for perusing the timeline for given phrases.
Bot.schedule(action, timeout, tweet)
Executes an action (by name, function or TwitterBotAction) after timeout
ms.
Bot.now(action, tweet)
Executes an action immediately