Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • MessengerClient

Index

Constructors

Properties

Methods

Constructors

constructor

Properties

Readonly accessToken

accessToken: string

The access token used by the client.

Optional Readonly appId

appId?: string

The app ID used by the client.

Optional Readonly appSecret

appSecret?: string

The app secret used by the client.

Readonly axios

axios: AxiosInstance

The underlying axios instance.

Readonly version

version: string

The version of the Facebook Graph API.

Methods

associateLabel

  • associateLabel(userId: string, labelId: number): Promise<{ success: true }>

createLabel

  • createLabel(name: string): Promise<{ id: string }>

createPersona

  • createPersona(persona: Persona): Promise<{ id: string }>

createSubscription

  • createSubscription(__namedParameters: { accessToken: string; callbackUrl: string; fields?: string[]; includeValues?: boolean; object?: "user" | "page" | "permissions" | "payments"; verifyToken: string }): Promise<{ success: boolean }>
  • Create new Webhooks subscriptions.

    see

    https://developers.facebook.com/docs/graph-api/reference/app/subscriptions

    example
    await client.createSubscription({
    accessToken: APP_ACCESS_TOKEN,
    callbackUrl: 'https://mycallback.com',
    fields: ['messages', 'messaging_postbacks', 'messaging_referrals'],
    verifyToken: VERIFY_TOKEN,
    });

    // Or provide app id and app secret instead of app access token:
    client.createSubscription({
    accessToken: `${APP_ID}|${APP_SECRET}`,
    callbackUrl: 'https://mycallback.com',
    fields: ['messages', 'messaging_postbacks', 'messaging_referrals'],
    verifyToken: VERIFY_TOKEN,
    });

    Parameters

    • __namedParameters: { accessToken: string; callbackUrl: string; fields?: string[]; includeValues?: boolean; object?: "user" | "page" | "permissions" | "payments"; verifyToken: string }
      • accessToken: string
      • callbackUrl: string
      • Optional fields?: string[]
      • Optional includeValues?: boolean
      • Optional object?: "user" | "page" | "permissions" | "payments"
      • verifyToken: string

    Returns Promise<{ success: boolean }>

    Success status

debugToken

deleteAccountLinkingURL

deleteGetStarted

deleteGreeting

deleteIceBreakers

deleteLabel

  • deleteLabel(labelId: number): Promise<{ success: true }>

deleteMessengerProfile

deletePersistentMenu

deletePersona

  • deletePersona(personaId: string): Promise<{ success: true }>

deleteUserPersistentMenu

deleteWhitelistedDomains

disableNLP

  • disableNLP(): Promise<any>

dissociateLabel

  • dissociateLabel(userId: string, labelId: number): Promise<{ success: true }>

enableNLP

  • enableNLP(): Promise<any>

getAccountLinkingURL

  • getAccountLinkingURL(): Promise<null | string>

getAllPersonas

  • getAllPersonas(): Promise<{ id: string; name: string; profilePictureUrl: string }[]>
  • Retrieves all personas associated with a page.

    example
    await client.getAllPersonas();
    // [
    // {
    // "name": "John Mathew",
    // "profile_picture_url": "https://facebook.com/john_image.jpg",
    // "id": "<PERSONA_ID>"
    // },
    // {
    // "name": "David Mark",
    // "profile_picture_url": "https://facebook.com/david_image.jpg",
    // "id": "<PERSONA_ID>"
    // }
    // ]

    Returns Promise<{ id: string; name: string; profilePictureUrl: string }[]>

    an array of all personas

