skip to Main Content

I’m connecting to Telegram API with this C# library: TLSharp

The resources for this library is not enough, I’m trying to Forward a message to channel .

I’m not quiet sure how to get channel post peer id (for forward function input parameters)

var store = new FileSessionStore();
            var client = new TelegramClient(Properties.Settings.Default.apiID, Properties.Settings.Default.apiHash, store, "session");
            await client.ConnectAsync();
            var dialogs = (TLDialogs)await client.GetUserDialogsAsync();
            var chat = dialogs.chats.lists
                .OfType<TLChannel>()
                .SingleOrDefault(a=>a.title=="test");
            await client.SendRequestAsync<TLAbsUpdates>(
                               new TLRequestForwardMessage()
                               {
                                   id = 2,
                                   peer = new TLInputPeerChannel() { channel_id = chat.id, access_hash = chat.access_hash.Value },
                                   random_id = Helpers.GenerateRandomLong()
                               });

I get this error message :

{“PEER_ID_INVALID”}

Please help me, what is that peer id and how can i access and use that for forwarding a message using TLSharp. Thanks.

3

Answers


  1. Chosen as BEST ANSWER

    This code can be used for forward

    **

    await client.SendRequestAsync<TLAbsUpdates>( new TLRequestForwardMessage() { id = item2.Id, peer = new TLInputPeerChat() { chat_id = item.id }, random_id = Helpers.GenerateRandomLong(), });
    ---------------------------------------
    

    **---------------------------------


  2. You can do that with this nice trick which is hilarious: this code is below:

    new TLInputPeerChannel { channel_id = chat.id, access_hash = cha.access_hash.Value }, offset,
                    maxId, limit);
    
    Login or Signup to reply.
  3. And this is my code to Forward a message:

    /* e.g you can use TLInputPeerUser, TLInputPeerChat, TLInputPeerChannel here as an SourcePeer */
    // a Person
    var sourcePeer = new TLInputPeerUser { UserId = <<<USER.ID>>>, AccessHash = <<<USER.AccessHash>>> };
        
    // normal Group
    //var sourcePeer = new TLInputPeerChat { ChatId = <<<USER.ID>>> };
    
    // SuperGroup or Channel
    //var sourcePeer = new TLInputPeerChannel { ChatId = <<<USER.ID>>> , AccessHash = <<<USER.AccessHash>>> };
    
    
    /* e.g you can use TLInputPeerUser, TLInputPeerChat, TLInputPeerChannel here as an SourcePeer */
    // a Person
    //var targetPeer = new TLInputPeerUser { UserId = <<<USER.ID>>>, AccessHash = <<<USER.AccessHash>>> };
    
    // normal Group
    var targetPeer = new TLInputPeerChat { ChatId = <<<USER.ID>>> };
    
    // SuperGroup or Channel
    //var targetPeer = new TLInputPeerChannel { ChatId = <<<USER.ID>>> , AccessHash = <<<USER.AccessHash>>> };
    
    // random Ids to prevent bombinggg
    var randomIds = new TLVector<long>
    {
        TLSharp.Core.Utils.Helpers.GenerateRandomLong()
    };
    
    // source messages
    var sourceMessageIds = new TLVector<int>
    {
        messageIdInSourceContactToForward   // this ID should be in the SourcePeer's Messages
    };
    
    var forwardRequest = new TLRequestForwardMessages()
    {
        FromPeer = sourcePeer,
        Id = sourceMessageIds,
        ToPeer = targetPeer,
        RandomId = randomIds,
        //Silent = false
    };
    
    var result = await myTelegramClient.SendRequestAsync<TLUpdates>(forwardRequest);
    

    I can’t use this method, and have to use this one

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search