Skip to content

Commit

Permalink
ft: translate API
Browse files Browse the repository at this point in the history
  • Loading branch information
varbhat committed Dec 11, 2024
1 parent af63684 commit e5defb1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ import {
TestSNSDataInput,
TestSQSDataInput,
TokenOrProvider,
TranslateResponse,
UnBanUserOptions,
UpdateChannelOptions,
UpdateChannelResponse,
Expand Down Expand Up @@ -2516,6 +2517,22 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
);
}

/**
* translate - translates the given text to provided language
*
* @param {string} text
* @param {string} destination_language
* @param {string} source_language
*
* @return {TranslateResponse} Response that includes the message
*/
async translate(text: string, destination_language: string,source_language: string) {
return await this.post<APIResponse & TranslateResponse>(
this.baseURL + `/translate`,
{ text, source_language, destination_language },
);
}

/**
* _normalizeExpiration - transforms expiration value into ISO string
* @param {undefined|null|number|string|Date} timeoutOrExpirationDate expiration date or timeout. Use number type to set timeout in seconds, string or Date to set exact expiration date
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ export type APIResponse = {
duration: string;
};

export type TranslateResponse = {
translated_text: string;
language: string;
}

export type AppSettingsAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & {
app?: {
// TODO
Expand Down

0 comments on commit e5defb1

Please sign in to comment.