GramJS

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

NameTypeDescription
flags#Flags, see TL conditional fields
peerflags.0?InputPeerIf the text is a chat message, the peer ID
msgIdflags.0?intIf the text is a chat message, the message ID
textflags.1?stringThe text to translate
fromLangflags.2?stringTwo-letter ISO 639-1 language code of the language from which the message is translated, if not set will be autodetected
toLangstringTwo-letter ISO 639-1 language code of the language to which the message is translated

Result

messages.TranslatedText

Possible errors

CodeTypeDescription

Can bots use this method?

Yes