Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forwarding message with TLSharp library (C#)

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.

like image 512
amirhossein mohseni Avatar asked Mar 11 '17 13:03

amirhossein mohseni


2 Answers

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);
like image 89
VahidHoseini Avatar answered Nov 16 '22 19:11

VahidHoseini


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(), });
---------------------------------------

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

like image 36
amirhossein mohseni Avatar answered Nov 16 '22 17:11

amirhossein mohseni