Options
All
  • Public
  • Public/Protected
  • All
Menu

Module messenger

Messenger Platform

Receive events and send messages through Messenger platform.

Install

npm install @sociably/core @sociably/http @sociably/messenger
# or with yarn
yarn add @sociably/core @sociably/http @sociably/messenger

Docs

Check the platform document and the package reference.

Setup

import Sociably from '@sociably/core';
import Http from '@sociably/http';
import Messenger from '@sociably/messenger';

const {
MESSENGER_PAGE_ID,
MESSENGER_APP_ID,
MESSENGER_ACCESS_TOKEN,
MESSENGER_APP_SECRET,
MESSENGER_VERIFY_TOKEN,
} = process.env;

const app = Sociably.createApp({
modules: [
Http.initModule({ /* ... */ }),
],
platforms: [
Messenger.intiModule({
entryPath: '/webhook/messenger',
pageId: MESSENGER_PAGE_ID,
appSecret: MESSENGER_APP_SECRET,
accessToken: MESSENGER_ACCESS_TOKEN,
verifyToken: MESSENGER_VERIFY_TOKEN,
}),
],
});

Index

Event

Other

BatchApiRequest: { attached_files?: string; body: null | any; depends_on?: string; method: string; name?: string; omit_response_on_success?: boolean; relative_url: string }

Type declaration

  • Optional attached_files?: string
  • body: null | any
  • Optional depends_on?: string
  • method: string
  • Optional name?: string
  • Optional omit_response_on_success?: boolean
  • relative_url: string
CommentPrivateReplyTarget: { comment_id: string }

Type declaration

  • comment_id: string
FbGraphApiResult: Record<string, any>
FileInfo: { contentType?: string; filename?: string; filepath?: string; knownLength?: number }

Type declaration

  • Optional contentType?: string
  • Optional filename?: string
  • Optional filepath?: string
  • Optional knownLength?: number
GraphApiErrorBody: { error: GraphApiErrorInfo }

Type declaration

GraphApiErrorInfo: { code: number; error_subcode: number; fbtrace_id: string; message: string; type: string }

Type declaration

  • code: number
  • error_subcode: number
  • fbtrace_id: string
  • message: string
  • type: string
MessageValue: { [ATTACHMENT_DATA]?: string | Buffer | NodeJS.ReadableStream; [ATTACHMENT_INFO]?: FileInfo; message: RawMessage; messaging_type?: MessagingType; notification_type?: NotificationType; persona_id?: string; tag?: MessageTags }

Type declaration

  • Optional [ATTACHMENT_DATA]?: string | Buffer | NodeJS.ReadableStream
  • Optional [ATTACHMENT_INFO]?: FileInfo
  • message: RawMessage
  • Optional messaging_type?: MessagingType
  • Optional notification_type?: NotificationType
  • Optional persona_id?: string
  • Optional tag?: MessageTags
MessengerComponent<Props, Segment>: NativeComponent<Props, Segment>

Type parameters

MessengerConfigs: { accessToken: string; apiBatchRequestInterval?: number; appSecret?: string; dispatchMiddlewares?: MaybeContainer<MessengerDispatchMiddleware>[]; eventMiddlewares?: MaybeContainer<MessengerEventMiddleware>[]; graphApiVersion?: string; optionalProfileFields?: ("locale" | "timezone" | "gender")[]; pageId: string; shouldHandleChallenge?: boolean; shouldVerifyRequest?: boolean; verifyToken?: string; webhookPath?: string }

Type declaration

  • accessToken: string

    The page access token for the app

  • Optional apiBatchRequestInterval?: number
  • Optional appSecret?: string

    The Facebook app secret

  • Optional dispatchMiddlewares?: MaybeContainer<MessengerDispatchMiddleware>[]
  • Optional eventMiddlewares?: MaybeContainer<MessengerEventMiddleware>[]
  • Optional graphApiVersion?: string

    The graph API version to make API calls

  • Optional optionalProfileFields?: ("locale" | "timezone" | "gender")[]

    Request additional info of user profile. This requires addtional permisions of your app

  • pageId: string

    The Facebook page id

  • Optional shouldHandleChallenge?: boolean

    To handle the webhook challenge request or not. Default to true

  • Optional shouldVerifyRequest?: boolean

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

  • Optional verifyToken?: string

    The secret string to verify the webhook challenge request

  • Optional webhookPath?: string

    The webhook path to receive events. Default to /

MessengerDispatchFrame: DispatchFrame<MessengerChannel, MessengerJob>
MessengerDispatchResponse: DispatchResponse<MessengerJob, MessengerResult>
MessengerEventContext: { bot: MessengerBot; event: MessengerEvent; metadata: WebhookMetadata; platform: "messenger"; reply: any }

Type declaration

MessengerEventMiddleware: EventMiddleware<MessengerEventContext, null>
MessengerJob: { assetTag?: string; fileData?: string | Buffer | NodeJS.ReadableStream; fileInfo?: { contentType?: string; filename?: string; filepath?: string; knownLength?: number }; key?: string; request: BatchApiRequest }

Type declaration

  • Optional assetTag?: string
  • Optional fileData?: string | Buffer | NodeJS.ReadableStream
  • Optional fileInfo?: { contentType?: string; filename?: string; filepath?: string; knownLength?: number }
    • Optional contentType?: string
    • Optional filename?: string
    • Optional filepath?: string
    • Optional knownLength?: number
  • Optional key?: string
  • request: BatchApiRequest
MessengerRawEvent: any
MessengerResult: { body: FbGraphApiResult; code: number; headers: Record<string, string> }

Type declaration

MessengerSendOptions: { messagingType?: MessagingType; notificationType?: NotificationType; oneTimeNotifToken?: string; personaId?: string; tag?: string }

Type declaration

  • Optional messagingType?: MessagingType
  • Optional notificationType?: NotificationType
  • Optional oneTimeNotifToken?: string
  • Optional personaId?: string
  • Optional tag?: string
PSIDTarget: { id: string }

Type declaration

  • id: string
PassThreadControlValue: { [API_PATH]: any; metadata?: string; target_app_id: number }

Type declaration

  • [API_PATH]: any
  • Optional metadata?: string
  • target_app_id: number
PostPrivateReplyTarget: { post_id: string }

Type declaration

  • post_id: string
RawMessage: any
RawUserProfile: { first_name: string; gender?: string; id: string; last_name: string; locale?: string; name: string; profile_pic: string; timezone?: number }

Type declaration

  • first_name: string
  • Optional gender?: string
  • id: string
  • last_name: string
  • Optional locale?: string
  • name: string
  • profile_pic: string
  • Optional timezone?: number
RequestThreadControlValue: { [API_PATH]: any; metadata?: string }

Type declaration

  • [API_PATH]: any
  • Optional metadata?: string
SenderActionValue: { sender_action: "mark_seen" | "typing_on" | "typing_off" }

Type declaration

  • sender_action: "mark_seen" | "typing_on" | "typing_off"
TakeThreadControlValue: RequestThreadControlValue
UserRefTarget: { user_ref: string }

Type declaration

  • user_ref: string
API_PATH: typeof API_PATH = ...
ATTACHMENT_ASSET_TAG: typeof ATTACHMENT_ASSET_TAG = ...
ATTACHMENT_DATA: typeof ATTACHMENT_DATA = ...
ATTACHMENT_INFO: typeof ATTACHMENT_INFO = ...

Generated using TypeDoc