gram-js / gramjs

NodeJS/Browser MTProto API Telegram client library,
MIT License
1.28k stars 179 forks source link

messages.forwardMessages #357

Closed Vo0oX closed 2 years ago

Vo0oX commented 2 years ago

I managed to fully connect.

_const {Api, TelegramClient} = require('telegram');
const {StoreSession, StringSession} = require("telegram/sessions");

const API_ID = 123;
const API_HASH = "123";
const client = new TelegramClient(new StoreSession(""), API_ID, API_HASH, {});_

let phoneCodeHash;
let phone = '+84923359377';

_client.connect();

const result = await client.sendCode(
                        {
                            apiId: API_ID,
                            apiHash: API_HASH,
                        },
                        phone
                    );
                    phoneCodeHash = result.phoneCodeHash;
})()

await client.invoke(
                        new Api.auth.SignIn({
                            phoneNumber: phone,
                            phoneCodeHash,
                            phoneCode: msg.text,
                        })
                    );_

thanks to the bottom function i can read the incoming data

_client.addEventHandler( (update) => {})_

but I still don't understand how I can figure out how to forward messages from a group.

_id_channel_fromPeer = '-1001774337596'
id_channel_toPeer ='-1001612019147'_

this feature doesn't work for me.

_(async function run() {
    const result = await client.invoke(new Api.messages.forwardMessages({
        silent: true,
        background: true,
        withMyScore: true,
        fromPeer: new Api.InputPeer({...}),
        id: [3594049],
        randomId: [2616332],
        toPeer: new Api.InputPeer({...}),
        scheduleDate: 46082,
        }));
    console.log(result); 
})();_

please help me figure it out

painor commented 2 years ago

you can probably use https://gram.js.org/beta/classes/TelegramClient.html#forwardMessages

await client.forwardMessages(id_channel_toPeer ,  {messages:[3594049],fromPeer:_id_channel_fromPeer });
Vo0oX commented 2 years ago

you can probably use https://gram.js.org/beta/classes/TelegramClient.html#forwardMessages

await client.forwardMessages(id_channel_toPeer ,  {messages:[3594049],fromPeer:_id_channel_fromPeer });

Thanks

Vo0oX commented 2 years ago

media -

photo:  {
  CONSTRUCTOR_ID: 4212750949,
  SUBCLASS_OF_ID: 3581324060,
  className: 'Photo',
  classType: 'constructor',
  flags: 0,
  hasStickers: false,
  id: Integer { value: 6253484336326226418n },
  accessHash: Integer { value: 3887061461413119359n },
  fileReference: <Buffer 02 69 c2 3e 3c 00 00 00 38 62 d9 50 84 18 26 cf b3 5c 91 79 9b 5d d5 80 20 d7 ba 5d ff>,
  date: 1658408930,
  sizes: [
    {
      CONSTRUCTOR_ID: 3769678894,
      SUBCLASS_OF_ID: 399256025,
      className: 'PhotoStrippedSize',
      classType: 'constructor',
      type: 'i',
      bytes: <Buffer 01 27 28 d8 a8 e7 62 90 bb 2f de 0a 48 a5 2e 17 ad 45 29 92 45 74 50 36 91 8c f7 a0 69 5d 8f 82 41 24 4a 43 12 71 c9 3d 6a 5a a5 66 1e 3d e9 21 3b 57 ... 184 more bytes>
    },
    {
      CONSTRUCTOR_ID: 1976012384,
      SUBCLASS_OF_ID: 399256025,
      className: 'PhotoSize',
      classType: 'constructor',
      type: 'm',
      w: 320,
      h: 313,
      size: 17712
    },
    {
      CONSTRUCTOR_ID: 1976012384,
      SUBCLASS_OF_ID: 399256025,
      className: 'PhotoSize',
      classType: 'constructor',
      type: 'x',
      w: 800,
      h: 782,
      size: 55948
    },
    {
      CONSTRUCTOR_ID: 4198431637,
      SUBCLASS_OF_ID: 399256025,
      className: 'PhotoSizeProgressive',
      classType: 'constructor',
      type: 'y',
      w: 1038,
      h: 1014,
      sizes: [Array]
    }
  ],
  videoSizes: null,
  dcId: 5
}

another question. If I'm in another group, I get text and a picture. How can I get it from this data and send it to my group?

or you need to download and send already

await client.sendFile('-1001612019147', {file:__dirname +'/upload/me.png', caption:"It's me!"})
painor commented 2 years ago

you don't need to download it. you can just pass the message to client.sendMessage