messages.TranslateText
Translate a given text
Example
const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");
const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});
(async function run() {
await client.connect(); // This assumes you have already authenticated with .start()
const result = await client.invoke(
new Api.messages.TranslateText({
toLang: "some string here",
peer: "username",
msgId: 43,
text: "some string here",
fromLang: "some string here",
})
);
console.log(result); // prints the result
})();
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";
const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});
(async function run() {
await client.connect(); // This assumes you have already authenticated with .start()
const result: Api.messages.TranslatedText = await client.invoke(
new Api.messages.TranslateText({
toLang: "some string here",
peer: "username",
msgId: 43,
text: "some string here",
fromLang: "some string here",
})
);
console.log(result); // prints the result
})();
Parameters
Name | Type | Description |
---|---|---|
flags | # | Flags, see TL conditional fields |
peer | flags.0?InputPeer | If the text is a chat message, the peer ID |
msgId | flags.0?int | If the text is a chat message, the message ID |
text | flags.1?string | The text to translate |
fromLang | flags.2?string | Two-letter ISO 639-1 language code of the language from which the message is translated, if not set will be autodetected |
toLang | string | Two-letter ISO 639-1 language code of the language to which the message is translated |
Result
Possible errors
Code | Type | Description |
---|
Can bots use this method?
Yes