getAssociatedLabels

  • getAssociatedLabels(userId: string, options?: { fields?: string[] }): Promise<{ data: { id: string; name: string }[]; paging: { cursors: { after: string; before: string } } }>
  • Retrieves the labels currently associated with a PSID

    see

    https://developers.facebook.com/docs/messenger-platform/identity/custom-labels#retrieving_labels_by_psid

    example
    await client.getAssociatedLabels(USER_ID);
    // {
    // data: [
    // {
    // name: 'myLabel',
    // id: '1001200005003',
    // },
    // {
    // name: 'myOtherLabel',
    // id: '1001200005002',
    // },
    // ],
    // paging: {
    // cursors: {
    // before:
    // 'QVFIUmx1WTBpMGpJWXprYzVYaVhabW55dVpycko4U2xURGE5ODNtNFZAPal94a1hTUnNVMUtoMVVoTzlzSDktUkMtQkUzWEFLSXlMS3ZALYUw3TURLelZAPOGVR',
    // after:
    // 'QVFIUmItNkpTbjVzakxFWGRydzdaVUFNNnNPaUl0SmwzVHN5ZAWZAEQ3lZANDAzTXFIM0NHbHdYSkQ5OG1GaEozdjkzRmxpUFhxTDl4ZAlBibnE4LWt1eGlTa3Bn',
    // },
    // },
    // }

    Parameters

    • userId: string

      Facebook page-scoped user ID of the user

    • options: { fields?: string[] } = {}
      • Optional fields?: string[]

    Returns Promise<{ data: { id: string; name: string }[]; paging: { cursors: { after: string; before: string } } }>

    Associated labels in pagination result

getBlockedConversations

  • getBlockedConversations(options: InsightOptions): Promise<{ name: "page_messages_blocked_conversations_unique"; period: "day"; values: { endTime: string; value: number | object }[] }>

getGetStarted

  • getGetStarted(): Promise<null | { payload: string }>

getGreeting

getIceBreakers

getIdsForApps

  • getIdsForApps(__namedParameters: { app?: string; appSecret: string; page?: string; userId: string }): Promise<{ data: { app: { category?: string; id: string; link: string; name: string; namespace?: string }; id: string }[]; paging: { cursors: { after: string; before: string } } }>
  • Given a user ID for a bot in Messenger, retrieve the IDs for apps owned by the same business

    see

    https://developers.facebook.com/docs/messenger-platform/identity/id-matching

    example
    await client.getIdsForApps({
    userId: USER_ID,
    appSecret: APP_SECRET,
    });
    // {
    // data: [
    // {
    // id: '10152368852405295',
    // app: {
    // category: 'Business',
    // link: 'https://www.facebook.com/games/?app_id=1419232575008550',
    // name: "John's Game App",
    // id: '1419232575008550',
    // },
    // },
    // {
    // id: '645195294',
    // app: {
    // link: 'https://apps.facebook.com/johnsmovieappns/',
    // name: 'JohnsMovieApp',
    // namespace: 'johnsmovieappns',
    // id: '259773517400382',
    // },
    // },
    // ],
    // paging: {
    // cursors: {
    // before: 'MTQ4OTU4MjQ5Nzc4NjY4OAZDZDA',
    // after: 'NDAwMDExOTA3MDM1ODMwA',
    // },
    // },
    // };

    Parameters

    • __namedParameters: { app?: string; appSecret: string; page?: string; userId: string }
      • Optional app?: string
      • appSecret: string
      • Optional page?: string
      • userId: string

    Returns Promise<{ data: { app: { category?: string; id: string; link: string; name: string; namespace?: string }; id: string }[]; paging: { cursors: { after: string; before: string } } }>

    User IDs in pagination result

getIdsForPages

  • getIdsForPages(__namedParameters: { app?: string; appSecret: string; page?: string; userId: string }): Promise<{ data: { id: string; page: { category?: string; id: string; link: string; name: string; namespace?: string } }[]; paging: { cursors: { after: string; before: string } } }>
  • Given a user ID for a Page (associated with a bot), retrieve the IDs for other Pages owned by the same business

    see

    https://developers.facebook.com/docs/messenger-platform/identity/id-matching

    example
    await client.getIdsForPages({
    userId: USER_ID,
    appSecret: APP_SECRET,
    });
    // {
    // data: [
    // {
    // id: '12345123', // The psid for the user for that page
    // page: {
    // category: 'Musician',
    // link:
    // 'https://www.facebook.com/Johns-Next-Great-Thing-380374449010653/',
    // name: "John's Next Great Thing",
    // id: '380374449010653',
    // },
    // },
    // ],
    // paging: {
    // cursors: {
    // before: 'MTQ4OTU4MjQ5Nzc4NjY4OAZDZDA',
    // after: 'NDAwMDExOTA3MDM1ODMwA',
    // },
    // },
    // };

    Parameters

    • __namedParameters: { app?: string; appSecret: string; page?: string; userId: string }
      • Optional app?: string
      • appSecret: string
      • Optional page?: string
      • userId: string

    Returns Promise<{ data: { id: string; page: { category?: string; id: string; link: string; name: string; namespace?: string } }[]; paging: { cursors: { after: string; before: string } } }>

    User IDs in pagination result

