1.1.2 • Published 8 years ago
twitter-poller v1.1.2
twitter-poller
It does exactly what you think.
Features
- Does not require Twitter account (or app)
- Notifies about new tweets from specified profiles
- Easy and intuitive structure and implementation
- Fully customizable
Navigation
Installation
npm install twitter-poller --save
Code sample
const twitterPoller = require('twitter-poller');
const tp = new twitterPoller({ profiles: ['Hasel_Loyance'] });
let handleTweet = async (tweetObject) => {
console.log('New tweet');
console.log(JSON.stringify(tweetObject));
}
tp.poll(handleTweet);
Tweet object structure
{
// Information about profile from which tweet was received from
profile: {
// Unique user name
user: 'Hasel_Loyance',
// Display user name
name: 'Hasel Loyance',
// User id
id: 2967579722,
// Avatar image url
avatarUrl: 'https://pbs.twimg.com/profile_images/770460179586424832/ZLGwf3E8.jpg'
},
// Information about profile that posted the tweet
from: {
// Unique user name
user: 'Hasel_Loyance',
// Display user name
name: 'Hasel Loyance',
// User id
id: 2967579722,
// Avatar image urls
avatar: {
small:'https://pbs.twimg.com/profile_images/770460179586424832/ZLGwf3E8_bigger.jpg',
normal: 'https://pbs.twimg.com/profile_images/770460179586424832/ZLGwf3E8_normal.jpg',
big: 'https://pbs.twimg.com/profile_images/770460179586424832/ZLGwf3E8.jpg'
}
},
// Tweet content
tweet: {
// Tweet id
id: '802731445110370304',
// Tweet timestamp
timestamp: 1480221065,
// Flag if tweet is pinned
isPinned: 0,
// Flag if tweet is marked as NSFW
isNSFW: 0,
// Array of attachments
// See attachment structure for details
attachments: [],
// Tweet message
text: 'No, I\'m not dead. I\'ve been working on something. And it require(\'s-lots-of-node-js\')',
// Tweet stats
replyCount: 0,
retweetCount: 0,
favoriteCount: 0
}
}
Tweet attachment structure
There are five attachment types:
- image
- gif
- video
- externalLink
- poll
Attachment structure is:
{
type: '<type>',
url: 'url',
}
Please note:
gif and video types urls lead to the Twitter embedding player with video/gif source
poll type contains id of the poll card instead of the link, since Twitter does not share any data about polls publically
Example:
{
type: 'video',
url: 'https://twitter.com/i/videos/tweet/858455030382419968',
}
{
type: 'poll',
url: 'card://858547291761893378',
}
Options
Parameter | Type | Description | Defaults to |
---|---|---|---|
redis.twitterCacheName | string | Ordered set where new tweet ids are stored | TwitterCache |
redis.host | string | IP for redis caching server | 127.0.0.1 |
redis.port | number | Port for redis caching server | 6379 |
redis.options.password | string | Password for redis caching server | |
profiles | array | Twitter profile names for polling | |
pollIntervalMs | number | Interval between polling requests (ms) | 10000 |
profileLoadTimeout | number | Timeout if can't get profile (ms) | 2000 |
userAgent | string | User-Agent header value in requests | Twitter-Poller |