mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Add telegram_bot.send_voice service (#43433)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
9043b7b214
commit
a4b1990487
@ -23,6 +23,7 @@ ATTR_KEYBOARD = "keyboard"
|
||||
ATTR_INLINE_KEYBOARD = "inline_keyboard"
|
||||
ATTR_PHOTO = "photo"
|
||||
ATTR_VIDEO = "video"
|
||||
ATTR_VOICE = "voice"
|
||||
ATTR_DOCUMENT = "document"
|
||||
|
||||
CONF_CHAT_ID = "chat_id"
|
||||
@ -65,7 +66,7 @@ class TelegramNotificationService(BaseNotificationService):
|
||||
keys = keys if isinstance(keys, list) else [keys]
|
||||
service_data.update(inline_keyboard=keys)
|
||||
|
||||
# Send a photo, video, document, or location
|
||||
# Send a photo, video, document, voice, or location
|
||||
if data is not None and ATTR_PHOTO in data:
|
||||
photos = data.get(ATTR_PHOTO)
|
||||
photos = photos if isinstance(photos, list) else [photos]
|
||||
@ -80,6 +81,13 @@ class TelegramNotificationService(BaseNotificationService):
|
||||
service_data.update(video_data)
|
||||
self.hass.services.call(DOMAIN, "send_video", service_data=service_data)
|
||||
return
|
||||
if data is not None and ATTR_VOICE in data:
|
||||
voices = data.get(ATTR_VOICE)
|
||||
voices = voices if isinstance(voices, list) else [voices]
|
||||
for voice_data in voices:
|
||||
service_data.update(voice_data)
|
||||
self.hass.services.call(DOMAIN, "send_voice", service_data=service_data)
|
||||
return
|
||||
if data is not None and ATTR_LOCATION in data:
|
||||
service_data.update(data.get(ATTR_LOCATION))
|
||||
return self.hass.services.call(
|
||||
|
@ -80,6 +80,7 @@ SERVICE_SEND_MESSAGE = "send_message"
|
||||
SERVICE_SEND_PHOTO = "send_photo"
|
||||
SERVICE_SEND_STICKER = "send_sticker"
|
||||
SERVICE_SEND_VIDEO = "send_video"
|
||||
SERVICE_SEND_VOICE = "send_voice"
|
||||
SERVICE_SEND_DOCUMENT = "send_document"
|
||||
SERVICE_SEND_LOCATION = "send_location"
|
||||
SERVICE_EDIT_MESSAGE = "edit_message"
|
||||
@ -224,6 +225,7 @@ SERVICE_MAP = {
|
||||
SERVICE_SEND_PHOTO: SERVICE_SCHEMA_SEND_FILE,
|
||||
SERVICE_SEND_STICKER: SERVICE_SCHEMA_SEND_FILE,
|
||||
SERVICE_SEND_VIDEO: SERVICE_SCHEMA_SEND_FILE,
|
||||
SERVICE_SEND_VOICE: SERVICE_SCHEMA_SEND_FILE,
|
||||
SERVICE_SEND_DOCUMENT: SERVICE_SCHEMA_SEND_FILE,
|
||||
SERVICE_SEND_LOCATION: SERVICE_SCHEMA_SEND_LOCATION,
|
||||
SERVICE_EDIT_MESSAGE: SERVICE_SCHEMA_EDIT_MESSAGE,
|
||||
@ -366,6 +368,7 @@ async def async_setup(hass, config):
|
||||
SERVICE_SEND_PHOTO,
|
||||
SERVICE_SEND_STICKER,
|
||||
SERVICE_SEND_VIDEO,
|
||||
SERVICE_SEND_VOICE,
|
||||
SERVICE_SEND_DOCUMENT,
|
||||
]:
|
||||
await hass.async_add_executor_job(
|
||||
@ -672,6 +675,7 @@ class TelegramNotificationService:
|
||||
SERVICE_SEND_PHOTO: self.bot.sendPhoto,
|
||||
SERVICE_SEND_STICKER: self.bot.sendSticker,
|
||||
SERVICE_SEND_VIDEO: self.bot.sendVideo,
|
||||
SERVICE_SEND_VOICE: self.bot.sendVoice,
|
||||
SERVICE_SEND_DOCUMENT: self.bot.sendDocument,
|
||||
}.get(file_type)
|
||||
file_content = load_data(
|
||||
|
@ -151,6 +151,46 @@ send_video:
|
||||
description: 'Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}'
|
||||
example: "msg_to_edit"
|
||||
|
||||
send_voice:
|
||||
description: Send a voice message.
|
||||
fields:
|
||||
url:
|
||||
description: Remote path to a voice message.
|
||||
example: "http://example.org/path/to/the/voice.opus"
|
||||
file:
|
||||
description: Local path to a voice message.
|
||||
example: "/path/to/the/voice.opus"
|
||||
caption:
|
||||
description: The title of the voice message.
|
||||
example: "My microphone recording"
|
||||
username:
|
||||
description: Username for a URL which require HTTP basic authentication.
|
||||
example: myuser
|
||||
password:
|
||||
description: Password for a URL which require HTTP basic authentication.
|
||||
example: myuser_pwd
|
||||
target:
|
||||
description: An array of pre-authorized chat_ids to send the document to. If not present, first allowed chat_id is the default.
|
||||
example: "[12345, 67890] or 12345"
|
||||
disable_notification:
|
||||
description: Sends the message silently. iOS users and Web users will not receive a notification, Android users will receive a notification with no sound.
|
||||
example: true
|
||||
verify_ssl:
|
||||
description: Enable or disable SSL certificate verification. Set to false if you're downloading the file from a URL and you don't want to validate the SSL certificate of the server.
|
||||
example: false
|
||||
timeout:
|
||||
description: Timeout for send voice. Will help with timeout errors (poor internet connection, etc)
|
||||
example: "1000"
|
||||
keyboard:
|
||||
description: List of rows of commands, comma-separated, to make a custom keyboard.
|
||||
example: '["/command1, /command2", "/command3"]'
|
||||
inline_keyboard:
|
||||
description: List of rows of commands, comma-separated, to make a custom inline keyboard with buttons with associated callback data.
|
||||
example: '["/button1, /button2", "/button3"] or [[["Text button1", "/button1"], ["Text button2", "/button2"]], [["Text button3", "/button3"]]]'
|
||||
message_tag:
|
||||
description: 'Tag for sent message. In telegram_sent event data: {{trigger.event.data.message_tag}}'
|
||||
example: "msg_to_edit"
|
||||
|
||||
send_document:
|
||||
description: Send a document.
|
||||
fields:
|
||||
|
Loading…
x
Reference in New Issue
Block a user