getInsights

getLabelDetails

  • getLabelDetails(labelId: number, options?: { fields?: string[] }): Promise<{ id: string; name: string }>

getLabelList

  • getLabelList(options?: { fields?: string[] }): Promise<{ data: { id: string; name: string }[]; paging: { cursors: { after: string; before: string } } }>
  • Retrieves a list of custom labels

    see

    https://developers.facebook.com/docs/messenger-platform/identity/custom-labels#get_all_labels

    example
    await client.getLabelList();
    // {
    // data: [
    // {
    // name: 'myLabel',
    // id: '1001200005003',
    // },
    // {
    // name: 'myOtherLabel',
    // id: '1001200005002',
    // },
    // ],
    // paging: {
    // cursors: {
    // before:
    // 'QVFIUmx1WTBpMGpJWXprYzVYaVhabW55dVpycko4U2xURGE5ODNtNFZAPal94a1hTUnNVMUtoMVVoTzlzSDktUkMtQkUzWEFLSXlMS3ZALYUw3TURLelZAPOGVR',
    // after:
    // 'QVFIUmItNkpTbjVzakxFWGRydzdaVUFNNnNPaUl0SmwzVHN5ZAWZAEQ3lZANDAzTXFIM0NHbHdYSkQ5OG1GaEozdjkzRmxpUFhxTDl4ZAlBibnE4LWt1eGlTa3Bn',
    // },
    // },
    // }

    Parameters

    • options: { fields?: string[] } = {}
      • Optional fields?: string[]

    Returns Promise<{ data: { id: string; name: string }[]; paging: { cursors: { after: string; before: string } } }>

    Custom labels in pagination result

getMessagingFeatureReview

getMessengerProfile

  • Retrieves the current value of one or more Messenger Profile properties by name.

    see

    https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api

    example
    await client.getMessengerProfile(['get_started', 'persistent_menu']);
    // [
    // {
    // getStarted: {
    // payload: 'GET_STARTED',
    // },
    // },
    // {
    // persistentMenu: [
    // {
    // locale: 'default',
    // composerInputDisabled: true,
    // callToActions: [
    // {
    // type: 'postback',
    // title: 'Restart Conversation',
    // payload: 'RESTART',
    // },
    // ],
    // },
    // ],
    // },
    // ]

    Parameters

    • fields: string[]

      An array of Messenger profile properties to retrieve. Value must be among account_linking_url, persistent_menu, get_started, greeting, ice_breakers and whitelisted_domains.

    Returns Promise<MessengerProfile[]>

    The current value of the requested properties

getNewConversations

  • getNewConversations(options: InsightOptions): Promise<{ name: "page_messages_new_conversations_unique"; period: "day"; values: { endTime: string; value: number | object }[] }>
  • Retrieves the number of messaging conversations on Facebook Messenger that began with people who had never messaged with your business before.

    see

    https://developers.facebook.com/docs/messenger-platform/reference/messaging-insights-api#metrics

    example
    await client.getNewConversations();
    // {
    // name: 'page_messages_new_conversations_unique',
    // period: 'day',
    // values: [
    // { value: 1, endTime: '2018-03-12T07:00:00+0000' },
    // { value: 0, endTime: '2018-03-13T07:00:00+0000' },
    // ],
    // title: 'Daily unique new conversations count',
    // description:
    // 'Daily: The number of messaging conversations on Facebook Messenger that began with people who had never messaged with your business before.',
    // id:
    // '1386473101668063/insights/page_messages_new_conversations_unique/day',
    // }

    Parameters

    Returns Promise<{ name: "page_messages_new_conversations_unique"; period: "day"; values: { endTime: string; value: number | object }[] }>

getPageInfo

  • getPageInfo(__namedParameters?: { fields?: string[] }): Promise<PageInfo>

