Skip to content

Commit

Permalink
feat: update open api
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Oct 17, 2024
1 parent c63222d commit c6a1c82
Show file tree
Hide file tree
Showing 8 changed files with 1,481 additions and 340 deletions.
29 changes: 29 additions & 0 deletions __tests__/call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,35 @@ describe('call API', () => {
});
});

it('closed caption settings', async () => {
const response = await call.update({
settings_override: {
transcription: {
mode: 'available',
closed_caption_mode: 'disabled',
},
},
});

expect(response.call.settings.transcription.mode).toBe('available');
expect(response.call.settings.transcription.closed_caption_mode).toBe(
'disabled',
);
expect(response.call.captioning).toBe(false);

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-bun

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-bun

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-bun

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-bun

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (18)

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (18)

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (18)

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (18)

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (20)

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (20)

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (20)

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (20)

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (22)

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (22)

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (22)

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38

Check failure on line 270 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (22)

__tests__/call.test.ts > call API > closed caption settings

AssertionError: expected undefined to be false // Object.is equality - Expected: false + Received: undefined ❯ __tests__/call.test.ts:270:38
});

it('should start-stop closed captions', async () => {
// somewhat dummy test, we should do a proper test in the future where we join a call and start recording
await expect(() => call.startClosedCaptions()).rejects.toThrowError(

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-bun

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-bun

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-bun

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-bun

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (18)

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (18)

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (18)

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (18)

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (20)

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (20)

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (20)

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (20)

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (22)

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (22)

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (22)

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5

Check failure on line 275 in __tests__/call.test.ts

View workflow job for this annotation

GitHub Actions / test-node (22)

__tests__/call.test.ts > call API > should start-stop closed captions

AssertionError: expected [Function] to throw error including 'Stream error code 4: StartClosedCapti…' but got 'Stream error code 16: Request failed …' - Expected + Received - Stream error code 4: StartClosedCaptions failed with error: "there is no active session" + Stream error code 16: Request failed with error: "Not Found" ❯ __tests__/call.test.ts:275:5
'Stream error code 4: StartClosedCaptions failed with error: "there is no active session"',
);

// somewhat dummy test, we should do a proper test in the future where we join a call and start recording
await expect(() => call.stopClosedCaptions()).rejects.toThrowError(
'Stream error code 4: StopClosedCaptions failed with error: "call is not being transcribed"',
);
});

