Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot cast [channel_ID] to any kind of InputPeer #14

Closed
moehmeni opened this issue Jan 15, 2023 · 5 comments
Closed

Cannot cast [channel_ID] to any kind of InputPeer #14

moehmeni opened this issue Jan 15, 2023 · 5 comments

Comments

@moehmeni
Copy link

moehmeni commented Jan 15, 2023

peerID := -1001187973481 // Already checked it's correct
_, err := client.GetInputPeer(int64(peerID))
if err != nil {
panic(err)
}
panic: cannot cast -1001187973481 to any kind of InputPeer
@AmarnathCJD
Copy link
Owner

AmarnathCJD commented Jan 15, 2023

@rtcq The chat/channel is not yet in cache
To get InputPeer the accesshash of channel should be recived in IncomingUpdates and saved in cache

If the client have already interacted in the chat, remove -100 and try.

@TAMILVIP007
Copy link

TAMILVIP007 commented Jan 15, 2023

@AmarnathCJD Pro

@moehmeni
Copy link
Author

I see, so when I want to get a message, what would be the best method to get it directly? my current method is requesting it with channel_ID and message_ID like client.GetMessages(channelID, &telegram.SearchOption{IDs: messageID}) but the availability of the channelID is not guaranteed. Is there any one-time unique identifier for a message to get it from both public and private channels by the client?

@AmarnathCJD
Copy link
Owner

AmarnathCJD commented Jan 15, 2023

I see, so when I want to get a message, what would be the best method to get it directly? my current method is requesting it with channel_ID and message_ID like client.GetMessages(channelID, &telegram.SearchOption{IDs: messageID}) but the availability of the channelID is not guaranteed. Is there any one-time unique identifier for a message to get it from both public and private channels by the client?

If the channel has a username
inputpeer, _ := client.GetSendablePeer("username")

if it's private, wait for NewMessage event and save the chatID and AccessHash from it. Reuse these values in future.

client.AddMessageHandler(telegram.OnNewMessage, func (m *telegram.NewMessage) error {
if m.ChatID() == 108653788..{
println(m.Chat.AccessHash) // m.Channel.AccessHash
})

@moehmeni
Copy link
Author

Ok thanks

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

No branches or pull requests

3 participants