npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reshuffle-twitter-connector

v0.0.2

Published

Reshuffle connectors for Twitter

Downloads

8

Readme

reshuffle-twitter-connector

Code | npm | Code sample

npm install reshuffle-twitter-connector

Reshuffle Twitter Connector

This package contains a Reshuffle connector for connecting to Twitter as a Twitter Developer App.

The following example follows Taylor Swift on Twitter. When running it, every Swift tweet is printed to the console:

const { Reshuffle } = require('reshuffle')
const { TwitterConnector } = require('reshuffle-twitter-connector')

const app = new Reshuffle()
const twitter = new TwitterConnector(app, {
  customerKey: process.env.TWITTER_CUSTOMER_KEY,
  customerSecret: process.env.TWITTER_CUSTOMER_SECRET,
})

twitter.on({ follow: 'taylorswift13' }, async (event, app) => {
  for (const tweet of event.tweets) {
    console.log(tweet.text)
  }
})

app.start()

Table of Contents

Configuration Configuration options

Connector events:

follow Follow a user on Twitter

search Track expressions in tweets

REST Operations:

GET Direct REST GET

POST Direct REST POST

Configuration options

Note: You will need to sign up as a Twitter developer and proceed to create a Developer App. Then navigate to the Keys and Tokens page to retrieve your Customer API keys.

const app = new Reshuffle()
const twitter = new TwitterConnector(app, {
  customerKey: process.env.TWITTER_CUSTOMER_KEY,
  customerSecret: process.env.TWITTER_CUSTOMER_SECRET,
})

Connector events

Follow event

Options:

  • follow: string A Twitter handle to follow, e.g. "taylorswift13" or "@taylorswift13"

Example: Process tweets generated by a specific user

async (event, app) => {
  for (const tweet of event.tweets) {
    console.log(tweet.text)
  }
})

The event object includes a single field named tweets, which is an array of objects similar to this:

{
  created_at: 'Sat Oct 17 15:01:59 +0000 2020',
  id: 1317480984862879700,
  id_str: '1317480984862879749',
  text: 'Along with the signed cd, some lucky purchasers of these items may even receive complimentary cat hair stuck inside… https://t.co/aQ139uxVJf',
  truncated: true,
  entities: { hashtags: [], symbols: [], user_mentions: [], urls: [ [Object] ] },
  source: '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a>',
  in_reply_to_status_id: null,
  in_reply_to_status_id_str: null,
  in_reply_to_user_id: null,
  in_reply_to_user_id_str: null,
  in_reply_to_screen_name: null,
  user: {
    id: 17919972,
    id_str: '17919972',
    name: 'Taylor Swift',
    screen_name: 'taylorswift13',
    location: '',
    description: 'you drew stars around my scars',
    url: 'https://t.co/9Cbc2ywlrl',
    entities: { url: [Object], description: [Object] },
    protected: false,
    followers_count: 87316619,
    friends_count: 0,
    listed_count: 112877,
    created_at: 'Sat Dec 06 10:10:54 +0000 2008',
    favourites_count: 1031,
    utc_offset: null,
    time_zone: null,
    geo_enabled: false,
    verified: true,
    statuses_count: 528,
    lang: null,
    contributors_enabled: false,
    is_translator: false,
    is_translation_enabled: false,
    profile_background_color: 'C0DEED',
    profile_background_image_url: 'http://abs.twimg.com/images/themes/theme1/bg.png',
    profile_background_image_url_https: 'https://abs.twimg.com/images/themes/theme1/bg.png',
    profile_background_tile: false,
    profile_image_url: 'http://pbs.twimg.com/profile_images/1286270219980242945/70DWScEH_normal.jpg',
    profile_image_url_https: 'https://pbs.twimg.com/profile_images/1286270219980242945/70DWScEH_normal.jpg',
    profile_banner_url: 'https://pbs.twimg.com/profile_banners/17919972/1595563550',
    profile_link_color: '0084B4',
    profile_sidebar_border_color: 'FFFFFF',
    profile_sidebar_fill_color: 'DDEEF6',
    profile_text_color: '333333',
    profile_use_background_image: false,
    has_extended_profile: false,
    default_profile: false,
    default_profile_image: false,
    following: null,
    follow_request_sent: null,
    notifications: null,
    translator_type: 'regular'
  },
  geo: null,
  coordinates: null,
  place: null,
  contributors: null,
  is_quote_status: false,
  retweet_count: 19509,
  favorite_count: 157344,
  favorited: false,
  retweeted: false,
  possibly_sensitive: false,
  lang: 'en'
}
Search event

Options:

  • search: string Search term, e.g. "#music"

Example: Process tweets containing the specified search term. (See follow for details of the event object)

async (event, app) => {
  for (const tweet of event.tweets) {
    console.log(tweet.user.name, 'says:', tweet.text)
  }
})

REST Operations

GET action

Definition:

(
  path: string,
  qs?: object,
) => object | text

Usage:

const response = await twitter.GET('statuses/user_timeline.json')

Send a GET request. Authenticate using the configured credentials, and check for errors before returning the response data.

POST action

Definition:

(
  path: string,
  qs?: object,
  body?: object,
) => object | text

Usage:

const response = await twitter.POST('friendships/create')

Send a POST request. Authenticate using the configured credentials, and check for errors before returning the response data.

Note that most POST requests may require user level authorization and are not supported by this connector at the moment.