Options
All
  • Public
  • Public/Protected
  • All
Menu

Module twitter

Twitter Platform

Tweeting and direct messaging on Twitter.

Install

npm install @machinat/core @machinat/http @machinat/twitter
# or with yarn
yarn add @machinat/core @machinat/http @machinat/twitter

Docs

Check the platform document and the package reference.

Setup

import Machinat from '@machinat/core';
import Http from '@machinat/http';
import Twitter from '@machinat/twitter';

const {
} = process.env;

const app = Machinat.createApp({
modules: [
Http.initModule({ /* ... */ }),
],
platforms: [
Twitter.intiModule({
entryPath: '/webhook/twitter',
}),
],
});

Index

Other

ActionSegmentValue: { accomplishRequest: null | AccomplishRequestFn; mediaSources: null | MediaSource[]; request: TwitterApiRequest; type: "action" }

Type declaration

AnimateInfo: { aspectRatio: NumberPairs; durationMs: number; variants: { bitrate: number; contentType: string; url: string }[] }

Type declaration

  • aspectRatio: NumberPairs

    Aspect ratio of the video. Example: [9, 16]

  • durationMs: number

    Video duration in milliseconds

  • variants: { bitrate: number; contentType: string; url: string }[]

    Source variants

AnimatedGif: Media & { type: "animated_gif"; videoInfo: AnimateInfo }
Coordinates: { latitude: number; longitude: number }

Type declaration

  • latitude: number
  • longitude: number
DirectMessageSegmentValue: { accomplishRequest: null | AccomplishRequestFn; mediaSources: null | MediaSource[]; request: TwitterApiRequest; type: "dm" }

Type declaration

FailApiResult: { client_id?: string; detail: string; errors: any[]; reason: string; registration_url?: string; required_enrollment?: string; title: string; type: string }

Type declaration

  • Optional client_id?: string
  • detail: string
  • errors: any[]
  • reason: string
  • Optional registration_url?: string
  • Optional required_enrollment?: string
  • title: string
  • type: string
FileMediaSource: { assetTag?: string; fileData: Buffer | NodeJS.ReadableStream; parameters: {}; type: "file" }

Type declaration

  • Optional assetTag?: string
  • fileData: Buffer | NodeJS.ReadableStream
  • parameters: {}
    • [k: string]: undefined | string | number
  • type: "file"
HashtagEntity: { indices: NumberPairs; text: string }

Type declaration

  • indices: NumberPairs

    An array of integers indicating the offsets within the Tweet text where the hashtag begins and ends. The first integer represents the location of the # character in the Tweet text string. The second integer represents the location of the first character after the hashtag. Therefore the difference between the two numbers will be the length of the hashtag name plus one (for the ‘#’ character). Example: [32,38]

  • text: string

    Name of the hashtag, minus the leading ‘#’ character

IdMediaSource: { id: string; type: "id" }

Type declaration

  • id: string
  • type: "id"
Media: { displayUrl: string; downloadUrl: string; expandedUrl: string; id: string; indices: NumberPairs; inlineUrl: string; sizes: RawMediaSizeChoices; sourceStatusId?: string; type: MediaType }

Type declaration

  • displayUrl: string

    URL of the media to display to clients. Example: pic.twitter.com/rJC5Pxsu

  • downloadUrl: string

    The URL pointing directly to the uploaded media file, for embedding on https pages.

  • expandedUrl: string

    An expanded version of display_url. Links to the media display page. Example: http://twitter.com/yunorno/status/114080493036773378/photo/1

  • id: string
  • indices: NumberPairs

    An array of integers indicating the offsets within the Tweet text where the URL begins and ends. The first integer represents the location of the first character of the URL in the Tweet text. The second integer represents the location of the first non-URL character occurring after the URL (or the end of the string if the URL is the last part of the Tweet text). Example: [15,35]

  • inlineUrl: string

    Wrapped URL for the media link. This corresponds with the URL embedded directly into the raw Tweet text, and the values for the indices parameter. Example: http://t.co/rJC5Pxsu

  • sizes: RawMediaSizeChoices

    An object showing available sizes for the media file

  • Optional sourceStatusId?: string

    For Tweets containing media that was originally associated with a different tweet, this string-based ID points to the original Tweet

  • type: MediaType

    Type of uploaded media