getPageSubscription

getPersistentMenu

getPersona

  • getPersona(personaId: string): Promise<{ id: string; name: string; profilePictureUrl: string }>

getPersonas

  • getPersonas(cursor?: string): Promise<{ data: { id: string; name: string; profilePictureUrl: string }[]; paging: { cursors: { after: string; before: string } } }>
  • Retrieves personas associated with a page using the cursor.

    see

    https://developers.facebook.com/docs/messenger-platform/send-messages/personas/#retrieve_all

    example
    await client.getPersonas(cursor);
    // {
    // "data": [
    // {
    // "name": "John Mathew",
    // "profile_picture_url": "https://facebook.com/john_image.jpg",
    // "id": "<PERSONA_ID>"
    // },
    // {
    // "name": "David Mark",
    // "profile_picture_url": "https://facebook.com/david_image.jpg",
    // "id": "<PERSONA_ID>"
    // }
    // ],
    // "paging": {
    // "cursors": {
    // "before": "QVFIUlMtR2ZATQlRtVUZALUlloV1",
    // "after": "QVFIUkpnMGx0aTNvUjJNVmJUT0Yw"
    // }
    // }
    // }

    Parameters

    • Optional cursor: string

      Pagination cursor.

    Returns Promise<{ data: { id: string; name: string; profilePictureUrl: string }[]; paging: { cursors: { after: string; before: string } } }>

    • Persona data in pagination result

getReportedConversations

  • getReportedConversations(options: InsightOptions): Promise<{ name: "page_messages_reported_conversations_unique"; period: "day"; values: { endTime: string; value: number | object }[] }>

getSecondaryReceivers

  • getSecondaryReceivers(): Promise<{ id: string; name: string }[]>

getSubscriptions

  • Gets the current Webhook subscriptions set up on your app.

    see

    https://developers.facebook.com/docs/graph-api/reference/app/subscriptions

    example
    await client.getSubscriptions({
    accessToken: APP_ACCESS_TOKEN,
    });
    // [{
    // object: 'page',
    // callbackUrl: 'https://www.example.com/callback'
    // fields: ['messages', 'messaging_postbacks', 'messaging_optins'],
    // active: true,
    // }]

    // Or provide app id and app secret instead of app access token:
    await client.getSubscriptions({
    accessToken: `${APP_ID}|${APP_SECRET}`,
    });

    Parameters

    • __namedParameters: { accessToken?: string } = {}
      • Optional accessToken?: string

    Returns Promise<MessengerSubscription[]>

    An array of subscriptions.

getThreadOwner

  • getThreadOwner(recipientId: string): Promise<{ appId: string }>

getTotalMessagingConnections

  • getTotalMessagingConnections(options: InsightOptions): Promise<{ name: "page_messages_total_messaging_connections"; period: "day"; values: { endTime: string; value: number | object }[] }>
  • Retrieves the number of people who have sent a message to your business, not including people who have blocked or reported your business on Messenger. (This number only includes connections made since October 2016.)

    see

    https://developers.facebook.com/docs/messenger-platform/reference/messaging-insights-api#metrics

    example
    await client.getTotalMessagingConnections();
    // {
    // name: 'page_messages_total_messaging_connections',
    // period: 'day',
    // values: [
    // { value: 1000, endTime: '2018-03-12T07:00:00+0000' },
    // { value: 1000, endTime: '2018-03-13T07:00:00+0000' },
    // ],
    // title: 'Messaging connections',
    // description:
    // 'Daily: The number of people who have sent a message to your business, not including people who have blocked or reported your business on Messenger. (This number only includes connections made since October 2016.)',
    // id:
    // '1386473101668063/insights/page_messages_total_messaging_connections/day',
    // }

    Parameters

    Returns Promise<{ name: "page_messages_total_messaging_connections"; period: "day"; values: { endTime: string; value: number | object }[] }>

getUserField

  • getUserField(__namedParameters: { app?: string; appSecret: string; field: string; page?: string; userId: string }): Promise<any>

getUserPersistentMenu

getUserProfile

getWhitelistedDomains

  • getWhitelistedDomains(): Promise<null | string[]>

