Toolkit for developing applications for the Messenger platform written in TypeScript.
- follow the original API as closely as possible and provide type information
- de-couple server (for receiving webhooks), client (for sending messages etc) and message builder parts (POJO)
- full support for Send API, message received events, messaging_postbacks (not fully implemented yet)
- helpers to de-duplicate and queue messages
- the support for the rest of APIs if required
To interact with the messenger platform you require a fb app connected to a page. Set up a webhook connecting the page with your server. To install the module:
npm i typed-messenger-platform
;;;;// initial configuration is passed via createServer.createServer// handle messages of specific types with .onTextMessage, .onLocationMessage etc.onTextMessage,;// call .done to get node http compatible handlerhttp.createServerfbServer.done.listen3000;// monitor errors asynchronouslyfbServer.on'error',
Message builder interface allows chaining calls to build a message:
messageTorecipient.text'Answer the question: Where is Berlin?'.quickTextReply'Germany', 'GER'.quickLocationReply;
Also see examples.
The following message handlers (
on[MessageType]Message) are available:
- onTextMessage - fired if the message contains text
- onLocationMessage - fired if the message contains a location attachment
- onAudioMessage - fired if the message contains an audio attachment
- onVideoMessage - fired if the message contains a video attachment
- onFileMessage - fired if the message contains a file attachment
- onImageMessage - fired if the message contains a image attachment
- onUnknownMessage - fired for every message of unknown type
- onAnyMesage - fired for every message of known type
The messages are evaluated in order and only one of the handlers is called for any given message, the one that matches first. Exceptions are onAnyMesage which is fired always for any message of known type (even if a more specific handlers were already called) and onUnknownMessage which is called for every message of unknown type.