GramJS

messages.SendVote

Vote in a poll

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.SendVote({
      peer: "username",
      msgId: 43,
      options: [Buffer.from("arbitrary data 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.SendVote({
      peer: "username",
      msgId: 43,
      options: [Buffer.from("arbitrary data here")],
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
peerInputPeerThe chat where the poll was sent
msgIdintThe message ID of the poll
optionsVector<bytes>The options that were chosen

Result

Updates

Possible errors

CodeTypeDescription
400MESSAGE_ID_INVALIDThe provided message id is invalid
400MESSAGE_POLL_CLOSEDPoll closed
400OPTIONS_TOO_MUCHToo many options provided
400OPTION_INVALIDInvalid option selected
400REVOTE_NOT_ALLOWEDYou cannot change your vote

Can bots use this method?

No

poll

Poll