Matrix Application Service framework in Node.js
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Add set/getProtocols (#9) Feb 28, 2017
.eslintrc Add helper functions to AppServiceRegistration Sep 1, 2015
.gitignore Add helper functions to AppServiceRegistration Sep 1, 2015
.jshint Add JSDoc support. Add more JSDoc Aug 11, 2015
LICENSE Initial commit Feb 27, 2015 Add set/getProtocols (#9) Feb 28, 2017
index.js Completely redo the API Aug 7, 2015

This is a Matrix Application Service framework written in Node.js.

This can be used to quickly setup performant application services for almost anything you can think of in a web framework agnostic way.

To create an app service registration file:

var AppServiceRegistration = require("matrix-appservice").AppServiceRegistration;

// creating registration files
var reg = new AppServiceRegistration();
reg.addRegexPattern("users", "@.*", true);
reg.setProtocols(["exampleservice"]); // For 3PID lookups

You only need to generate a registration once, provided the registration info does not change. Once you have generated a registration, you can run the app service like so:

var AppService = require("matrix-appservice").AppService;
// listening
var as = new AppService({
  homeserverToken: "abcd653bac492087d3c87"
as.on("", function(event) {
  // handle the incoming message
as.onUserQuery = function(userId, callback) {
  // handle the incoming user query then respond
  console.log("RECV %s", userId);
// can also do this as a promise
as.onAliasQuery = function(alias) {
    // Needs a promise lib e.g.  var q = require("q");
    var defer = q.defer();
    // do stuff
    return defer.promise;

TLS Connections

If MATRIX_AS_TLS_KEY and MATRIX_AS_TLS_CERT environment variables are defined and point to valid tls key and cert files, the AS will listen using an HTTPS listener.

API Reference

A hosted API reference can be found on GitHub Pages.