logCustomEvents

  • logCustomEvents(__namedParameters: { appId: number; events: Record<string, any>[]; pageId: number; pageScopedUserId: string }): Promise<any>

markSeen

passThreadControl

  • passThreadControl(recipientId: string, targetAppId: number, metadata?: string): Promise<{ success: true }>

passThreadControlToPageInbox

  • passThreadControlToPageInbox(recipientId: string, metadata?: string): Promise<{ success: true }>

requestThreadControl

  • requestThreadControl(recipientId: string, metadata?: string): Promise<{ success: true }>

sendAirlineBoardingPassTemplate

  • Sends airline boarding pass template messages to the specified user using the Send API.

    sendAirlineBoardingPassTemplate
    see

    https://developers.facebook.com/docs/messenger-platform/send-messages/template/airline#boarding_pass

    example
    await client.sendAirlineBoardingPassTemplate(RECIPIENT_ID, {
    introMessage: 'You are checked in.',
    locale: 'en_US',
    boardingPass: [
    {
    passengerName: 'SMITH/NICOLAS',
    pnrNumber: 'CG4X7U',
    travelClass: 'business',
    seat: '74J',
    auxiliaryFields: [
    {
    label: 'Terminal',
    value: 'T1',
    },
    {
    label: 'Departure',
    value: '30OCT 19:05',
    },
    ],
    secondaryFields: [
    {
    label: 'Boarding',
    value: '18:30',
    },
    {
    label: 'Gate',
    value: 'D57',
    },
    {
    label: 'Seat',
    value: '74J',
    },
    {
    label: 'Sec.Nr.',
    value: '003',
    },
    ],
    logoImageUrl: 'https://www.example.com/en/logo.png',
    headerImageUrl: 'https://www.example.com/en/fb/header.png',
    qrCode: 'M1SMITH/NICOLAS CG4X7U nawouehgawgnapwi3jfa0wfh',
    aboveBarCodeImageUrl: 'https://www.example.com/en/PLAT.png',
    flightInfo: {
    flightNumber: 'KL0642',
    departureAirport: {
    airportCode: 'JFK',
    city: 'New York',
    terminal: 'T1',
    gate: 'D57',
    },
    arrivalAirport: {
    airportCode: 'AMS',
    city: 'Amsterdam',
    },
    flightSchedule: {
    departureTime: '2016-01-02T19:05',
    arrivalTime: '2016-01-05T17:30',
    },
    },
    },
    ],
    });

    Parameters

    Returns Promise<SendMessageSuccessResponse>

    An object includes recipientId and messageId.

sendAirlineCheckinTemplate

sendAirlineItineraryTemplate

  • Send airline itinerary template messages to the specified user using the Send API.

    sendAirlineItineraryTemplate
    see

    https://developers.facebook.com/docs/messenger-platform/send-messages/template/airline#itinerary

    example
    await client.sendAirlineItineraryTemplate(USER_ID, {
    introMessage: "Here's your flight itinerary.",
    locale: 'en_US',
    pnrNumber: 'ABCDEF',
    passengerInfo: [
    {
    name: 'Farbound Smith Jr',
    ticketNumber: '0741234567890',
    passengerId: 'p001',
    },
    {
    name: 'Nick Jones',
    ticketNumber: '0741234567891',
    passengerId: 'p002',
    },
    ],
    flightInfo: [
    {
    connectionId: 'c001',
    segmentId: 's001',
    flightNumber: 'KL9123',
    aircraftType: 'Boeing 737',
    departureAirport: {
    airportCode: 'SFO',
    city: 'San Francisco',
    terminal: 'T4',
    gate: 'G8',
    },
    arrivalAirport: {
    airportCode: 'SLC',
    city: 'Salt Lake City',
    terminal: 'T4',
    gate: 'G8',
    },
    flightSchedule: {
    departureTime: '2016-01-02T19:45',
    arrivalTime: '2016-01-02T21:20',
    },
    travelClass: 'business',
    },
    ],
    passengerSegmentInfo: [
    {
    segmentId: 's001',
    passengerId: 'p001',
    seat: '12A',
    seatType: 'Business',
    },
    {
    segmentId: 's001',
    passengerId: 'p002',
    seat: '12B',
    seatType: 'Business',
    },
    ],
    priceInfo: [
    {
    title: 'Fuel surcharge',
    amount: '1597',
    currency: 'USD',
    },
    ],
    basePrice: '12206',
    tax: '200',
    totalPrice: '14003',
    currency: 'USD',
    });

    Parameters

    Returns Promise<SendMessageSuccessResponse>

    An object includes recipientId and messageId.

