Client/Server for FB messenger platform written in TypeScript
Last updated 3 years ago by orkon .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install typed-messenger-platform 
SYNC missed versions from official npm registry.


Toolkit for developing applications for the Messenger platform written in TypeScript.


In active development. Feel free to open an issue if you would like to contribute or check out existing issues.


  • 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)



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


Echo bot:

import http = require('http');
import * as platform from 'typed-messenger-platform';


const { sendMessage, messageTo } = platform;

const fbServer = platform
  // initial configuration is passed via createServer
    verificationToken: 'YOUR TOKEN',
  // handle messages of specific types with .onTextMessage, .onLocationMessage etc
    async (testMessage: platform.webhookApi.MessageReceivedEvent) => {
      // decide
      // - when to construct a message (with the builder interface `messageTo`)
      // - when to actually send a message (with `sendMessage` call)
      // - whether to process synchronously or concurrently (with await)
      await sendMessage(
          testMessage.message.text || 'No message',

// call .done to get node http compatible handler

// monitor errors asynchronously
fbServer.on('error', (err: Error) => {
  console.log('error', err);

Message builder interface allows chaining calls to build a message:

  .text('Answer the question: Where is Berlin?')
  .quickTextReply('Germany', 'GER')

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.



Current Tags

  • 0.3.1                                ...           latest (3 years ago)

4 Versions

  • 0.3.1                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (4)
Dev Dependencies (12)
Dependents (0)

Copyright 2014 - 2017 © taobao.org |