zerobias / telegram-mtproto

Telegram client api (MTProto) library
MIT License
617 stars 136 forks source link

Constructor for Channel Messages Text #142

Closed Roy5000 closed 5 years ago

Roy5000 commented 6 years ago

I try to get the text of messages in a public channel and tried several constructor but without success. The constructors I tried do not return the message text. Which constructor can I use to retrieve the message text?

Attempt 1: Constructor readMessageContents.
(for parameter "id" I added [2] but i'm not sure how this is used by the contructor.)

  const myChannel = {
  _: 'inputChannel',
  channel_id: 1******8,
  access_hash: '1*************3'
};

client('channels.readMessageContents', { channel: myChannel, id: [2] })
 .then(console.log)  

result is error message:

(node:15624) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: No method name channels.readMessageContents found

Attempt 2: constructor channels.getChannels

  const channel = await client('channels.getChannels', {
        id: [{
            _: "inputChannel",
            channel_id: 1******8,
            access_hash: '1*************3'
        }]
    })
    .then(console.log)

return below channel details without message text:

  [ { _: 'channel',
       flags: 8288,
       broadcast: true,
       id: 1******8,
       access_hash: '1***********3',
       title: 'C***r',
       username: 'C***r',
       photo: [Object],
       date: 1508393708,
       version: 0 } ] }

Attempt 3: constructor channels.getFullChannel

  const myChannel = {
  _: 'inputChannel',
  channel_id: 1******8,
  access_hash: '1*************3'
};

client('channels.getFullChannel', { channel: myChannel })
 .then(console.log)

returns below channel details, but no message text:

{ _: 'messages.chatFull',
  full_chat:
   { _: 'channelFull',
     flags: 1,
     id: 1******8,
     about: 'We *********s',
     participants_count: 2931,
     read_inbox_max_id: 7774,
     read_outbox_max_id: 0,
     unread_count: 3,
     chat_photo:
      { _: 'photo',
        flags: 0,
        id: '1**********5',
        access_hash: '11***********5',
        date: 1511941688,
        sizes: [Array] },
     notify_settings:
      { _: 'peerNotifySettings',
        flags: 1,
        show_previews: true,
        mute_until: 0,
        sound: 'default' },
     exported_invite: { _: 'chatInviteEmpty' },
     bot_info: [] },
  chats:
   [ { _: 'channel',
       flags: 8288,
       broadcast: true,
       id: 1******8,
       access_hash: '1**********3',
       title: 'C****r',
       username: 'C****r',
       photo: [Object],
       date: 1508393708,
       version: 0 } ],
  users: [] }
Alavi1412 commented 6 years ago

You can use this to get messages you know the ids

var messages = await client('channels.getMessages', {
        channel: {
            _:"inputPeerChannel",
            channel_id:'*******',
            access_hash: '*******'
        },
        id: [1, 2, 3, 4, 25]          // Example message_id
    });

    console.log(messages);

This is also useful for

var messages = await client('messages.getHistory', {
        peer: {
            _:"inputPeerChannel",
            channel_id:'*****',
            access_hash: '*******'
        }

    });
    console.log(messages);