sendAirlineUpdateTemplate

sendAttachment

sendAudio

sendBatch

  • sendBatch(batch: BatchItem[], __namedParameters?: { includeHeaders?: boolean }): Promise<{ body: Record<string, any>; code: number; headers?: { name: string; value: string }[] }[]>

sendButtonTemplate

sendFile

sendGenericTemplate

  • Sends generic template messages to the specified user using the Send API.

    sendGenericTemplate
    see

    https://developers.facebook.com/docs/messenger-platform/send-messages/template/generic

    example
    await client.sendGenericTemplate(
    USER_ID,
    [
    {
    title: "Welcome to Peter's Hats",
    imageUrl: 'https://petersfancybrownhats.com/company_image.png',
    subtitle: "We've got the right hat for everyone.",
    defaultAction: {
    type: 'web_url',
    url: 'https://peterssendreceiveapp.ngrok.io/view?item=103',
    messengerExtensions: true,
    webviewHeightRatio: 'tall',
    fallbackUrl: 'https://peterssendreceiveapp.ngrok.io/',
    },
    buttons: [
    {
    type: 'postback',
    title: 'Start Chatting',
    payload: 'DEVELOPER_DEFINED_PAYLOAD',
    },
    ],
    },
    ],
    { imageAspectRatio: 'square' }
    );

    Parameters

    Returns Promise<SendMessageSuccessResponse>

    An object includes recipientId and messageId.

sendImage

sendMediaTemplate

sendMessage

  • Sends messages to the specified user using the Send API.

    example
    await client.sendMessage(USER_ID, {
    text: 'Hello!',
    });

    You can specify messaging type using options. If messagingType and tag is not provided, UPDATE will be used as default messaging type.

    await client.sendMessage(
    USER_ID,
    { text: 'Hello!' },
    { messagingType: 'RESPONSE' }
    );

    Available messaging types:

    • UPDATE as default
    • RESPONSE using { messagingType: 'RESPONSE' } options
    • MESSAGE_TAG using { tag: 'ANY_TAG' } options

    Parameters

    Returns Promise<SendMessageSuccessResponse>

    An object includes recipientId and messageId.

sendMessageFormData

sendOneTimeNotifReqTemplate

sendRawBody

sendReceiptTemplate

  • Sends receipt template messages to the specified user using the Send API.

    sendReceiptTemplate
    see

    https://developers.facebook.com/docs/messenger-platform/send-messages/template/receipt

    example
    await client.sendReceiptTemplate(USER_ID, {
    recipientName: 'Stephane Crozatier',
    orderNumber: '12345678902',
    currency: 'USD',
    paymentMethod: 'Visa 2345',
    orderUrl: 'http://petersapparel.parseapp.com/order?order_id=123456',
    timestamp: '1428444852',
    elements: [
    {
    title: 'Classic White T-Shirt',
    subtitle: '100% Soft and Luxurious Cotton',
    quantity: 2,
    price: 50,
    currency: 'USD',
    imageUrl: 'http://petersapparel.parseapp.com/img/whiteshirt.png',
    },
    {
    title: 'Classic Gray T-Shirt',
    subtitle: '100% Soft and Luxurious Cotton',
    quantity: 1,
    price: 25,
    currency: 'USD',
    imageUrl: 'http://petersapparel.parseapp.com/img/grayshirt.png',
    },
    ],
    address: {
    street1: '1 Hacker Way',
    street2: '',
    city: 'Menlo Park',
    postalCode: '94025',
    state: 'CA',
    country: 'US',
    },
    summary: {
    subtotal: 75.0,
    shippingCost: 4.95,
    totalTax: 6.19,
    totalCost: 56.14,
    },
    adjustments: [
    {
    name: 'New Customer Discount',
    amount: 20,
    },
    {
    name: '$10 Off Coupon',
    amount: 10,
    },
    ],
    });

    Parameters

    Returns Promise<SendMessageSuccessResponse>

    An object includes recipientId and messageId.

