Skip to content

Commit e8edcbb

Browse files
committed
getActiveProxyAddresses ignores closed conversations
1 parent e9eb373 commit e8edcbb

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/services/session.service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ export const getActiveProxyAddresses = async (phoneNumbers: Array<String>) : Pro
55
const activeConversations = {}
66

77
const promises = phoneNumbers.map(async (phoneNumber: string) => {
8+
// listParticipantConversations returns ALL conversations, closed and active.
89
const participantConversations = await listParticipantConversations(phoneNumber)
910

10-
const proxyAddresses = participantConversations.map((participant) => {
11+
// We want to ignore closed conversations since we cant use conversations once they're closed.
12+
// We can use conversations that are active or inactive
13+
const participantActiveConversations = participantConversations.filter((participant) => {
14+
return participant.conversationState !== 'closed'
15+
})
16+
// Let's get all the proxy addresses that currently being used in the active conversations
17+
const proxyAddresses = participantActiveConversations.map((participant) => {
1118
return participant.participantMessagingBinding.proxy_address
1219
})
1320

tests/services/session.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('session service', () => {
2020
mockedListParticipantConversations.mockResolvedValue(mockListParticipantsResponse as any)
2121
const result = await getActiveProxyAddresses(['+1112223333', '+2223334444'])
2222

23-
expect(result).toEqual({ '+1112223333': ['+3334445555', '+4445556666'], '+2223334444': ['+3334445555', '+4445556666'] })
23+
expect(result).toEqual({ '+1112223333': ['+3334445555', '+3334449999', '+4445556666'], '+2223334444': ['+3334445555', '+3334449999', '+4445556666'] })
2424
})
2525

2626
it('returns key with empty array if no active conversations', async () => {

tests/support/testSupport.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,48 @@ export const mockListParticipantsResponse = [{
1919
},
2020
participantSid: 'MB2d794fc4f4af4ee49ddcc1bdd8be6b94',
2121
participantUserSid: null
22+
}, {
23+
accountSid: 'ACXXX',
24+
chatServiceSid: 'ISXXX',
25+
conversationState: 'inactive',
26+
conversationTimers: {},
27+
conversationUniqueName: null,
28+
links: {
29+
conversation: 'https://conversations.twilio.com/v1/Conversations/CH82681a28cddf4475afda30a2d94d9b29',
30+
participant: 'https://conversations.twilio.com/v1/Conversations/CH82681a28cddf4475afda30a2d94d9b29/Participants/MB2d794fc4f4af4ee49ddcc1bdd8be6b94'
31+
},
32+
participantIdentity: null,
33+
participantMessagingBinding: {
34+
name: null,
35+
level: null,
36+
type: 'sms',
37+
proxy_address: '+3334449999',
38+
address: '+2223334444',
39+
projected_address: null
40+
},
41+
participantSid: 'MB2d794fc4f4af4ee49ddcc1bdd8be6b94',
42+
participantUserSid: null
43+
}, {
44+
accountSid: 'ACXXX',
45+
chatServiceSid: 'ISXXX',
46+
conversationState: 'closed',
47+
conversationTimers: {},
48+
conversationUniqueName: null,
49+
links: {
50+
conversation: 'https://conversations.twilio.com/v1/Conversations/CH82681a28cddf4475afda30a2d94d9b29',
51+
participant: 'https://conversations.twilio.com/v1/Conversations/CH82681a28cddf4475afda30a2d94d9b29/Participants/MB2d794fc4f4af4ee49ddcc1bdd8be6b94'
52+
},
53+
participantIdentity: null,
54+
participantMessagingBinding: {
55+
name: null,
56+
level: null,
57+
type: 'sms',
58+
proxy_address: '+3334445555',
59+
address: '+2223334444',
60+
projected_address: null
61+
},
62+
participantSid: 'MB2d794fc4f4af4ee49ddcc1bdd8be6b94',
63+
participantUserSid: null
2264
}, {
2365
accountSid: 'ACXXX',
2466
chatServiceSid: 'ISXXX',

0 commit comments

Comments
 (0)