alik0211 / mtproto-core

Telegram API JS (MTProto) client library for Node.js and browser
https://mtproto-core.js.org
GNU General Public License v3.0
630 stars 113 forks source link

messages.sendMedia returns error because "call" is undefined #226

Open fjpedrosa opened 2 years ago

fjpedrosa commented 2 years ago

Describe the bug I can not execute sendMedia command, receiveing error message:

messages.sendMedia error: TypeError: Cannot read property 'call' of undefined Code example

function sendMedia(mtprotoInstance, media, message, replyId) {
  console.log("Broadcasting message with media");
  console.log(mtprotoInstance)

  let options = {
    peer: {
      _: "inputPeerChannel",
      channel_id: process.env.BROADCAST_TEST_CHANNEL_ID,
      access_hash: process.env.BROADCAST_TEST_CHANNEL_ACCESS_HASH,
    },

    message,
    media,
    random_id:
      Math.ceil(Math.random() * 0xffffff) + Math.ceil(Math.random() * 0xffffff),
  };

  if (replyId) options.reply_to_msg_id = replyId;

  return mtprotoInstance.call("messages.sendMedia", options);
}

mtproto instance is in a class here:

constructor(api_id, api_hash, dataFile) {
    this.mtproto = new MTProto({
      api_id,
      api_hash,
      invokeWithLayer: 0xda9b0d0d,
      layer: 57,
      initConnection: 0x69796de9,
      app_version: "1.0.1",
      lang_code: "es",
      storageOptions: {
        path: path.resolve(__dirname, `./data/${dataFile}.json`),
      },
    });

Expected behavior Media is sent.

Screenshots If applicable, add screenshots to help explain your problem.

Context:

Additional context Other methods like messages.sendMessage or messages.getAllChats, but this in particular returns that error and I can not figure out what is going on.