MediaAttachment: { source: MediaSource; type: MediaType }

Type declaration

MediaSegmentValue: { attachment: MediaAttachment; type: "media" }

Type declaration

MediaType: "photo" | "video" | "animated_gif"
MediaUploadResult: { expires_after_secs: number; media_id: number | BigInt; media_id_string: string; processing_info?: { check_after_secs: number; state: "pending" }; size: number; video?: { video_type: string } }

Type declaration

  • expires_after_secs: number
  • media_id: number | BigInt
  • media_id_string: string
  • Optional processing_info?: { check_after_secs: number; state: "pending" }
    • check_after_secs: number
    • state: "pending"
  • size: number
  • Optional video?: { video_type: string }
    • video_type: string
MentionEntity: { id: string; indices: [number, number]; name: string; screenName: string; user: TwitterUser }

Type declaration

  • id: string

    ID of the mentioned user

  • indices: [number, number]

    An array of integers representing the offsets within the Tweet text where the user reference begins and ends. The first integer represents the location of the ‘@’ character of the user mention. The second integer represents the location of the first non-screenname character following the user mention. Example: [4,15]

  • name: string

    Display name of the referenced user

  • screenName: string

    Screen name of the referenced user

  • user: TwitterUser

    The mentioned user object

NumberPairs: [number, number]
Photo: Media & { type: "photo" }
Place: { boundingCoordinates: Coordinates[]; country: string; countryCode: string; fullName: string; id: string; name: string; type: string; url: string }

Type declaration

  • boundingCoordinates: Coordinates[]

    A bounding box of coordinates which encloses this place

  • country: string

    Name of the country containing this place

  • countryCode: string

    Shortened country code representing the country containing this place

  • fullName: string

    Full human-readable representation of the place’s name

  • id: string

    ID representing this place. Note that this is represented as a string

  • name: string

    Short human-readable representation of the place’s name

  • type: string

    The type of location represented by this place

  • url: string

    URL representing the location of additional place metadata for this place

PollEntity: { durationMinutes: number; endTime: Date; options: { position: number; text: string }[] }

Type declaration

  • durationMinutes: number

    Duration of poll in minutes

  • endTime: Date

    The Date representing when poll ends

  • options: { position: number; text: string }[]

    An array of options, each having a poll position, and the text for that position

RawActionInfo: { created_timestamp: number; source: RawUser; target: RawUser }

Type declaration

RawApp: { id: string; name: string; url: string }

Type declaration

  • id: string
  • name: string
  • url: string
RawBlockStatusEvent: { block_events: ({ type: "block" | "unblock" } & RawActionInfo)[]; for_user_id: string }

Type declaration

  • block_events: ({ type: "block" | "unblock" } & RawActionInfo)[]
  • for_user_id: string
RawDirectMessage: { created_timestamp: string; id: string; message_create: { initiated_via?: { tweet_id?: string; welcome_message_id?: string }; message_data: { attachment?: { media: RawMedia; type: "media" }; entities: RawEntities; quick_reply_response?: { metadata: string; type: "options" }; text: string }; sender_id: string; source_app_id: string; target: { recipient_id: string } }; type: "message_create" }

