mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add telegram_sent event (#41159)
Co-authored-by: Heine Furubotten <hfurubotten@users.noreply.github.com>
This commit is contained in:
parent
7027b01a29
commit
a396f8f76f
@ -67,6 +67,7 @@ ATTR_USER_ID = "user_id"
|
|||||||
ATTR_USERNAME = "username"
|
ATTR_USERNAME = "username"
|
||||||
ATTR_VERIFY_SSL = "verify_ssl"
|
ATTR_VERIFY_SSL = "verify_ssl"
|
||||||
ATTR_TIMEOUT = "timeout"
|
ATTR_TIMEOUT = "timeout"
|
||||||
|
ATTR_MESSAGE_TAG = "message_tag"
|
||||||
|
|
||||||
CONF_ALLOWED_CHAT_IDS = "allowed_chat_ids"
|
CONF_ALLOWED_CHAT_IDS = "allowed_chat_ids"
|
||||||
CONF_PROXY_URL = "proxy_url"
|
CONF_PROXY_URL = "proxy_url"
|
||||||
@ -91,6 +92,7 @@ SERVICE_LEAVE_CHAT = "leave_chat"
|
|||||||
EVENT_TELEGRAM_CALLBACK = "telegram_callback"
|
EVENT_TELEGRAM_CALLBACK = "telegram_callback"
|
||||||
EVENT_TELEGRAM_COMMAND = "telegram_command"
|
EVENT_TELEGRAM_COMMAND = "telegram_command"
|
||||||
EVENT_TELEGRAM_TEXT = "telegram_text"
|
EVENT_TELEGRAM_TEXT = "telegram_text"
|
||||||
|
EVENT_TELEGRAM_SENT = "telegram_sent"
|
||||||
|
|
||||||
PARSER_HTML = "html"
|
PARSER_HTML = "html"
|
||||||
PARSER_MD = "markdown"
|
PARSER_MD = "markdown"
|
||||||
@ -136,6 +138,7 @@ BASE_SERVICE_SCHEMA = vol.Schema(
|
|||||||
vol.Optional(ATTR_KEYBOARD): vol.All(cv.ensure_list, [cv.string]),
|
vol.Optional(ATTR_KEYBOARD): vol.All(cv.ensure_list, [cv.string]),
|
||||||
vol.Optional(ATTR_KEYBOARD_INLINE): cv.ensure_list,
|
vol.Optional(ATTR_KEYBOARD_INLINE): cv.ensure_list,
|
||||||
vol.Optional(ATTR_TIMEOUT): cv.positive_int,
|
vol.Optional(ATTR_TIMEOUT): cv.positive_int,
|
||||||
|
vol.Optional(ATTR_MESSAGE_TAG): cv.string,
|
||||||
},
|
},
|
||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
)
|
)
|
||||||
@ -508,6 +511,7 @@ class TelegramNotificationService:
|
|||||||
ATTR_REPLY_TO_MSGID: None,
|
ATTR_REPLY_TO_MSGID: None,
|
||||||
ATTR_REPLYMARKUP: None,
|
ATTR_REPLYMARKUP: None,
|
||||||
ATTR_TIMEOUT: None,
|
ATTR_TIMEOUT: None,
|
||||||
|
ATTR_MESSAGE_TAG: None,
|
||||||
}
|
}
|
||||||
if data is not None:
|
if data is not None:
|
||||||
if ATTR_PARSER in data:
|
if ATTR_PARSER in data:
|
||||||
@ -522,6 +526,8 @@ class TelegramNotificationService:
|
|||||||
params[ATTR_DISABLE_WEB_PREV] = data[ATTR_DISABLE_WEB_PREV]
|
params[ATTR_DISABLE_WEB_PREV] = data[ATTR_DISABLE_WEB_PREV]
|
||||||
if ATTR_REPLY_TO_MSGID in data:
|
if ATTR_REPLY_TO_MSGID in data:
|
||||||
params[ATTR_REPLY_TO_MSGID] = data[ATTR_REPLY_TO_MSGID]
|
params[ATTR_REPLY_TO_MSGID] = data[ATTR_REPLY_TO_MSGID]
|
||||||
|
if ATTR_MESSAGE_TAG in data:
|
||||||
|
params[ATTR_MESSAGE_TAG] = data[ATTR_MESSAGE_TAG]
|
||||||
# Keyboards:
|
# Keyboards:
|
||||||
if ATTR_KEYBOARD in data:
|
if ATTR_KEYBOARD in data:
|
||||||
keys = data.get(ATTR_KEYBOARD)
|
keys = data.get(ATTR_KEYBOARD)
|
||||||
@ -548,12 +554,22 @@ class TelegramNotificationService:
|
|||||||
out = func_send(*args_msg, **kwargs_msg)
|
out = func_send(*args_msg, **kwargs_msg)
|
||||||
if not isinstance(out, bool) and hasattr(out, ATTR_MESSAGEID):
|
if not isinstance(out, bool) and hasattr(out, ATTR_MESSAGEID):
|
||||||
chat_id = out.chat_id
|
chat_id = out.chat_id
|
||||||
self._last_message_id[chat_id] = out[ATTR_MESSAGEID]
|
message_id = out[ATTR_MESSAGEID]
|
||||||
|
self._last_message_id[chat_id] = message_id
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Last message ID: %s (from chat_id %s)",
|
"Last message ID: %s (from chat_id %s)",
|
||||||
self._last_message_id,
|
self._last_message_id,
|
||||||
chat_id,
|
chat_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
event_data = {
|
||||||
|
ATTR_CHAT_ID: chat_id,
|
||||||
|
ATTR_MESSAGEID: message_id,
|
||||||
|
}
|
||||||
|
message_tag = kwargs_msg.get(ATTR_MESSAGE_TAG)
|
||||||
|
if message_tag is not None:
|
||||||
|
event_data[ATTR_MESSAGE_TAG] = message_tag
|
||||||
|
self.hass.bus.async_fire(EVENT_TELEGRAM_SENT, event_data)
|
||||||
elif not isinstance(out, bool):
|
elif not isinstance(out, bool):
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Update last message: out_type:%s, out=%s", type(out), out
|
"Update last message: out_type:%s, out=%s", type(out), out
|
||||||
|
@ -30,6 +30,9 @@ send_message:
|
|||||||
inline_keyboard:
|
inline_keyboard:
|
||||||
description: List of rows of commands, comma-separated, to make a custom inline keyboard with buttons with associated callback data.
|
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"] or [[["Text button1", "/button1"], ["Text button2", "/button2"]], [["Text button3", "/button3"]]]'
|
example: '["/button1, /button2", "/button3"] or ["Text button1:/button1, Text button2:/button2", "Text button3:/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_photo:
|
send_photo:
|
||||||
description: Send a photo.
|
description: Send a photo.
|
||||||
@ -67,6 +70,9 @@ send_photo:
|
|||||||
inline_keyboard:
|
inline_keyboard:
|
||||||
description: List of rows of commands, comma-separated, to make a custom inline keyboard with buttons with associated callback data.
|
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"]]]'
|
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_sticker:
|
send_sticker:
|
||||||
description: Send a sticker.
|
description: Send a sticker.
|
||||||
@ -101,6 +107,9 @@ send_sticker:
|
|||||||
inline_keyboard:
|
inline_keyboard:
|
||||||
description: List of rows of commands, comma-separated, to make a custom inline keyboard with buttons with associated callback data.
|
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"]]]'
|
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_video:
|
send_video:
|
||||||
description: Send a video.
|
description: Send a video.
|
||||||
@ -138,6 +147,9 @@ send_video:
|
|||||||
inline_keyboard:
|
inline_keyboard:
|
||||||
description: List of rows of commands, comma-separated, to make a custom inline keyboard with buttons with associated callback data.
|
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"]]]'
|
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:
|
send_document:
|
||||||
description: Send a document.
|
description: Send a document.
|
||||||
@ -175,6 +187,9 @@ send_document:
|
|||||||
inline_keyboard:
|
inline_keyboard:
|
||||||
description: List of rows of commands, comma-separated, to make a custom inline keyboard with buttons with associated callback data.
|
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"]]]'
|
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_location:
|
send_location:
|
||||||
description: Send a location.
|
description: Send a location.
|
||||||
@ -200,6 +215,9 @@ send_location:
|
|||||||
inline_keyboard:
|
inline_keyboard:
|
||||||
description: List of rows of commands, comma-separated, to make a custom inline keyboard with buttons with associated callback data.
|
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"]]]'
|
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"
|
||||||
|
|
||||||
edit_message:
|
edit_message:
|
||||||
description: Edit a previously sent message.
|
description: Edit a previously sent message.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user