Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add translate API support #1415

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 18 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,23 @@ 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 = {
language: string;
translated_text: string;
};

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