Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Facing Invalid Channel Problem #277

Open
PBhadoo opened this issue Feb 15, 2023 · 0 comments
Open

Facing Invalid Channel Problem #277

PBhadoo opened this issue Feb 15, 2023 · 0 comments

Comments

@PBhadoo
Copy link

PBhadoo commented Feb 15, 2023

Describe the bug
Unable to do anything with a channel

Code example

const path = require('path');
const MTProto = require('@mtproto/core');

const api_id = 202xxxxx3;
const api_hash = 'c95fbxxxxxxxxxxxx7d9b0f0';
const bottoken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const bot_id = '6140xxxx684';
const access_hash = '4443xxxxxxxxx438';
const channelId = '-100178570xxxx';
const messageId  = '43759';
const server = { webogram: true };

// 1. Create instance
const client = new MTProto({
  api_id,
  api_hash,
  bottoken,
  server,
  storageOptions: {
      path: path.resolve(__dirname, './data/1.json'),
    },
});

async function downloadFileFromChannel(mtproto, channelId, messageId) {
  // Get the message object for the specified message ID
  try {
    const result = await client.call('channels.getMessages', {
      channel: {
        _: 'inputChannel',
        channel_id: channelId,
        access_hash: access_hash
      },
      id: {
        _: 'inputMessageID',
        id: 43759,
      }
    });
    console.log(result)
    const message = result.messages[0];
    if (message.media._ !== 'messageMediaDocument') {
      throw new Error('The message does not contain a document');
    }

    // Get the file location from the message object
    const document = message.media.document;
    const fileLocation = {
      _: 'inputDocumentFileLocation',
      id: document.id,
      access_hash: document.access_hash,
      file_reference: document.file_reference
    };

    // Download the file
    const fileBytes = await downloadFile(mtproto, fileLocation);
    console.log(fileBytes);
  } catch (e) {
    console.log(e)
  }
}

async function importBotAuthorization(mtproto, botToken) {
    try {
      const result = await client.call('auth.importBotAuthorization', {
        api_id: api_id,
        api_hash: api_hash,
        bot_auth_token: botToken
      });
      const { bot } = result;
      console.log(result);
    } catch (e) {
      console.log(e)
    }
}


async function getChannelAccessHash(channelId) {
  try {
    const inputChannel = {
      _: 'inputChannel',
      channel_id: channelId,
      //access_hash: 0
    };

    const chatFull = await client.call('channels.getFullChannel', {
      channel: inputChannel
    });

    const accessHash = chatFull.full_chat.access_hash;
    console.log('Access hash for the channel:', accessHash);

    return accessHash;
  } catch (error) {
    console.error('Error while getting access hash:', error);
  }
}

//importBotAuthorization(mtproto, bottoken);
getChannelAccessHash(channelId)
//downloadFileFromChannel(mtproto, channelId, messageId);

Expected behavior
A clear and concise description of what you expected to happen.

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

Context:

  • Library environment: node or browser
  • Library version: x.x.x
  • Node version (if node environment): x.x.x
  • Browser version (if browser environment): x.x.x

Additional context
Add any other context about the problem here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant