我正在使用此C#库连接到 Telegram API:TLSharp
此库的资源不足,我试图将邮件转发到频道。
我不确定如何获取频道peer
ID(转发功能输入参数)
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()
});
我收到此错误消息:
{&#34; PEER_ID_INVALID&#34;}
请帮助我,该对等ID是什么以及如何使用TLSharp来访问和使用它来转发消息。感谢。
答案 0 :(得分:3)
你可以用这个很有趣的好技巧来做到这一点:这段代码如下:
new TLInputPeerChannel { channel_id = chat.id, access_hash = cha.access_hash.Value }, offset,
maxId, limit);
答案 1 :(得分:2)
此代码可用于转发
**
/static
** ---------------------------------
答案 2 :(得分:0)
这是我转发邮件的代码:
/* 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);
我不能使用this method,而必须使用this one