telegram-bot-api
telegram-bot-api copied to clipboard
`Message.chat_id` can be a `string` or `int`
From the telegram api chat_it
can be an int
or string
(int
for username
but string
for channel "@channelname"
.
Currently using the library:
msg := tgbotapi.NewMessage("@channelname", "here is a new message on the channel !")
bot.Send(msg)
I have the error
cannot use "@channelname" (untyped string constant) as int64 value in argument to tgbotapi.NewMessage
My go skills are not enough but from what I understand, we would need to change this line in the Types.go
file.
From what I have read it isn't possible to have 2 types for the same field. But the type json.number
could be the solution from this stackoverflow link.
https://stackoverflow.com/questions/24480835/decoding-json-int-into-string/24480906#24480906.
Edit: from the new 1.18 go release, Generics may potentially be the solution.
in my practice (6+ years) no one uses channel name as chat_id
I use it so my bot can post content on my channel to automatically update followers. And I think a lot of people use it
All groups and channels can be addressed by their ID, you don't need to use the username. The library is structured in such a way that every request accepts a username field, but there aren't helpers for it. You can construct the MessageConfig
with a username yourself if you really want to.