diff --git a/README.md b/README.md index dd6977b..c7bd575 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ zulip.callEndpoint('/messages', 'POST', params); | `zulip.messages.update()` | PATCH `/messages/` | updates the content or topic of the message with the given `msg_id`. | | `zulip.messages.flags.add()` | POST `/messages/flags` | add a flag to a list of messages. Its params are `flag` which is one of `[read, starred, mentioned, wildcard_mentioned, has_alert_word, historical]` and `messages` which is a list of messageIDs. | | `zulip.messages.flags.remove()` | POST `/messages/flags` | remove a flag from a list of messages. Its params are `flag` which is one of `[read, starred, mentioned, wildcard_mentioned, has_alert_word, historical]` and `messages` which is a list of messageIDs. | +| `zulip.messages.getById()` | GET `/messages/` | returns a message by its id. | | `zulip.queues.register()` | POST `/register` | registers a new queue. You can pass it a params object with the types of events you are interested in and whether you want to receive raw text or html (using markdown). | | `zulip.queues.deregister()` | DELETE `/events` | deletes a previously registered queue. | | `zulip.reactions.add()` | POST `/reactions` | add a reaction to a message. Accepts a params object with `message_id`, `emoji_name`, `emoji_code` and `reaction_type` (default is `unicode_emoji`). | diff --git a/examples/messages.js b/examples/messages.js index b421cbc..6014686 100644 --- a/examples/messages.js +++ b/examples/messages.js @@ -59,3 +59,10 @@ zulip(config).then((z) => { }); }).then(res => console.log(res.messages)); }).catch(err => console.log(err.message)); + +zulip(config).then((z) => { + const readParams = { + message_id: 1, + }; + z.messages.getById(readParams).then(console.log); +}).catch(err => console.log(err.message)); diff --git a/src/resources/messages.js b/src/resources/messages.js index e2274f7..0fef762 100644 --- a/src/resources/messages.js +++ b/src/resources/messages.js @@ -52,6 +52,10 @@ function messages(config) { return api(flagsURL, config, 'POST', params); }, }, + getById: (params) => { + const url = `${config.apiURL}/messages/${params.message_id}`; + return api(url, config, 'GET', params); + }, }; } diff --git a/test/resources/messages.js b/test/resources/messages.js index c8fc42c..07df218 100644 --- a/test/resources/messages.js +++ b/test/resources/messages.js @@ -121,6 +121,28 @@ describe('Messages', () => { }).catch(done); }); + it('should get message by id', (done) => { + const params = { + message_id: 1, + }; + const validator = (url, options) => { + url.should.contain(`${common.config.apiURL}/messages/1`); + options.should.not.have.property('body'); + options.method.should.be.equal('GET'); + }; + const output = { + msg: '', + result: 'success', + }; + const stubs = common.getStubs(validator, output); + messages(common.config).getById(params) + .then((data) => { + data.should.have.property('result', 'success'); + common.restoreStubs(stubs); + done(); + }).catch(done); + }); + it('should mark message as read', (done) => { const params = { flag: 'read',