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

Message.chat_id can be a string or int #527

Open
CedricRaison opened this issue Mar 16, 2022 · 4 comments
Open

Message.chat_id can be a string or int #527

CedricRaison opened this issue Mar 16, 2022 · 4 comments

Comments

@CedricRaison
Copy link

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
@CedricRaison CedricRaison changed the title Message.chat_id can be a string or int Message.chat_id can be a string or int Mar 16, 2022
@CedricRaison
Copy link
Author

CedricRaison commented Mar 16, 2022

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.

@temamagic
Copy link
Contributor

in my practice (6+ years) no one uses channel name as chat_id

@CedricRaison
Copy link
Author

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

@Syfaro
Copy link
Member

Syfaro commented Apr 19, 2022

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.

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