GramJS

messages.StartBot

Start a conversation with a bot using a deep linking parameter

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.StartBot({
      bot: "username",
      peer: "username",
      randomId: BigInt("-4156887774564"),
      startParam: "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.Updates = await client.invoke(
    new Api.messages.StartBot({
      bot: "username",
      peer: "username",
      randomId: BigInt("-4156887774564"),
      startParam: "some string here",
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
botInputUserThe bot
peerInputPeerThe chat where to start the bot, can be the bot's private chat or a group
randomIdlongRandom ID to avoid resending the same message
startParamstringDeep linking parameter

Result

Updates

Possible errors

CodeTypeDescription
400BOT_INVALIDThis is not a valid bot.
400CHAT_ADMIN_REQUIREDYou must be an admin in this chat to do this.
400INPUT_USER_DEACTIVATEDThe specified user was deleted.
400MSG_ID_INVALIDInvalid message ID provided.
400PEER_ID_INVALIDThe provided peer id is invalid.
500RANDOM_ID_DUPLICATEYou provided a random ID that was already used.
400START_PARAM_EMPTYThe start parameter is empty.
400START_PARAM_INVALIDStart parameter invalid.
400START_PARAM_TOO_LONGStart parameter is too long.

Can bots use this method?

No

Bots: An introduction for developers