Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions lambdas/account-scoped/src/conference/getParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import { AccountScopedHandler } from '../httpTypes';
import { newMissingParameterResult } from '../httpErrors';
import { getTwilioClient } from '@tech-matters/twilio-configuration';
import { newOk } from '../Result';
import { newErr, newOk } from '../Result';
import type RestException from 'twilio/lib/base/RestException';

export type Body = {
callSid: string;
Expand All @@ -34,10 +35,26 @@ export const getParticipantHandler: AccountScopedHandler = async (
if (!callSid) return newMissingParameterResult('callSid');
if (!conferenceSid) return newMissingParameterResult('conferenceSid');
const client = await getTwilioClient(accountSid);
const participant = await client.conferences
.get(conferenceSid)
.participants.get(callSid)
.fetch();

return newOk({ participant });
try {
const participant = await client.conferences
.get(conferenceSid)
.participants.get(callSid)
.fetch();
return newOk({ participant });
} catch (error) {
const restError = error as RestException;
if (restError.status === 404) {
const message = `Participant with call sid ${callSid} not found on ${accountSid}/${conferenceSid}`;
// Often errors of this type are thrown but the recording appears to pause at the correct point.
console.warn(message, error);
return newErr({
message,
error: {
cause: restError,
statusCode: 404,
},
});
}
throw error;
}
};
31 changes: 24 additions & 7 deletions lambdas/account-scoped/src/conference/removeParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

import { AccountScopedHandler } from '../httpTypes';
import { getTwilioClient } from '@tech-matters/twilio-configuration';
import { newOk } from '../Result';
import { newErr, newOk } from '../Result';
import { newMissingParameterResult } from '../httpErrors';
import type RestException from 'twilio/lib/base/RestException';

export type Body = {
callSid: string;
Expand All @@ -35,10 +36,26 @@ export const removeParticipantHandler: AccountScopedHandler = async (
if (!conferenceSid) return newMissingParameterResult('conferenceSid');

const client = await getTwilioClient(accountSid);
const participantRemoved = await client
.conferences(conferenceSid)
.participants(callSid)
.remove();

return newOk({ message: `Participant removed: ${participantRemoved}` });
try {
const participantRemoved = await client
.conferences(conferenceSid)
.participants(callSid)
.remove();
return newOk({ message: `Participant removed: ${participantRemoved}` });
} catch (error) {
const restError = error as RestException;
if (restError.status === 404) {
const message = `Participant with call sid ${callSid} not found on ${accountSid}/${conferenceSid}`;
// Often errors of this type are thrown but the recording appears to pause at the correct point.
console.warn(message, error);
return newErr({
message,
error: {
cause: restError,
statusCode: 404,
},
});
}
throw error;
}
};
23 changes: 20 additions & 3 deletions lambdas/account-scoped/src/conference/updateParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import { AccountScopedHandler } from '../httpTypes';
import { newMissingParameterResult } from '../httpErrors';
import { getTwilioClient } from '@tech-matters/twilio-configuration';
import { newOk } from '../Result';
import { newErr, newOk } from '../Result';
import type RestException from 'twilio/lib/base/RestException';

const validUpdates = ['endConferenceOnExit', 'hold', 'muted'] as const;

Expand Down Expand Up @@ -56,8 +57,24 @@ export const updateParticipantHandler: AccountScopedHandler = async (
.conferences(conferenceSid)
.participants(callSid)
.fetch();

await participant.update(parsedUpdates);
try {
await participant.update(parsedUpdates);
} catch (error) {
const restError = error as RestException;
if (restError.status === 404) {
const message = `Participant with call sid ${callSid} not found on ${accountSid}/${conferenceSid}`;
// Often errors of this type are thrown but the recording appears to pause at the correct point.
console.warn(message, error);
return newErr({
message,
error: {
cause: restError,
statusCode: 404,
},
});
}
throw error;
}

return newOk({ message: `Participant updated: ${updates}` });
};
Loading