Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Client

The core rest Client

param options

Options for the twitter Client

example
import { Client } from 'tweets.ts'

const client = new Client({
debug: (msg) => console.log(msg),
authorization: {
consumer_key: 'qR3vKd535gdhfjt7ffdfsgdq',
consumer_secret: 'wAsefweffsfsfefsKWTRfls',
access_token: '1234454545oZ866Kan',
access_token_secret: 'i366iP633443rewfefef',
}
});

Hierarchy

  • Client

Index

Constructors

constructor

  • new Client(options: ClientOptions): Client

Properties

_rest

_rest: rest

auth

auth: { access_token: null | string; access_token_secret: null | string; consumer_key: null | string; consumer_secret: null | string } & { access_token: null | string; access_token_secret: null | string; consumer_key: null | string; consumer_secret: null | string }

debug

debug: null | Function

oauthClient

oauthClient: any

oauthUserData

oauthUserData: { key: null | string; secret: null | string }

Type declaration

  • key: null | string
  • secret: null | string

options

options: ClientOptions & { api: { rateLimits: boolean; subdomain: string; userAgent: string; version: string }; authorization: { access_token: null | string; access_token_secret: null | string; consumer_key: null | string; consumer_secret: null | string } }

version

version: string

Methods

Private _request

  • _request(obj: requestOptions): Promise<any>

Private _uploadChunk

  • _uploadChunk(attachment: any): Promise<any>

Private _uploadNormal

  • _uploadNormal(attachment: any): Promise<any>

follow

  • follow(user: string | User, enableNotifications?: Boolean): Promise<User>
  • Follows a user

    example
    bot.follow('11112124234').then(console.log).catch(console.log)
    

    Parameters

    • user: string | User

      Users id / screen name or user object to follow

    • enableNotifications: Boolean = true

      if true, sends api param follow set to true, enables notifications for the followed user

    Returns Promise<User>

get

  • get(obj: requestOptions): Promise<any>
  • GET request to the twitter api

    example
    // get request to "/followers/list"
    bot.get({ endPoint: '/followers/list', bodyOrParams: { screen_name: 'typicalninja' } }).then(console.log).catch(console.log);

    Parameters

    • obj: requestOptions

      Request Config for rest manager

    Returns Promise<any>

    Raw json response or a Error

getFollowers

  • getFollowers(user: string, options?: { count: number; cursor: number; noStatus: boolean }): Promise<{ next_cursor: number; previous_cursor: number; users: User[] }>
  • Get a Users Followers, only the first page, use getManyFollowers for more pages

    example
    // get 20 of user's Follower's
    bot.getFollowers('typicalninja', { count: 20 }).then(console.log).catch(console.log)

    Parameters

    • user: string

      User Screen name or id to fetch followers of

    • options: { count: number; cursor: number; noStatus: boolean } = ...

      Options for getFollowers method

      • count: number
      • cursor: number
      • noStatus: boolean

    Returns Promise<{ next_cursor: number; previous_cursor: number; users: User[] }>

    • Array of Users

getManyFollowers

  • getManyFollowers(user: string, options?: { page: { count: number; cursor: number; noStatus: boolean }; pages: number }): Promise<User[][]>
  • Get a Users Followers, Gets multiple pages, sends requests over and over, limit use of this

    example
    // get 3 pages of users with 10 users each for a particular user
    bot.getManyFollowers('typicalninja', { pages: 3, page: { count: 10 } })

    Parameters

    • user: string

      User Screen name or id to fetch followers of

    • options: { page: { count: number; cursor: number; noStatus: boolean }; pages: number } = ...

      Options for getManyFollowers method

      • page: { count: number; cursor: number; noStatus: boolean }
        • count: number
        • cursor: number
        • noStatus: boolean
      • pages: number

    Returns Promise<User[][]>

    Array's inside A Array, containing (page) amount of Users in each Array

getTweets

  • getTweets(tweetIds?: never[], options?: { params: {} }): Promise<unknown>
  • Parameters

    • tweetIds: never[] = []
    • options: { params: {} } = ...
      • params: {}

      Returns Promise<unknown>

    post

    • post(obj: requestOptions): Promise<any>
    • POST request to the twitter api

      example
      // post request to "/statuses/update"
      bot.post({ endPoint: '/statuses/update', bodyOrParams: { status: 'Tweets.js is the best library' } }).then(console.log).catch(console.log);

      Parameters

      • obj: requestOptions

        Request Config for rest manager

      Returns Promise<any>

      Raw json response or a Error

    reply

    • reply(tweetID: string, reply: string, options?: { body: {} }): Promise<Tweet>
    • Reply to a tweet

      example
      // reply to a tweet with message "Hey have you used tweets.js?"
      bot.reply('12232455799', 'Hey have you used tweets.js?')

      Parameters

      • tweetID: string

        Id of the tweet to reply to

      • reply: string

        Message to Reply with

      • options: { body: {} } = ...

        Options for tweet method (passes to tweet())

        • body: {}

        Returns Promise<Tweet>

        A tweet, containing all the usual tweet functions

      retweet

      • retweet(tweetID: string): Promise<Tweet>
      • Retweet a tweet

        example
        // retweet the tweet with id "12233445566"
        bot.retweet('12233445566').then(console.log).catch(console.log)

        Parameters

        • tweetID: string

          Id of the tweet to retweet

        Returns Promise<Tweet>

        A tweet, containing all the usual tweet functions

      tweet

      • tweet(status: string, options?: { body: {} }): Promise<Tweet>
      • Tweet a message

        example
        // tweet a message "hey, this is a tweet from tweets.js"
        bot.tweet('hey, this is a tweet from tweets.js')

        Parameters

        • status: string

          Message to Tweet

        • options: { body: {} } = ...

          Options for tweet method

          • body: {}

            custom body for the request

          Returns Promise<Tweet>

          A tweet, containing all the usual tweet functions

        Private tweetMedia

        • tweetMedia(media: string | Media | Buffer): Promise<any>

        unfollow

        • unfollow(user: string | User): Promise<User>
        • Unfollow's a user

          example
          bot.unfollow('1121212121').then(console.log).catch(console.log)
          

          Parameters

          • user: string | User

            user to unfollow

          Returns Promise<User>

        Generated using TypeDoc