reshuffle-twitter-connector
v0.0.2
Published
Reshuffle connectors for Twitter
Downloads
2
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.