Type declaration

  • created_timestamp: string
  • id: string
  • message_create: { initiated_via?: { tweet_id?: string; welcome_message_id?: string }; message_data: { attachment?: { media: RawMedia; type: "media" }; entities: RawEntities; quick_reply_response?: { metadata: string; type: "options" }; text: string }; sender_id: string; source_app_id: string; target: { recipient_id: string } }
    • Optional initiated_via?: { tweet_id?: string; welcome_message_id?: string }
      • Optional tweet_id?: string
      • Optional welcome_message_id?: string
    • message_data: { attachment?: { media: RawMedia; type: "media" }; entities: RawEntities; quick_reply_response?: { metadata: string; type: "options" }; text: string }
      • Optional attachment?: { media: RawMedia; type: "media" }
      • entities: RawEntities
      • Optional quick_reply_response?: { metadata: string; type: "options" }
        • metadata: string
        • type: "options"
      • text: string
    • sender_id: string
    • source_app_id: string
    • target: { recipient_id: string }
      • recipient_id: string
  • type: "message_create"
RawDirectMessageAction: { created_timestamp: string; sender_id: string; target: { recipient_id: string }; users: {} }

Type declaration

  • created_timestamp: string
  • sender_id: string
  • target: { recipient_id: string }
    • recipient_id: string
  • users: {}
RawDirectMessageEvent: { apps: {}; direct_message_events: RawDirectMessage[]; for_user_id: string; users: {} }

Type declaration

RawDirectMessageIndicateTypingEvent: { direct_message_indicate_typing_events: RawDirectMessageAction[]; for_user_id: string; users: {} }

Type declaration

RawDirectMessageMarkRead: RawDirectMessageAction & { last_read_event_id: string }
RawDirectMessageMarkReadEvent: { direct_message_mark_read_events: RawDirectMessageMarkRead[]; for_user_id: string; users: {} }

Type declaration

RawEntities: { hashtags: { indices: NumberPairs; text: string }[]; media: RawMedia[]; polls?: { duration_minutes: number; end_datetime: string; options: { position: number; text: string }[] }[]; symbols: { indices: NumberPairs; text: string }[]; urls: RawUrlEntity[]; user_mentions: { id: number | BigInt; id_str: string; indices: NumberPairs; name: string; screen_name: string }[] }

Type declaration

  • hashtags: { indices: NumberPairs; text: string }[]
  • media: RawMedia[]
  • Optional polls?: { duration_minutes: number; end_datetime: string; options: { position: number; text: string }[] }[]
  • symbols: { indices: NumberPairs; text: string }[]
  • urls: RawUrlEntity[]
  • user_mentions: { id: number | BigInt; id_str: string; indices: NumberPairs; name: string; screen_name: string }[]
RawFavorite: { created_at: string; favorited_status: RawTweet; id: string; timestamp_ms: number; user: RawUser }

Type declaration

  • created_at: string
  • favorited_status: RawTweet
  • id: string
  • timestamp_ms: number
  • user: RawUser
RawFavoriteEvent: { favorite_events: RawFavorite[]; for_user_id: string }

Type declaration

RawFollowStatueEvent: { follow_events: ({ type: "follow" | "unfollow" } & RawActionInfo)[]; for_user_id: string }

Type declaration

  • follow_events: ({ type: "follow" | "unfollow" } & RawActionInfo)[]
  • for_user_id: string
RawMedia: { additional_media_info?: { description: string; embeddable: boolean; monetizable: boolean; title: string }; display_url: string; expanded_url: string; id: number | BigInt; id_str: string; indices: NumberPairs; media_url: string; media_url_https: string; sizes: RawMediaSizeChoices; source_status_id?: number | BigInt; source_status_id_str?: string; type: MediaType; url: string; video_info?: { aspect_ratio: NumberPairs; duration_millis: number; variants: { bitrate: number; content_type: string; url: string }[] } }

Type declaration

  • Optional additional_media_info?: { description: string; embeddable: boolean; monetizable: boolean; title: string }
    • description: string
    • embeddable: boolean
    • monetizable: boolean
    • title: string
  • display_url: string
  • expanded_url: string
  • id: number | BigInt
  • id_str: string
  • indices: NumberPairs
  • media_url: string
  • media_url_https: string
  • sizes: RawMediaSizeChoices
  • Optional source_status_id?: number | BigInt
  • Optional source_status_id_str?: string
  • type: MediaType
  • url: string
  • Optional video_info?: { aspect_ratio: NumberPairs; duration_millis: number; variants: { bitrate: number; content_type: string; url: string }[] }
    • aspect_ratio: NumberPairs
    • duration_millis: number
    • variants: { bitrate: number; content_type: string; url: string }[]
