Git Product home page Git Product logo

twtrbot's Introduction

TwtrBot

Twtrbot is a simple Node module wrapper that allows developers to build a Twitter bot via the Twitter API in conjunction with the twit module. Using an object-oriented approach, TwtrBot makes calling functions more intuitive, resulting in cleaner and easier to understand code.

TwtrBot arose from a personal need to encapsulate popular actions such as posting a status, retweeting a status, and searching for statuses, into a set of methods for better efficiency and code maintainability.

Instillation

npm i twtrbot --save

Usage

Be sure to first create a new bot (aka application) over at https://developer.twitter.com/. This package can and should be used in conjunction to https://github.com/ttezel/twit.

Features

JSDoc highlighting with link to corresponding Twitter API reference: highlight

Example Snippet

const TwtrBot  = require('./TwtrBot');
const MyBot = new TwtrBot(CONSUMER_KEY CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_SECRET);

MyBot.postTweet("Hello world!");  // Post a Tweet

let params = {
  lat: 34.052235,
  long:  -118.243683
};

MyBot.postTweet('Hello from Los Angeles!', params);

MyBot.searchTweets("oat milk latte").then(async (data) => {
  let tweets = data.statuses;
  for await (let tweet of tweets) {
    let tweet_id = tweet.id;
    MyBot.postRetweet(tweet_id);
  }
});

MyBot.twit.stream('statuses/filter', { track: 'oolong milk tea' });

Snippet Breakdown

Import the module:

const TwtrBot  = require('./TwtrBot');

Initialize your bot object:

const MyBot = new TwtrBot(CONSUMER_KEY CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_SECRET);

You can find find all your credentials over at https://developer.twitter.com/, under the Projects & Apps tab.

Posting your first Tweet (aka status):

MyBot.postTweet("Hello world!");  // Post a Tweet

Posting a Tweet passing optional parameters:

let params = {
  lat: 34.052235,
  long:  -118.243683
};

MyBot.postTweet('Hello from Los Angeles!', params);

Searching tweets based on a query and retweeting those tweets:

MyBot.searchTweets("oat milk latte").then(async (data) => {
  let tweets = data.statuses;
  for await (let tweet of tweets) {
    let tweet_id = tweet.id;
    MyBot.postRetweet(tweet_id);
  }
});

Accessing the twit object to perform uncovered functions in the module:

MyBot.twit.stream('statuses/filter', { track: 'oolong milk tea' })

Bots Created with TwtrBot

Contributing

Feel free to make any changes and submit a pull request!

twtrbot's People

Contributors

sirandluke avatar

Stargazers

 avatar

Watchers

 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.