diff --git a/packages/rocketchat-api/server/v1/channels.js b/packages/rocketchat-api/server/v1/channels.js index c8dd2905385c7..dbd37c209e521 100644 --- a/packages/rocketchat-api/server/v1/channels.js +++ b/packages/rocketchat-api/server/v1/channels.js @@ -747,6 +747,24 @@ RocketChat.API.v1.addRoute('channels.setTopic', { authRequired: true }, { } }); +RocketChat.API.v1.addRoute('channels.setAnnouncement', { authRequired: true }, { + post() { + if (!this.bodyParams.announcement || !this.bodyParams.announcement.trim()) { + return RocketChat.API.v1.failure('The bodyParam "announcement" is required'); + } + + const findResult = findChannelByIdOrName({ params: this.requestParams() }); + + Meteor.runAsUser(this.userId, () => { + Meteor.call('saveRoomSettings', findResult._id, 'roomAnnouncement', this.bodyParams.announcement); + }); + + return RocketChat.API.v1.success({ + announcement: this.bodyParams.announcement + }); + } +}); + RocketChat.API.v1.addRoute('channels.setType', { authRequired: true }, { post() { if (!this.bodyParams.type || !this.bodyParams.type.trim()) { diff --git a/tests/end-to-end/api/02-channels.js b/tests/end-to-end/api/02-channels.js index 784263e7b8ce0..c46a319c5ef62 100644 --- a/tests/end-to-end/api/02-channels.js +++ b/tests/end-to-end/api/02-channels.js @@ -231,6 +231,22 @@ describe('[Channels]', function() { .end(done); }); + it('/channels.setAnnouncement', (done) => { + request.post(api('channels.setAnnouncement')) + .set(credentials) + .send({ + roomId: channel._id, + announcement: 'this is an announcement of a channel for api tests' + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.nested.property('announcement', 'this is an announcement of a channel for api tests'); + }) + .end(done); + }); + it('/channels.setPurpose', (done) => { request.post(api('channels.setPurpose')) .set(credentials)