0.0.6 • Published 5 years ago
@immail/realtime-api v0.0.6
imMail Web API
The @immail/realtime-api
lib contains an easy and customizable HTTP client for using Real-time API.
Use it to emit or listen real-time events from imMail.
Installation
$ npm install @immail/realtime-api
Usage
These example shows one of the most common features of the RTMClient
.
Initialize the client
The package exports a RTMClient
class. All you need to do is instantiate it, and you're ready to go. You'll typically
initialize it with a { host, authToken }
. If you do not provide a host, the default one (https://app.immail.ca) will be defined.
const { WebClient } = require('@immail/web-api');
const { RTMClient } = require('@immail/realtime-api');
// Read a host from the environment variables
const apiHost = process.env.IMMAIL_API_HOST // Optional. Usefull for on-premise versions. The imMail's production host will be set as default
const rtmHost = process.env.IMMAIL_RTM_HOST // Optional. Usefull for on-premise versions. The imMail's production host will be set as default
const login = process.env.IMMAIL_LOGIN
const password = process.env.IMMAIL_PASSWORD
// Log in using the WebClient library first of all
const webImmail = new WebClient({ host: apiHost })
const { token } = await immail.login({ login, password })
// Take the token from login and initialize
const rtmImmail = new RTMClient({ host: rtmHost, authToken: token })
// Connect
rtmImmail.connect()
/**
* Alternatively you can use
* rtmImmail.connect(token)
* /