Skip to content

Commit 7c1c58d

Browse files
feat: add translate API support (#1415)
Co-authored-by: Vishal Narkhede <vishalnarkhede.iitd@gmail.com>
1 parent 13dc6f6 commit 7c1c58d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/client.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ import {
189189
TestSNSDataInput,
190190
TestSQSDataInput,
191191
TokenOrProvider,
192+
TranslateResponse,
192193
UnBanUserOptions,
193194
UpdateChannelOptions,
194195
UpdateChannelResponse,
@@ -2516,6 +2517,23 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
25162517
);
25172518
}
25182519

2520+
/**
2521+
* translate - translates the given text to provided language
2522+
*
2523+
* @param {string} text
2524+
* @param {string} destination_language
2525+
* @param {string} source_language
2526+
*
2527+
* @return {TranslateResponse} Response that includes the message
2528+
*/
2529+
async translate(text: string, destination_language: string, source_language: string) {
2530+
return await this.post<APIResponse & TranslateResponse>(this.baseURL + `/translate`, {
2531+
text,
2532+
source_language,
2533+
destination_language,
2534+
});
2535+
}
2536+
25192537
/**
25202538
* _normalizeExpiration - transforms expiration value into ISO string
25212539
* @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

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ export type APIResponse = {
7777
duration: string;
7878
};
7979

80+
export type TranslateResponse = {
81+
language: string;
82+
translated_text: string;
83+
};
84+
8085
export type AppSettingsAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & {
8186
app?: {
8287
// TODO

0 commit comments

Comments
 (0)