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

No way to put comma inside button on telegram bot keyboard #41750

Closed
notpurum opened this issue Oct 13, 2020 · 4 comments
Closed

No way to put comma inside button on telegram bot keyboard #41750

notpurum opened this issue Oct 13, 2020 · 4 comments

Comments

@notpurum
Copy link

notpurum commented Oct 13, 2020

The problem

For now there's no way to create a keyboard with a comma inside the button. The HA splits the button in two and there's no way to prevent it (At least I couldn't find one). This behavior is not expected in my opinion. There should be a way to create such keyboards, just like one shown on https://core.telegram.org/bots#keyboards
image

Environment

  • Home Assistant Core release with the issue: 0.115.6

Problem-relevant yaml

keyboard: 
  - "Yes, do vacuum"
  - "No, don't vacuum"

image

@probot-home-assistant
Copy link

telegram documentation
telegram source
(message by IssueLinks)

@otivedani
Copy link

after looking the code, currently this is how the argument parsed :

if ATTR_KEYBOARD in data:
keys = data.get(ATTR_KEYBOARD)
keys = keys if isinstance(keys, list) else [keys]
if keys:
params[ATTR_REPLYMARKUP] = ReplyKeyboardMarkup(
[[key.strip() for key in row.split(",")] for row in keys]
)
else:
params[ATTR_REPLYMARKUP] = ReplyKeyboardRemove(True)

possible change is, by using yaml array instead comma separator, so comma could be used in the layout text.

from this :

keyboard: 
  - "Yes, do vacuum"
  - "No, don't vacuum"

to this :

keyboard: 
  - ["Yes", "do vacuum"]
  - ["No", "don't vacuum"]

# or, 

keyboard: 
  - 
    - "Yes"
    - "do vacuum"
  - 
    - "No" 
    - "don't vacuum"

if it's ok, I want to make PR about this. please let me know what you think.

@notpurum
Copy link
Author

notpurum commented Oct 15, 2020

Well, what I would do is change
[[key.strip() for key in row.split(",")] for row in keys]
to
[[key.strip() for key in row.split(";")] for row in keys]

So that any time I want separate buttons I use semicolon, but when I use comma it stays comma. Like so:

keyboard: 
  - Yes, do vacuum; Yes, in 10 minutes
  - No, dont vacuum
Output:
[['Yes, do vacuum', 'Yes, in 10 minutes'], ['No, dont vacuum']]

This still seems to be not the best solution thou. And it might be not a correct solution at all since I'm very weak at yaml

@github-actions
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jan 13, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Feb 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants