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

TypeError: Cannot read properties of undefined (reading 'call') when calling `messages.getMessages` #213

Closed pooyarm closed 2 years ago

pooyarm commented 2 years ago

Describe the bug I'm trying to fetch a message, but I get the following error:

TypeError: Cannot read properties of undefined (reading 'call')
    at Counter.predicate (/Users/pooya/workspace/our-living-room-tv/node_modules/@mtproto/core/src/tl/counter/index.js:101:8)
    at Counter.vector (/Users/pooya/workspace/our-living-room-tv/node_modules/@mtproto/core/src/tl/counter/index.js:94:10)
    at Counter.messages.getMessages (/Users/pooya/workspace/our-living-room-tv/node_modules/@mtproto/core/src/tl/builder/index.js:5326:10)
    at Counter.predicate (/Users/pooya/workspace/our-living-room-tv/node_modules/@mtproto/core/src/tl/counter/index.js:101:8)
    at Counter.initConnection (/Users/pooya/workspace/our-living-room-tv/node_modules/@mtproto/core/src/tl/builder/index.js:5625:10)
    at Counter.predicate (/Users/pooya/workspace/our-living-room-tv/node_modules/@mtproto/core/src/tl/counter/index.js:101:8)
    at Counter.invokeWithLayer (/Users/pooya/workspace/our-living-room-tv/node_modules/@mtproto/core/src/tl/builder/index.js:5670:10)
    at new Counter (/Users/pooya/workspace/our-living-room-tv/node_modules/@mtproto/core/src/tl/counter/index.js:7:8)
    at new Serializer (/Users/pooya/workspace/our-living-room-tv/node_modules/@mtproto/core/src/tl/serializer/index.js:7:21)
    at RPC.call (/Users/pooya/workspace/our-living-room-tv/node_modules/@mtproto/core/src/rpc/index.js:591:24)
    at Object.call (/Users/pooya/workspace/our-living-room-tv/node_modules/@mtproto/core/src/index.js:106:32)
    at /Users/pooya/workspace/our-living-room-tv/dist/apps/bot/webpack:/apps/bot/src/main.ts:31:6
    at Generator.next (<anonymous>)
    at fulfilled (/Users/pooya/workspace/our-living-room-tv/node_modules/tslib/tslib.js:114:62)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Code example

  mt.call('messages.getMessages', { id: [39] }, options)
    .then((refetchedMessage) => {
      console.log('refetchedMessage', refetchedMessage)
    })
    .catch((error) => {
      console.error('refetch filed!', error)
    })

Expected behavior To be able to fetch a message, or at least get a proper error message to know what is wrong.

Context:

pooyarm commented 2 years ago

ok, as I researched, it seems that this error is because the payload of the method is wrong, instead of { id: [39]} it should be like:

{
  id: {
    {
      _: 'inputMessageID',
      id: 39,
    }
  }
}