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

Telegram documentation unclear regarding chat_id #538

Open
danwie opened this issue Sep 12, 2024 · 8 comments
Open

Telegram documentation unclear regarding chat_id #538

danwie opened this issue Sep 12, 2024 · 8 comments

Comments

@danwie
Copy link

danwie commented Sep 12, 2024

From the FAQ: "On the next start, the scanner will help you obtain the chat_id"

I tried to leave the chat_id empty, but I got an error: "Telegram Error: Chat_id is empty". I then created a new Telegram channel and added the bot to it as admin, then I added the channel id as chat_id - and that seems to be working. I get notifications to the channel. However, when I try to send command to the bot in the channel - nothing happens. When I send commands directly to the bot I get a warning: "Unauthorized access to _list_favorites from chat id 57xxxxx42 and user id 57xxxxx42".

If possible, please add some more instructions on how to obtain the chat_id for the bot. I've googled it, but it seems bots doesn't have a chat id. I'm confused.

@floriegl
Copy link
Contributor

How did you send the commands to the bot in the channel? I just tried what you explained and got it working.

  • Invited @ShowJsonBot to the group, set the chat_id to the chat.id from the bot output (starts with minus) and kicked the bot again
  • Added the bot to the group and started the bot
  • Using the "slash command icon" I selected the command and I sent "/listfavorites@" in the group and the bot answered correctly.

I also figured out what your issue with "Telegram Error: Chat_id is empty" was. You left the chat_ids empty, but you need to remove it. If you are e.g., using docker compose, you have to comment out the whole line. But yes, this should be improved in chat IDs handling. An empty config should be handled the same as no config. I would suggest also checking for a blank string in https://github.com/Der-Henning/tgtg/blob/main/tgtg_scanner/models/config.py#L71 @Der-Henning

@danwie
Copy link
Author

danwie commented Sep 13, 2024

It seems I don't really understand how to start or talk to the bot in a channel. I've added the bot as a administrator in the channel, and it can successfully send messages. Then I've tried a lot of different things to start/talk to it (@BotUsername, slash command etc), but none of it is working.

Thank you for the advice of inviting @ShowJsonBot to the group. I have the chat_id and have set it in the docker config. However, I only can send slash commands directly to the bot (and that's what triggered the warning-message above) - but I can not talk to it in the channel. How do I start it in the channel?

Sorry for basic question, but I have googled this and could not find any anwers on how to start a bot in a channel.

@floriegl
Copy link
Contributor

https://chatimize.com/telegram-bot-group/#What_if_your_bot_only_responds_when_someone_mentions_it

I only can send slash commands directly to the bot (and that's what triggered the warning-message above)

Do you mean that the slash commands still don't work even after setting the correct chat ID for the group? As mentioned before the bot correctly responded to me after doing that and did not log any warnings for new slash commands. If you still have issues after doing the fix describes in the link above, please also provide screenshots from the logs and the Telegram group.

@danwie
Copy link
Author

danwie commented Sep 13, 2024

I think I have found the solution. It seems bots doesn't work in TG channels, only TG groups. I've created a group now, and added the bot - and now I can send commands to it.

@floriegl
Copy link
Contributor

Oh sorry, I always misread channel with group. I didn't assume that anyone would want to do that. But if you are the only one using the bot you should just be able to have a normal chat with it. Just comment out the - TELEGRAM_CHAT_IDS= line, send the bot the numbers it displays in the log and after that add the line with the chat ID from the logs to the docker compose file.

@ColinusM
Copy link

How do you get chat id in the first place. Why is this so complicated.
Terminal doesn't help me find it.
Please help

@floriegl
Copy link
Contributor

If you just want to write with the bot directly, you can just send it "/getid" (without the quotes) to get the chat ID. Or you can send the bot the numbers it displays in the terminal if you don't have the "TELEGRAM_CHAT_IDS" or the chat IDs set in general.

For group chats just invite the @ShowJsonBot which also shows you the chat id.

@ColinusM
Copy link

Thanks that worked

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