sendSenderAction

sendTemplate

sendText

sendVideo

setAccountLinkingURL

setGetStarted

setGreeting

setIceBreakers

setMessengerProfile

setNLPConfigs

setPersistentMenu

setUserPersistentMenu

setWhitelistedDomains

takeThreadControl

  • takeThreadControl(recipientId: string, metadata?: string): Promise<{ success: true }>

typingOff

typingOn

uploadAttachment

  • uploadAttachment(type: "audio" | "image" | "video" | "file", attachment: string | FileData, options?: UploadOption): Promise<{ attachmentId: string }>
  • Uploads specified attachment using URL address, buffer, or stream.

    see

    https://developers.facebook.com/docs/messenger-platform/reference/attachment-upload-api

    example
    await client.uploadAttachment('image', 'http://www.example.com/image.jpg', { isReusable: true });
    // { attachmentId: "1857777774821032" }

    // Or using read stream:
    const fs = require('fs');
    await client.uploadAttachment('image', fs.createReadStream('image.jpg'), { isReusable: true });

    // Or using buffer:
    await client.uploadAttachment('image', buffer, {
    isReusable: true,
    filename: 'image.jpg',
    });

    Parameters

    • type: "audio" | "image" | "video" | "file"

      Must be one of image, video, audio or file.

    • attachment: string | FileData

      Attachment to be uploaded.

    • options: UploadOption = {}

      Other optional parameters.

    Returns Promise<{ attachmentId: string }>

    An object includes attachment ID

uploadAudio

  • uploadAudio(attachment: string | FileData, options?: UploadOption): Promise<{ attachmentId: string }>
  • example
    await client.uploadAudio('http://www.example.com/audio.mp3', { isReusable: true });

    // Or using read stream:
    const fs = require('fs');
    await client.uploadAudio(fs.createReadStream('audio.mp3'), { isReusable: true });

    // Or using buffer:
    await client.uploadAudio(buffer, {
    isReusable: true,
    filename: 'audio.mp3',
    });

    Parameters

    Returns Promise<{ attachmentId: string }>

    An object includes attachment ID

uploadFile

  • uploadFile(attachment: string | FileData, options?: UploadOption): Promise<{ attachmentId: string }>
  • Uploads file attachment using URL address, buffer, or stream.

    example
    await client.uploadFile('http://www.example.com/file.pdf', { isReusable: true });

    // Or using read stream:
    const fs = require('fs');
    await client.uploadFile(fs.createReadStream('file.pdf'), { isReusable: true });

    // Or using buffer:
    await client.uploadFile(buffer, {
    isReusable: true,
    filename: 'file.pdf',
    });

    Parameters

    Returns Promise<{ attachmentId: string }>

    An object includes attachment ID

uploadImage

  • uploadImage(attachment: string | FileData, options?: UploadOption): Promise<{ attachmentId: string }>
  • Uploads image attachment using URL address, buffer, or stream.

    example
    await client.uploadImage('http://www.example.com/image.jpg', { isReusable: true });

    // Or using read stream:
    const fs = require('fs');
    await client.uploadImage(fs.createReadStream('image.jpg'), { isReusable: true });

    // Or using buffer:
    await client.uploadImage(buffer, {
    isReusable: true,
    filename: 'image.jpg',
    });

    Parameters

    Returns Promise<{ attachmentId: string }>

    An object includes attachment ID

uploadVideo

  • uploadVideo(attachment: string | FileData, options?: UploadOption): Promise<{ attachmentId: string }>
  • Uploads video attachment using URL address, buffer, or stream.

    example
    await client.uploadVideo('http://www.example.com/video.mp4', { isReusable: true });

    // Or using read stream:
    const fs = require('fs');
    await client.uploadVideo(fs.createReadStream('video.mp4'), { isReusable: true });

    // Or using buffer:
    await client.uploadVideo(buffer, {
    isReusable: true,
    filename: 'video.mp4',
    });

    Parameters

    Returns Promise<{ attachmentId: string }>

    An object includes attachment ID

Static connect

Generated using TypeDoc