Giter Site home page Giter Site logo

node-twbot's Introduction

This README is still under construction.

node-twbot

This library provides the microframework to implement a twitter bot program.

How to use

OAuth Configuration

You need to get OAuth configuration before implementing your bot.

At first, use twbot:config command to generate oauth_token.

$ twbot:config YOUR_CONSUMER_KEY YOUR_CONSUMER_SECRET
The 'sys' module is now called 'util'. It should have a similar interface.
please visit http://twitter.com/oauth/authorize?oauth_token=ZZZZZZZZZZZZZZZZZZZZ to get verification code.
input verification code: XXXXXX

Then open your browser, go to authorize url, and input verification code.

*********************************************************************
Access key/secret have been successfully retrieved from Twitter
You can use Bot application by following constructions.
*********************************************************************

var TwBot = require("twbot").TwBot;
var bot = new TwBot({"consumerKey":"YOUR_CONSUMER_KEY","consumerSecret":"YOUR_CONSUMER_SECRET","accessKey":"YOUR_ACCESS_KEY","accessSecret":"YOUR_ACCESS_SECRET"})

You can use the above statement to initialize bot object.

Implement Raw Events.

a bot instance is an EventEmitter instance. You can addListener/on function to define your event handers.

bot.on('tweet', function(data){
    console.log(data.text);
});

bot.on('mentioned', function(data){
    console.log(data.text);
});

Implement Match Events

Focusing on tweet stream, you can use match function to trigger functions only when conditions are matched.

bot.match(
  '#node-twbot',
  function(tweet){  // only executed when the tweet include #node-twbot hashtag.
     console.log(tweet.text);
  }
);

The first argument accepts String or RegExp, which are compared with the tweet text. It also accept an function, which returns true to execute the handler.

Starting event loop

A bot instance currently uses only UserStream API. To start streaming event loop, execute as follows:

bot.startUserStream();

To stop the bot, kill the process. If connection reset by Twitter server, it try to reconnect in several seconds.

Examples

See more examples on the examples directory.

Plugins

The plugins directory contains several useful implementations.

  • auto-follow
  • store-couchdb
  • ... etc

To use plugins, just call the load method with plugin file path (require.paths is used to load).

bot.loadPlugin('twbot/auto-follow');

You can implement your own plugin in your application.

Lisense

MIT License

node-twbot's People

Contributors

kernow avatar yssk22 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.