it('delete call', async () => {
try {
await call.delete({ hard: true });
Expand Down
4 changes: 3 additions & 1 deletion __tests__/create-test-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ const apiKey = process.env.STREAM_API_KEY!;
const secret = process.env.STREAM_SECRET!;

export const createTestClient = () => {
return new StreamClient(apiKey, secret, { timeout: 10000 });
return new StreamClient(apiKey, secret, {
timeout: 10000,
});
};
221 changes: 221 additions & 0 deletions src/gen/chat/ChatApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseApi } from '../../BaseApi';
import { StreamResponse } from '../../types';
import {
CampaignResponse,
CastPollVoteRequest,
ChannelGetOrCreateRequest,
ChannelStateResponse,
Expand All @@ -16,18 +17,21 @@ import {
DeleteChannelsResponse,
DeleteCommandResponse,
DeleteMessageResponse,
DeleteSegmentTargetsRequest,
EventResponse,
ExportChannelsRequest,
ExportChannelsResponse,
FileUploadRequest,
FileUploadResponse,
GetCampaignResponse,
GetChannelTypeResponse,
GetCommandResponse,
GetExportChannelsStatusResponse,
GetManyMessagesResponse,
GetMessageResponse,
GetReactionsResponse,
GetRepliesResponse,
GetSegmentResponse,
GetThreadResponse,
HideChannelRequest,
HideChannelResponse,
Expand All @@ -50,6 +54,8 @@ import {
PollVotesResponse,
QueryBannedUsersPayload,
QueryBannedUsersResponse,
QueryCampaignsRequest,
QueryCampaignsResponse,
QueryChannelsRequest,
QueryChannelsResponse,
QueryMembersPayload,
Expand All @@ -62,6 +68,10 @@ import {
QueryPollsResponse,
QueryReactionsRequest,
QueryReactionsResponse,
QuerySegmentTargetsRequest,
QuerySegmentTargetsResponse,
QuerySegmentsRequest,
QuerySegmentsResponse,
QueryThreadsRequest,
QueryThreadsResponse,
ReactionRemovalResponse,
Expand All @@ -77,6 +87,9 @@ import {
ShowChannelRequest,
ShowChannelResponse,
SortParamRequest,
StartCampaignRequest,
StartCampaignResponse,
StopCampaignRequest,
TranslateMessageRequest,
TruncateChannelRequest,
TruncateChannelResponse,
Expand Down Expand Up @@ -108,6 +121,83 @@ import {
import { decoders } from '../model-decoders';

export class ChatApi extends BaseApi {
queryCampaigns = async (
request?: QueryCampaignsRequest,
): Promise<StreamResponse<QueryCampaignsResponse>> => {
const body = {
limit: request?.limit,
next: request?.next,
prev: request?.prev,
sort: request?.sort,
filter: request?.filter,
};

const response = await this.sendRequest<
StreamResponse<QueryCampaignsResponse>
>('POST', '/api/v2/chat/campaigns/query', undefined, undefined, body);

decoders.QueryCampaignsResponse?.(response.body);

return { ...response.body, metadata: response.metadata };
};

getCampaign = async (request: {
id: string;
}): Promise<StreamResponse<GetCampaignResponse>> => {
const pathParams = {
id: request?.id,
};

const response = await this.sendRequest<
StreamResponse<GetCampaignResponse>
>('GET', '/api/v2/chat/campaigns/{id}', pathParams, undefined);

decoders.GetCampaignResponse?.(response.body);

return { ...response.body, metadata: response.metadata };
};

startCampaign = async (
request: StartCampaignRequest & { id: string },
): Promise<StreamResponse<StartCampaignResponse>> => {
const pathParams = {
id: request?.id,
};
const body = {
scheduled_for: request?.scheduled_for,
stop_at: request?.stop_at,
};

const response = await this.sendRequest<
StreamResponse<StartCampaignResponse>
>('POST', '/api/v2/chat/campaigns/{id}/start', pathParams, undefined, body);

decoders.StartCampaignResponse?.(response.body);

return { ...response.body, metadata: response.metadata };
};

scheduleCampaign = async (
request: StopCampaignRequest & { id: string },
): Promise<StreamResponse<CampaignResponse>> => {
const pathParams = {
id: request?.id,
};
const body = {};

const response = await this.sendRequest<StreamResponse<CampaignResponse>>(
'POST',
'/api/v2/chat/campaigns/{id}/stop',
pathParams,
undefined,
body,
);

decoders.CampaignResponse?.(response.body);

return { ...response.body, metadata: response.metadata };
};

queryChannels = async (
request?: QueryChannelsRequest,
): Promise<StreamResponse<QueryChannelsResponse>> => {
Expand Down Expand Up @@ -1758,6 +1848,137 @@ export class ChatApi extends BaseApi {
return { ...response.body, metadata: response.metadata };
};

querySegments = async (
request: QuerySegmentsRequest,
): Promise<StreamResponse<QuerySegmentsResponse>> => {
const body = {
filter: request?.filter,
limit: request?.limit,
next: request?.next,
prev: request?.prev,
sort: request?.sort,
};

const response = await this.sendRequest<
StreamResponse<QuerySegmentsResponse>
>('POST', '/api/v2/chat/segments/query', undefined, undefined, body);

decoders.QuerySegmentsResponse?.(response.body);

return { ...response.body, metadata: response.metadata };
};

deleteSegment = async (request: {
id: string;
}): Promise<StreamResponse<Response>> => {
const pathParams = {
id: request?.id,
};

const response = await this.sendRequest<StreamResponse<Response>>(
'DELETE',
'/api/v2/chat/segments/{id}',
pathParams,
undefined,
);

decoders.Response?.(response.body);

return { ...response.body, metadata: response.metadata };
};

getSegment = async (request: {
id: string;
}): Promise<StreamResponse<GetSegmentResponse>> => {
const pathParams = {
id: request?.id,
};

const response = await this.sendRequest<StreamResponse<GetSegmentResponse>>(
'GET',
'/api/v2/chat/segments/{id}',
pathParams,
undefined,
);

decoders.GetSegmentResponse?.(response.body);

return { ...response.body, metadata: response.metadata };
};

deleteSegmentTargets = async (
request: DeleteSegmentTargetsRequest & { id: string },
): Promise<StreamResponse<Response>> => {
const pathParams = {
id: request?.id,
};
const body = {
target_ids: request?.target_ids,
};

const response = await this.sendRequest<StreamResponse<Response>>(
'POST',
'/api/v2/chat/segments/{id}/deletetargets',
pathParams,
undefined,
body,
);

decoders.Response?.(response.body);

return { ...response.body, metadata: response.metadata };
};

segmentTargetExists = async (request: {
id: string;
target_id: string;
}): Promise<StreamResponse<Response>> => {
const pathParams = {
id: request?.id,
target_id: request?.target_id,
};

const response = await this.sendRequest<StreamResponse<Response>>(
'GET',
'/api/v2/chat/segments/{id}/target/{target_id}',
pathParams,
undefined,
);

decoders.Response?.(response.body);

return { ...response.body, metadata: response.metadata };
};

controllerNameQuerySegmentTargets = async (
request: QuerySegmentTargetsRequest & { id: string },
): Promise<StreamResponse<QuerySegmentTargetsResponse>> => {
const pathParams = {
id: request?.id,
};
const body = {
limit: request?.limit,
next: request?.next,
prev: request?.prev,
sort: request?.sort,
filter: request?.filter,
};

const response = await this.sendRequest<
StreamResponse<QuerySegmentTargetsResponse>
>(
'POST',
'/api/v2/chat/segments/{id}/targets/query',
pathParams,
undefined,
body,
);

decoders.QuerySegmentTargetsResponse?.(response.body);

return { ...response.body, metadata: response.metadata };
};

queryThreads = async (
request?: QueryThreadsRequest,
): Promise<StreamResponse<QueryThreadsResponse>> => {
Expand Down
Loading

0 comments on commit c6a1c82

Please sign in to comment.