I’m trying to retrieve a message from a channel in telegram, I have its id, that is the id with which it is displayed in the channel, the token of the bot that is added to this channel and is the administrator (I retrieve it by email from the database) and the name of the channel from which I retrieve the channel id of type Long.
Since I couldn’t find a suitable method in the lib I’m using, I turned to this.
I tried writing this kind of code, but the response comes back 404.
fun getMessageFromChannel(email: String, channelUsername: String, messageId: Long): Message? {
return runBlocking {
val botToken = getTelegram(email) ?: return@runBlocking null
val chatId = getChannelId(botToken, channelUsername) ?: return@runBlocking null
val response= client.get("https://api.telegram.org/bot$botToken/getMessages") {
parameter("channel", chatId)
parameter("id", messageId)
}
if (response.status.value == 200) {
val getMessageResponse: GetMessageResponse = response.body()
if (getMessageResponse.ok) {
return@runBlocking getMessageResponse.result
}
}
null
}
}
I guess I don’t understand something in the api telegram device, unfortunately I didn’t find how to send requests. So I would appreciate any help, thank you.