zulip-node
v1.0.1
Published
Node bindings for Zulip API
Downloads
8
Readme
zulip-node
Zulip API bindings for node.js. Includes most of the available API calls, though the API docs from Zulip are quite sparse.
Available API docs are here
Example
Here's an example of registering a queue and polling for messages:
var zulip = require('zulip-node'),
client = new zulip(process.env.ZULIP_EMAIL, process.env.ZULIP_API_KEY);
client.registerQueue({
event_types: ['message']
}, true);
client.on('registered', function() {
console.log('registered');
})
.on('message', function(msg) {
// only message events will be received here
})
.on('event', function(evt) {
// all queue events will be received here
})
.on('error', function(err) {
console.error(err);
});
Credit
This project was forked from paulvstheworld/zulip-node.
#class: Client Client constructor
Members
- class: Client
- new Client(email, apiKey)
- client.sendMessage(opts, [callback])
- client.sendStreamMessage(opts, callback)
- client.sendPrivateMessage(opts, callback)
- client.registerQueue(opts, [watch], [watchOpts])
- client.deregisterQueue(queueId, [callback])
- client.getUsers(callback)
- client.getEvents([watchOpts])
- client.getStreams(callback)
- client.getSubscriptions(callback)
- client.updateSubscriptions(opts, [callback])
- client.me(callback)
- client.setPresence(presence, [callback])
- client.getStreamMembers(stream, callback)
- client.updateMessage(opts, [callback])
- event: "registered"
- event: "error"
- event: "event"
- event: "message"
- event: "presence"
##new Client(email, apiKey) Params
- email
string
- Zulip account address - apiKey
string
- Zulip API key
##client.sendMessage(opts, [callback]) Send a message
Params
- opts
Object
- Message options per https://zulip.com/api/endpoints/- type
String
- One of {private, stream} - content
String
- The content of the message. Maximum message size of 10000 bytes. - to
String
- In the case of a stream message, a string identifying the stream. In the case of a private message, a JSON-encoded list containing the usernames of the recipients. - subject
String
- The topic for the message (Only required if type is “stream”). Maximum length of 60 characters.
- type
- [callback]
function
- Optional callback function with (err, results) params
##client.sendStreamMessage(opts, callback) Send a stream message
Params
- opts
Object
- Message options per https://zulip.com/api/endpoints/- content
String
- The content of the message. Maximum message size of 10000 bytes - to
String
- A string identifying the stream. - subject
String
- The topic for the message. Maximum length of 60 characters.
- content
- callback
function
- Optional callback function with (err, results) params
##client.sendPrivateMessage(opts, callback) Send a private message
Params
- opts
Object
- Message options per https://zulip.com/api/endpoints/- content
String
- The content of the mssage. Maximum message size of 10000 bytes. - to
String
- A JSON-encoded list containing the usernames of the recipients.
- content
- callback
function
- Optional callback function with (err, results) params
##client.registerQueue(opts, [watch], [watchOpts]) Register to receive Zulip events
Params
- opts
Object
- Register options per https://zulip.com/api/endpoints/- [event_types=all]
Array
- A JSON-encoded array indicating which types of events you're interested in. Values include message, subscriptions, realm_user, pointer - [apply_markdown=false]
Boolean
- Set to “true” if you would like the content to be rendered in HTML format
- [event_types=all]
- [watch=false]
Boolean
- If true, will automatically poll for events - [watchOpts]
Object
- Optional set of options to be passed to getEvents while polling
##client.deregisterQueue(queueId, [callback]) Deregisters from a queue
Params
- queueId
String
- Queue ID - [callback]
function
- Optional callback with (err, response)
##client.getUsers(callback) Gets a list of all Zulip users in the realm
Params
- callback
function
- Callback function with (err, users) params
##client.getEvents([watchOpts]) Gets events from the subscribed queue
Params
- [watchOpts]
Object
- Optional set of options to override defaults- [queueId=this.queueId]
String
- The ID of a queue that you registered via registerQueue(). - [lastEventId=this.lastEventId]
String
- The highest event ID in this queue that you've received and wish to acknowledge. - [dontBlock=false]
String
- set to “true” if the client is requesting a nonblocking reply. If not specified, the request will block until either a new event is available or a few minutes have passed, in which case the server will send the client a heartbeat event.
- [queueId=this.queueId]
##client.getStreams(callback) Gets a list of all public streams
Params
- callback
function
- Callback function with (err, streams) properties
##client.getSubscriptions(callback) List stream subscriptions
Params
- callback
function
- Callback with (err, subscriptions)
##client.updateSubscriptions(opts, [callback]) Adds or removes stream subscriptions
Params
- opts
Object
- Object containing subscription additions and deletions- additions
Array
- Array of streams to subscribe to - deletions
Array
- Array of streams to unsubscribe from
- additions
- [callback]
function
- Optional callback with (err, response)
##client.me(callback) Gets profile information such as max_message_id, pointer, and client_id
Params
- callback
function
- Callback with (err, response)
##client.setPresence(presence, [callback]) Sets presence state
Params
- presence
String
- Valid values include 'idle' and 'active'. There may be more but they are missing from the API docs - [callback]
function
- Optional callback with (err, allPresences)
##client.getStreamMembers(stream, callback) List members of a stream
Params
- stream
String
- Name of stream - callback
function
- Callback with (err, members)
##client.updateMessage(opts, [callback]) Updates a message subject or content
Params
- opts
Object
- Object of update options- message_id
String
|Number
- Zulip message ID - [subject]
String
- New message subject - [content]
String
- New message content
- message_id
- [callback]
function
- Optional callback with (err, response)
##event: "registered" Properties
- response
Object
- Contains the response from the Zulip API
##event: "error" Properties
- err
Object
|String
- Either an object returned from another call or a description of the error
##event: "event" Properties
- event
Object
- Contains all details of an event received from Zulip
##event: "message" Properties
- message
Object
- Contains message details
##event: "presence" Properties
- event
Object
- Contains presence event details