Matrix JS SDK
The Matrix JavaScript SDK is the official wrapper of the Matrix 'restful' HTTP API for the JavaScript/Node ecosystem.
It is compatible with NodeJS and browser based JS, is used by Matrix React SDK, Polite.ai and others.
Installation
NodeJS
> npm i --save matrix-js-sdk
Browsers
<script src=''>Coming Soon (sorry)</script>
Sending a message
const sdk = require('matrix-js-sdk');
const roomId = '!QalgtPGHgcjJQAeYId:matrix.org'; // Matrix JS SDK Docs Room
const client = sdk.createClient({
baseUrl: 'https://matrix.org',
userId: '@USERNAMEHERE:matrix.org',
accessToken: 'ACCESSTOKENHERE' // See https://reeve.xyz/getting-started-with-matrix-bots-on-nodejs/
});
client.joinRoom(roomId) // Join Matrix JS SDK Room and send a message
.error(function (err) {
console.error('Failed to join room', err);
})
.done(function (room) {
console.info('Joined room: [%s]', room.roomId);
client.sendTextMessage(roomId, 'Hello from a simple Node Matrix bot');
});