Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Clarified requirements for allowed_chat_ids parameter #3068

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

Merged
merged 2 commits into from
Jul 30, 2017
Merged

Clarified requirements for allowed_chat_ids parameter #3068

merged 2 commits into from
Jul 30, 2017

Conversation

dullage
Copy link
Contributor

@dullage dullage commented Jul 27, 2017

I'm not 100% sure on this but my tests seem to back it up. Unless I list both the chat id and my user id in the allowed_chat_ids parameter then I receive a "Incoming message is not allowed" message in the HA log.

Description: Clarified requirements for allowed_chat_ids parameter

I'm not 100% sure on this but my tests seem to back it up. Unless I list both the chat id and my user id in the allowed_chat_ids parameter then I receive a "Incoming message is not allowed" message in the HA log.
@mention-bot
Copy link

@dullage, thanks for your PR! By analyzing the history of the files in this pull request, we identified @sander76, @cyberplant and @azogue to be potential reviewers.

@Landrash Landrash added Enhancement help-wanted Wanna help? Jump in! labels Jul 28, 2017
@Landrash
Copy link
Contributor

@azogue can you have a look and confirm this? 😈

@azogue
Copy link
Member

azogue commented Jul 30, 2017

Perfect, I passed by a few minutes ago and saw that it was clearly improveable, but laziness is very bad ...

To get your `chat_id` and `api_key` follow the instructions [here](/components/notify.telegram) .
To get your `chat_id` and `api_key` follow the instructions [here](/components/notify.telegram).

*Note: If you have added your bot to a group. In the allowed_chat_ids list you will need to include the id for the chat as well as the user. Both of these ids are visible using the getUpdates methods described in the link above.*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If you have added your bot to a group, in the..."

@azogue
Copy link
Member

azogue commented Jul 30, 2017

I think if you set the DEBUG logging level for the telegram_bot component, you can get the chat_id's without leaving HA, but I'm not sure.

@azogue
Copy link
Member

azogue commented Jul 30, 2017

I've checked it, when you add your bot to a new chat group, it will raise an error in the Home Assistant logs like that:

2017-07-30 17:08:53 ERROR (MainThread) [homeassistant.components.telegram_bot]
Incoming message is not allowed ({'new_chat_participant':
{'first_name': 'MyBot', 'id': 123456789, 'username': 'my_bot_name'}, 'new_chat_members': [{'first_name': 'MyBot', 'id': 123456789, 'username': ''my_bot_name'}], 'chat': {'id': -246188003, 'title': 'Chat group title', 'type': 'group', 'all_members_are_administrators': True}, 'message_id': 2740, 'date': 1501427333, 'new_chat_member': {'first_name': 'MyBot', 'id': 123456789, 'username': ''my_bot_name'}, 'from': {'last_name': 'Your last name', 'language_code': 'es', 'first_name': 'Your name', 'id': 987654321, 'username': 'your_username'}})

Because the incoming message is logged, you can get the group chat_id from incoming_msg['chat']['id'].

@azogue
Copy link
Member

azogue commented Jul 30, 2017

Hi @dullage,

Unless I list both the chat id and my user id in the allowed_chat_ids parameter then I receive a "Incoming message is not allowed" message in the HA log.

When targeting groups, you need to include both the group id (the negative number) and all the participants ids, because for listening the messages sent by them, all ids need to be allowed previously.

If a new user tries to send a message, HA will raise another error with all needed data to get the new id, so no need to leave HA.

@Landrash
Copy link
Contributor

@azogue Trying to follow the conversation. Rewrite this and merge or close since it's close enough?

@dullage
Copy link
Contributor Author

dullage commented Jul 30, 2017

Hi All,

My main goal with the PR was to clarify that we need to add user ids as well as chat ids if we are using a group. Azogues findings on being able to use the HA log to obtain these ids is very useful and I've added another commit which hopefully addresses this.

@azogue
Copy link
Member

azogue commented Jul 30, 2017

@Landrash, looks good to me!

@Landrash
Copy link
Contributor

Thank you @dullage & @azogue 🍰

@Landrash Landrash merged commit 06b6e4b into home-assistant:current Jul 30, 2017
@dullage dullage deleted the patch-2 branch July 30, 2017 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted Wanna help? Jump in!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants