Skip to content

Commit

Permalink
Merge pull request #69 from twilio-labs/add-conversations-timers
Browse files Browse the repository at this point in the history
Add conversations timers
  • Loading branch information
timmydoza authored Mar 30, 2021
2 parents d875a5f + 69391c9 commit 2c55246
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/serverless/functions/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion test/serverless/functions/token.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down

0 comments on commit 2c55246

Please sign in to comment.