Telegram Bot services.yaml is incorrect making it impossible to speciufy target
The problem
https://github.com/home-assistant/core/blob/dev/homeassistant/components/telegram_bot/services.yaml#L17 specifies target as object which is incorrect as expected value is actually an int or an array of ints.
What version of Home Assistant Core has the issue?
2024.10.3
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Container
Integration causing the issue
telegram_bot
Link to integration documentation on our website
https://www.home-assistant.io/integrations/telegram_bot/
Diagnostics information
AppDeemon app:
await self.call_service("telegram_bot/send_message",
target=123456789,
message="test",
return_result=True)
Result:
{'id': 48, 'type': 'result', 'success': False, 'error': {'code': 'invalid_format', 'message': "expected a dictionary for dictionary value @ data['target']. Got ['123456789']"}, 'ad_status': 'OK', 'ad_duration': 0.0007150173187255859}
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response
It's incorrect for years: https://github.com/home-assistant/core/commit/d37a3cded059d0cde95eb5826ebf42a0e03f97dd but something has changed that now calling service with mismatched data type is throwing an error.
in services.yaml target is defined as object selector. That should accept both list and dictionary as far as I can see. not sure why it's not working then and what changed suddenly
I've been looking into websocket_api and telegram_bot components but can't seem to find a change that would trigger such an error
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.
I'm still experiencing this issue, rendering my telegram automations useless. Any hint on where to look to fix this would be great!
I'm still experiencing this issue, rendering my telegram automations useless. Any hint on where to look to fix this would be great!
It needs to be fixed here: https://github.com/home-assistant/core/blob/dev/homeassistant/components/telegram_bot/services.yaml#L17
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.
I'll give this a crack!
You need to specify parameters in service_data.
self.call_service('telegram_bot/send_message',
service_data={
"target": 123456789,
"message" : "test"
},
return_result=True
}
References: https://github.com/AppDaemon/appdaemon/issues/2371
I fixed this in my local installation. The issue is that the "target" keyword is overloaded in websocket API and shouldn't be used by telegram itself. Hence the errors. Patch in attach fixes it where I renamed "target" to "destination".
If helpful, happy to create formal PR for this.
`diff --git a/homeassistant/components/telegram_bot/init.py b/homeassistant/components/telegram_bot/init.py index 15e1f7d4f0e..212bcada133 100644 --- a/homeassistant/components/telegram_bot/init.py +++ b/homeassistant/components/telegram_bot/init.py @@ -81,7 +81,7 @@ ATTR_REPLY_TO_MSGID = "reply_to_message_id" ATTR_REPLYMARKUP = "reply_markup" ATTR_SHOW_ALERT = "show_alert" ATTR_STICKER_ID = "sticker_id" -ATTR_TARGET = "target" +ATTR_TARGET = "destination" ATTR_TEXT = "text" ATTR_URL = "url" ATTR_USER_ID = "user_id" diff --git a/homeassistant/components/telegram_bot/services.yaml b/homeassistant/components/telegram_bot/services.yaml index a09f4d8f79b..2fd760f8060 100644 --- a/homeassistant/components/telegram_bot/services.yaml +++ b/homeassistant/components/telegram_bot/services.yaml @@ -11,7 +11,7 @@ send_message: example: "Your Garage Door Friend" selector: text:
- target:
- destination: example: "[12345, 67890] or 12345" selector: object: @@ -88,7 +88,7 @@ send_photo: options: - "digest" - "bearer_token"
- target:
- destination: example: "[12345, 67890] or 12345" selector: object: @@ -164,7 +164,7 @@ send_sticker: options: - "digest" - "bearer_token"
- target:
- destination: example: "[12345, 67890] or 12345" selector: object: @@ -232,7 +232,7 @@ send_animation: options: - "digest" - "bearer_token"
- target:
- destination: example: "[12345, 67890] or 12345" selector: object: @@ -308,7 +308,7 @@ send_video: options: - "digest" - "bearer_token"
- target:
- destination: example: "[12345, 67890] or 12345" selector: object: @@ -384,7 +384,7 @@ send_voice: options: - "digest" - "bearer_token"
- target:
- destination: example: "[12345, 67890] or 12345" selector: object: @@ -452,7 +452,7 @@ send_document: options: - "digest" - "bearer_token"
- target:
- destination: example: "[12345, 67890] or 12345" selector: object: @@ -517,7 +517,7 @@ send_location: max: 180 step: 0.001 unit_of_measurement: "°"
- target:
- destination: example: "[12345, 67890] or 12345" selector: object: @@ -555,7 +555,7 @@ send_location:
send_poll: fields:
- target:
- destination: example: "[12345, 67890] or 12345" selector: object: diff --git a/homeassistant/components/telegram_bot/strings.json b/homeassistant/components/telegram_bot/strings.json index 8f4894f42a7..f7c37ccfec7 100644 --- a/homeassistant/components/telegram_bot/strings.json +++ b/homeassistant/components/telegram_bot/strings.json @@ -12,8 +12,8 @@ "name": "Title", "description": "Optional title for your notification. Will be composed as '%title\n%message'." },
-
"target": { -
"name": "Target",
-
"destination": { -
"name": "Destination", "description": "An array of pre-authorized chat IDs to send the notification to. If not present, first allowed chat ID is the default." }, "parse_mode": {
@@ -50,7 +50,7 @@ }, "message_thread_id": { "name": "Message thread ID",
-
"description": "Unique identifier for the target message thread (topic) of the forum; for forum supergroups only."
-
}, @@ -82,8 +82,8 @@ "name": "Authentication method", "description": "Define which authentication method to use. Set to"description": "Unique identifier for the destination message thread (topic) of the forum; for forum supergroups only." } }digestto use HTTP digest authentication, orbearer_tokenfor OAuth 2.0 bearer token authentication. Defaults tobasic." },
-
"target": { -
"name": "Target",
-
"destination": { -
"name": "Destination", "description": "An array of pre-authorized chat IDs to send the document to. If not present, first allowed chat ID is the default." }, "parse_mode": {
@@ -152,9 +152,9 @@ "name": "[%key:component::telegram_bot::services::send_photo::fields::authentication::name%]", "description": "[%key:component::telegram_bot::services::send_photo::fields::authentication::description%]" },
-
"target": { -
"name": "Target", -
"description": "[%key:component::telegram_bot::services::send_photo::fields::target::description%]"
-
"destination": { -
"name": "Destination", -
"description": "[%key:component::telegram_bot::services::send_photo::fields::destination::description%]" }, "disable_notification": { "name": "[%key:component::telegram_bot::services::send_message::fields::disable_notification::name%]",
@@ -218,9 +218,9 @@ "name": "[%key:component::telegram_bot::services::send_photo::fields::authentication::name%]", "description": "[%key:component::telegram_bot::services::send_photo::fields::authentication::description%]" },
-
"target": { -
"name": "Target", -
"description": "[%key:component::telegram_bot::services::send_photo::fields::target::description%]"
-
"destination": { -
"name": "Destination", -
"description": "[%key:component::telegram_bot::services::send_photo::fields::destination::description%]" }, "parse_mode": { "name": "Parse Mode",
@@ -288,9 +288,9 @@ "name": "[%key:component::telegram_bot::services::send_photo::fields::authentication::name%]", "description": "[%key:component::telegram_bot::services::send_photo::fields::authentication::description%]" },
-
"target": { -
"name": "Target", -
"description": "[%key:component::telegram_bot::services::send_photo::fields::target::description%]"
-
"destination": { -
"name": "Destination", -
"description": "[%key:component::telegram_bot::services::send_photo::fields::destination::description%]" }, "parse_mode": { "name": "[%key:component::telegram_bot::services::send_message::fields::parse_mode::name%]",
@@ -358,9 +358,9 @@ "name": "[%key:component::telegram_bot::services::send_photo::fields::authentication::name%]", "description": "[%key:component::telegram_bot::services::send_photo::fields::authentication::description%]" },
-
"target": { -
"name": "Target", -
"description": "[%key:component::telegram_bot::services::send_photo::fields::target::description%]"
-
"destination": { -
"name": "Destination", -
"description": "[%key:component::telegram_bot::services::send_photo::fields::destination::description%]" }, "disable_notification": { "name": "[%key:component::telegram_bot::services::send_message::fields::disable_notification::name%]",
@@ -424,9 +424,9 @@ "name": "[%key:component::telegram_bot::services::send_photo::fields::authentication::name%]", "description": "[%key:component::telegram_bot::services::send_photo::fields::authentication::description%]" },
-
"target": { -
"name": "Target", -
"description": "[%key:component::telegram_bot::services::send_photo::fields::target::description%]"
-
"destination": { -
"name": "Destination", -
"description": "[%key:component::telegram_bot::services::send_photo::fields::destination::description%]" }, "parse_mode": { "name": "[%key:component::telegram_bot::services::send_message::fields::parse_mode::name%]",
@@ -478,8 +478,8 @@ "name": "[%key:common::config_flow::data::longitude%]", "description": "The longitude to send." },
-
"target": { -
"name": "Target",
-
"destination": { -
"name": "Destination", "description": "An array of pre-authorized chat IDs to send the location to. If not present, first allowed chat ID is the default." }, "disable_notification": {
@@ -516,9 +516,9 @@ "name": "Send poll", "description": "Sends a poll.", "fields": {
-
"target": { -
"name": "Target", -
"description": "[%key:component::telegram_bot::services::send_location::fields::target::description%]"
-
"destination": { -
"name": "Destination", -
"description": "[%key:component::telegram_bot::services::send_location::fields::destination::description%]" }, "question": { "name": "Question",
`
Thanks for sharing the patch.
Renaming the target parameter does resolve the conflicting name but I would disagree with you on this PR since it creates a leaky abstraction between AppDaemon and the Telegram bot integration. The service_data parameter in AppDaemon is intended for this purpose and AppDaemon users should migrate accordingly if they upgrade to 4.5.x or later.
Just to note, other integrations using the target parameter would probably face the same issue.
The options for AppDaemon users are:
- stick to AppDaemon versions < 4.5.x
- use the
service_dataparameter (my recommendation)
I haven't use AppDaemon before; feel free to correct me if I misunderstood.
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.