diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b23201..80280c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.8.1 + +### Enhancement + +- Specified a timer when creating a Twilio Conversation. This will automatically close the conversation after 24 hours, which is equal to the maximum duration of a video room. This helps to clean up old conversations since there is a limit that a single participant can not be added to more than 1,000 open conversations. + ## 0.8.0 ### New Features diff --git a/src/serverless/functions/token.js b/src/serverless/functions/token.js index badf27c..3c1db55 100644 --- a/src/serverless/functions/token.js +++ b/src/serverless/functions/token.js @@ -93,7 +93,10 @@ module.exports.handler = async (context, event, callback) => { } catch (e) { try { // If conversation doesn't exist, create it. - await conversationsClient.conversations.create({ uniqueName: room.sid }); + // Here we add a timer to close the conversation after the maximum length of a room (24 hours). + // This helps to clean up old conversations since there is a limit that a single participant + // can not be added to more than 1,000 open conversations. + await conversationsClient.conversations.create({ uniqueName: room.sid, 'timers.closed': 'P1D' }); } catch (e) { response.setStatusCode(500); response.setBody({ diff --git a/test/serverless/functions/token.test.js b/test/serverless/functions/token.test.js index c512294..82cc15b 100644 --- a/test/serverless/functions/token.test.js +++ b/test/serverless/functions/token.test.js @@ -59,7 +59,7 @@ describe('the video-token-server', () => { ); expect(mockFns.createRoom).toHaveBeenCalledWith({ type: 'group', uniqueName: 'test-room' }); - expect(mockFns.createConversation).toHaveBeenCalledWith({ uniqueName: 'mockNewRoomSid' }); + expect(mockFns.createConversation).toHaveBeenCalledWith({ uniqueName: 'mockNewRoomSid', 'timers.closed': 'P1D' }); expect(callback).toHaveBeenCalledWith(null, { body: { token: expect.any(String), room_type: 'group' }, headers: { 'Content-Type': 'application/json' },