GramJS

messages.CreateChat

Creates a new chat.

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.CreateChat({
      users: ["username"],
      title: "My very normal title",
    })
  );
  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.Updates = await client.invoke(
    new Api.messages.CreateChat({
      users: ["username"],
      title: "My very normal title",
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
usersVector<InputUser>List of user IDs to be invited
titlestringChat name

Result

Updates

Possible errors

CodeTypeDescription
500CHAT_ID_GENERATE_FAILEDFailure while generating the chat ID.
400CHAT_INVALIDInvalid chat.
400CHAT_TITLE_EMPTYNo chat title provided.
400INPUT_USER_DEACTIVATEDThe specified user was deleted.
400USERS_TOO_FEWNot enough users (to create a chat, for example).
403USER_RESTRICTEDYou're spamreported, you can't create channels or chats.

Can bots use this method?

No