RawMediaSize: { h: number; resize: string; w: number }

Type declaration

  • h: number
  • resize: string
  • w: number
RawMediaSizeChoices: { large: RawMediaSize; medium: RawMediaSize; small: RawMediaSize; thumb: RawMediaSize }

Type declaration

RawMuteStatusEvent: { for_user_id: string; mute_events: ({ type: "mute" | "unmute" } & RawActionInfo)[] }

Type declaration

  • for_user_id: string
  • mute_events: ({ type: "mute" | "unmute" } & RawActionInfo)[]
RawPlace: { attributes?: {}; bounding_box: { coordinates: NumberPairs[]; type: "Polygon" }; country: string; country_code: string; full_name: string; id: string; name: string; place_type: string; url: string }

Type declaration

  • Optional attributes?: {}
    • bounding_box: { coordinates: NumberPairs[]; type: "Polygon" }
    • country: string
    • country_code: string
    • full_name: string
    • id: string
    • name: string
    • place_type: string
    • url: string
    RawSettings: { allow_contributor_request: string; always_use_https: boolean; discoverable_by_email: boolean; geo_enabled: boolean; language: string; protected: boolean; screen_name: string; show_all_inline_media: boolean; sleep_time: { enabled: boolean; end_time: null | number; start_time: null | number }; time_zone: { name: string; tzinfo_name: string; utc_offset: number }; trend_location: [{ country: string; countryCode: string; name: string; parentid: number; placeType: { code: number; name: number }; url: string; woeid: number }]; use_cookie_personalization: boolean }

    Type declaration

    • allow_contributor_request: string
    • always_use_https: boolean
    • discoverable_by_email: boolean
    • geo_enabled: boolean
    • language: string
    • protected: boolean
    • screen_name: string
    • show_all_inline_media: boolean
    • sleep_time: { enabled: boolean; end_time: null | number; start_time: null | number }
      • enabled: boolean
      • end_time: null | number
      • start_time: null | number
    • time_zone: { name: string; tzinfo_name: string; utc_offset: number }
      • name: string
      • tzinfo_name: string
      • utc_offset: number
    • trend_location: [{ country: string; countryCode: string; name: string; parentid: number; placeType: { code: number; name: number }; url: string; woeid: number }]
    • use_cookie_personalization: boolean
    RawTweet: { coordinates?: { coordinates: NumberPairs; type: "Point" }; created_at: string; entities: RawEntities; extended_entities: { media: RawMedia[] }; favorite_count?: number; favorited: boolean; filter_level: string; id: number | BigInt; id_str: string; in_reply_to_screen_name?: string; in_reply_to_status_id?: number | BigInt; in_reply_to_status_id_str?: string; in_reply_to_user_id?: number | BigInt; in_reply_to_user_id_str?: string; is_quote_status: boolean; lang?: string; place?: RawPlace; possibly_sensitive?: boolean; quote_count?: number; quoted_status?: RawTweet; quoted_status_id: number | BigInt; quoted_status_id_str: string; reply_count: number; retweet_count: number; retweeted: boolean; retweeted_status?: RawTweet; source: string; text: string; truncated: boolean; user: RawUser }

    Type declaration

    • Optional coordinates?: { coordinates: NumberPairs; type: "Point" }
    • created_at: string
    • entities: RawEntities
    • extended_entities: { media: RawMedia[] }
    • Optional favorite_count?: number
    • favorited: boolean
    • filter_level: string
    • id: number | BigInt
    • id_str: string
    • Optional in_reply_to_screen_name?: string
    • Optional in_reply_to_status_id?: number | BigInt
    • Optional in_reply_to_status_id_str?: string
    • Optional in_reply_to_user_id?: number | BigInt
    • Optional in_reply_to_user_id_str?: string
    • is_quote_status: boolean
    • Optional lang?: string
    • Optional place?: RawPlace
    • Optional possibly_sensitive?: boolean
    • Optional quote_count?: number
    • Optional quoted_status?: RawTweet
    • quoted_status_id: number | BigInt
    • quoted_status_id_str: string
    • reply_count: number
    • retweet_count: number
    • retweeted: boolean
    • Optional retweeted_status?: RawTweet
    • source: string
    • text: string
    • truncated: boolean
    • user: RawUser
    RawTweetCreateEvent: { for_user_id: string; tweet_create_events: RawTweet[]; user_has_blocked?: "true" | "false" }

    Type declaration

    • for_user_id: string
    • tweet_create_events: RawTweet[]
    • Optional user_has_blocked?: "true" | "false"
    RawTweetDelete: { status: { id: string; user_id: string }; timestamp_ms: string }

    Type declaration

    • status: { id: string; user_id: string }
      • id: string
      • user_id: string
    • timestamp_ms: string
    RawTweetDeleteEvent: { for_user_id: string; tweet_delete_events: RawTweetDelete[] }

    Type declaration

    RawUrlEntity: { display_url: string; expanded_url: string; indices: NumberPairs; url: string }

    Type declaration

    • display_url: string
    • expanded_url: string
    • indices: NumberPairs
    • url: string
    RawUser: { created_at: string; default_profile: boolean; default_profile_image: boolean; derived?: { location: {} }; description?: string; entities?: { description: { urls: RawUrlEntity[] }; url: { urls: RawUrlEntity[] } }; favourites_count: number; followers_count: number; friends_count: number; id: number | BigInt; id_str: string; listed_count: number; location?: string; name: string; profile_banner_url: null | string; profile_image_url_https: string; protected: boolean; screen_name: string; status?: RawTweet; statuses_count: number; url?: string; verified: boolean; withheld_in_countries?: string[]; withheld_scope?: string }

    Type declaration

    • created_at: string
    • default_profile: boolean
    • default_profile_image: boolean
    • Optional derived?: { location: {} }
      • location: {}
        • [k: string]: string
    • Optional description?: string
    • Optional entities?: { description: { urls: RawUrlEntity[] }; url: { urls: RawUrlEntity[] } }
    • favourites_count: number
    • followers_count: number
    • friends_count: number
    • id: number | BigInt
    • id_str: string
    • listed_count: number
    • Optional location?: string
    • name: string
    • profile_banner_url: null | string
    • profile_image_url_https: string
    • protected: boolean
    • screen_name: string
    • Optional status?: RawTweet
    • statuses_count: number
    • Optional url?: string
    • verified: boolean
    • Optional withheld_in_countries?: string[]
    • Optional withheld_scope?: string
    RawUserRevokeEvent: { user_event: { revoke: { date_time: number; source: { user_id: string }; target: { app_id: string } } } }

    Type declaration

    • user_event: { revoke: { date_time: number; source: { user_id: string }; target: { app_id: string } } }
      • revoke: { date_time: number; source: { user_id: string }; target: { app_id: string } }
        • date_time: number
        • source: { user_id: string }
          • user_id: string
        • target: { app_id: string }
          • app_id: string
    RenderMediaResponse: { id: string; result: MediaUploadResult; source: MediaSource; type: MediaType }

    Type declaration

    ReplyToTarget: { screenName: string; tweetId: string; user: TwitterUser; userId: string }

    Type declaration

    • screenName: string
    • tweetId: string
    • user: TwitterUser
    • userId: string
    SymbolEntity: { indices: NumberPairs; text: string }

    Type declaration

    • indices: NumberPairs

      An array of integers indicating the offsets within the Tweet text where the symbol/cashtag begins and ends. The first integer represents the location of the $ character in the Tweet text string. The second integer represents the location of the first character after the cashtag. Therefore the difference between the two numbers will be the length of the hashtag name plus one (for the ‘$’ character). Example: [12,17]

    • text: string

      Name of the cashhtag, minus the leading ‘$’ character

    TweetResult: { data: { id: string; text: string } }

    Type declaration

    • data: { id: string; text: string }
      • id: string
      • text: string
    TweetSegmentValue: { accomplishRequest: null | AccomplishRequestFn; mediaSources: null | MediaSource[]; request: TwitterApiRequest; type: "tweet" }

    Type declaration

    TwitterApiRequest: { href: string; method: string; parameters: any }

    Type declaration

    • href: string
    • method: string
    • parameters: any
    TwitterApiResult: { body: unknown; code: number; uploadedMedia: null | { assetTag: undefined | string; result: MediaUploadResult; source: MediaSource }[] }

    Type declaration

    TwitterChannel: TweetTarget | TwitterChat
    TwitterComponent<Props, Segment>: NativeComponent<Props, Segment>

    Type parameters

    TwitterDispatchFrame: DispatchFrame<TwitterChannel, TwitterJob>
    TwitterDispatchResponse: DispatchResponse<TwitterJob, TwitterApiResult>
    TwitterEventContext: { bot: TwitterBot; event: TwitterEvent; metadata: WebhookMetadata; platform: "twitter"; reply: any }

    Type declaration

    TwitterEventMiddleware: EventMiddleware<TwitterEventContext, null>
    TwitterJob: { accomplishRequest: null | AccomplishRequestFn; asApplication: boolean; key: undefined | string; mediaSources: null | MediaSource[]; refreshTarget: null | ((currentTarget: TwitterChannel, result: unknown) => null | TwitterChannel); request: TwitterApiRequest; target: TwitterChannel }

    Type declaration

    TwitterPlatformConfigs: { accessSecret: string; accessToken: string; appId: string; appKey: string; appSecret: string; bearerToken: string; dispatchMiddlewares?: TwitterDispatchMiddleware[]; eventMiddlewares?: TwitterEventMiddleware[]; maxRequestConnections?: number; shouldVerifyRequest?: boolean; webhookPath?: string }

    Type declaration

    • accessSecret: string

      The secret of the access token

    • accessToken: string

      The access token for the agent user

    • appId: string

      The id of Twitter app

    • appKey: string

      The key of Twitter app

    • appSecret: string

      The secret of Twitter app

    • bearerToken: string

      The bearer token of Twitter app

    • Optional dispatchMiddlewares?: TwitterDispatchMiddleware[]
    • Optional eventMiddlewares?: TwitterEventMiddleware[]
    • Optional maxRequestConnections?: number

      The max API request connections at the same time

    • Optional shouldVerifyRequest?: boolean

      To verify the request by the signature or not. Default to true

    • Optional webhookPath?: string

      The webhook path to receive events. Default to /

    UrlEntity: { displayUrl: string; expandedUrl: string; indices: NumberPairs; url: string }

    Type declaration

    • displayUrl: string

      URL pasted/typed into Tweet. Example: bit.ly/2so49n2

    • expandedUrl: string

      Expanded version of displayUrl . Example: http://bit.ly/2so49n2

    • indices: NumberPairs

      An array of integers representing offsets within the Tweet text where the URL begins and ends. The first integer represents the location of the first character of the URL in the Tweet text. The second integer represents the location of the first non-URL character after the end of the URL. Example: [30,53]

    • url: string

      Wrapped URL, corresponding to the value embedded directly into the raw Tweet text, and the values for the indices parameter. Example: https://t.co/yzocNFvJuL

    UrlMediaSource: { assetTag?: string; parameters: {}; type: "url"; url: string }

    Type declaration

    • Optional assetTag?: string
    • parameters: {}
      • [k: string]: undefined | string | number
    • type: "url"
    • url: string
    Video: Media & { additionalMediaInfo: null | { description: string; embeddable: boolean; monetizable: boolean; title: string }; type: "video"; videoInfo: null | AnimateInfo }

    Generated using TypeDoc