Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Commit

Permalink
Merge branch 'patch-messages'
Browse files Browse the repository at this point in the history
  • Loading branch information
avbel committed May 3, 2018
2 parents 3bd91e9 + 5bc2f43 commit cec4332
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
16 changes: 16 additions & 0 deletions docs/api.md
Expand Up @@ -2730,6 +2730,7 @@ Remove a media file
* [.send(params, [callback])](#Message+send) ⇒ <code>[MessageResponse](#MessageResponse)</code>
* [.sendMultiple(params, [callback])](#Message+sendMultiple) ⇒ <code>[ExtendedMessageResponse](#ExtendedMessageResponse)</code>
* [.get(messageId, [callback])](#Message+get) ⇒ <code>[MessageResponse](#MessageResponse)</code>
* [.patch(messageId, data, [callback])](#Message+patch) ⇒ <code>Promise</code>
* [.list(params, [callback])](#Message+list) ⇒ <code>[MessageListResponse](#MessageListResponse)</code>

<a name="new_Message_new"></a>
Expand Down Expand Up @@ -2863,6 +2864,21 @@ Get a message
| messageId | <code>String</code> | The ID of the message to get |
| [callback] | <code>function</code> | A callback for the message |

<a name="Message+patch"></a>

### message.patch(messageId, data, [callback]) ⇒ <code>Promise</code>
Redact the text of a previously sent message

**Kind**: instance method of <code>[Message](#Message)</code>
**Returns**: <code>Promise</code> - A promise for the message

| Param | Type | Description |
| --- | --- | --- |
| messageId | <code>String</code> | The ID of the message to patch |
| data | <code>Object</code> | data to patch (only text is supported now) |
| data.text | <code>Object</code> | the contents of the text must be the empty string (""). Any other value will fail. |
| [callback] | <code>function</code> | A callback for the message |

<a name="Message+list"></a>

### message.list(params, [callback]) ⇒ <code>[MessageListResponse](#MessageListResponse)</code>
Expand Down
17 changes: 17 additions & 0 deletions lib/message.js
Expand Up @@ -178,6 +178,23 @@ var Message = function (client) {
.asCallback(callback);
};

/**
* Redact the text of a previously sent message
* @param {String} messageId The ID of the message to patch
* @param {Object} data data to patch (only text is supported now)
* @param {Object} data.text the contents of the text must be the empty string (""). Any other value will fail.
* @param {Function} [callback] A callback for the message
* @return {Promise} A promise for the message
*/
this.patch = function (messageId, data, callback) {
return client.makeRequest({
path : "messages/" + messageId,
method : "PATCH",
body : data
})
.asCallback(callback);
};

/**
* Gets a list of messages
* @param {Object} params Search parameters
Expand Down
12 changes: 11 additions & 1 deletion test/message-test.js
Expand Up @@ -91,7 +91,9 @@ describe("Message API", function () {
.get("/v1/users/" + userId + "/messages/" + testMessage.id)
.reply(200, testMessage)
.get("/v1/users/" + userId + "/messages?fromDateTime=" + fromDateTime + "&" + "toDateTime=" + toDateTime)
.reply(200, messagesList);
.reply(200, messagesList)
.patch("/v1/users/" + userId + "/messages/" + testMessage.id, { text : "" })
.reply(200);
});

after(function () {
Expand Down Expand Up @@ -172,6 +174,14 @@ describe("Message API", function () {
done();
});
});

it("should patch a message, promise style", function () {
return client.Message.patch(testMessage.id, { text : "" });
});

it("should patch a message, callback style", function (done) {
return client.Message.patch(testMessage.id, { text : "" }, done);
});
});

describe("list function with a multiple page response", function () {
Expand Down

0 comments on commit cec4332

Please sign in to comment.