facebook-send-api
Typescript & promise based module for facebook's messenger send api.
Currently used in production by fynd.me for fyndbot.
Installation
npm install --save facebook-send-api
Thread Settings
;;;;;;; FBPlatform.setGreetingText'hello';FBPlatform.setGetStartedPostbackGET_STARTED_POSTBACK;FBPlatform.setPersistentMenu;
Usage
;;;;;; // a simple text message of 'hello'FBPlatform.sendTextMessagesender.id, 'hello' .then .catch; // a button message with 3 buttons using both an object and the libraries helper functionsFBPlatform.sendButtonMessagesender.id, 'title', ; //a generic template messageFBPlatform.sendGenericMessagesender.id, ; // a set of quick reply buttonsFBPlatform.sendQuickRepliessender.id, 'Which of these?', ; // sender actionsFBPlatform.sendSenderActionsender.id, 'mark_seen';FBPlatform.sendReadReceiptsender.id;FBPlatform.sendTypingIndicatorssender.id;FBPlatform.sendCancelTypingIndicatorssender.id;
Chained usage
;;;;;; FBPlatform.createTextMessagesender.id .text'hello' .send; FBPlatform.createButtonMessagesender.id .title'title'; .postbackButton'reset', RESET_SEARCH .postbackButton'cancel', RESET_CANEL .send; FBPlatform.createGenericMessagesender.id .elementnew FBElement.title'1'.subtitle'first'.image'https://www.com/1.jpg' .elementnew FBElement.title'2'.subtitle'second'.image'https://www.com/2.jpg' .send;
FAQ
On my local machine, nothing is being sent to Facebook
By default if NODE_ENV is set to 'development', the library will log the request and return a dummy response so as not to spam the FB messenger platform. You can enable sending in development mode using the turnOnSendingInDevelopment()
method.
Some of my arrays are being truncated
The library automatically truncates arrays to match the limits of the facebook platform as of July 26, 2016. If you want to change these you can set the class variables maxElements
, maxButtons
, maxQuickReplies
to the new maximumums or do a pull request! You can enable throwing an error instead of truncating using the turnOnValidation()
method.