Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion homeassistant/components/telegram_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
ATTR_USERNAME = "username"
ATTR_VERIFY_SSL = "verify_ssl"
ATTR_TIMEOUT = "timeout"
ATTR_RESULT_CODE = "result_code"
Comment thread
NikoM87 marked this conversation as resolved.
Outdated

CONF_ALLOWED_CHAT_IDS = "allowed_chat_ids"
CONF_PROXY_URL = "proxy_url"
Expand All @@ -91,6 +92,7 @@
EVENT_TELEGRAM_CALLBACK = "telegram_callback"
EVENT_TELEGRAM_COMMAND = "telegram_command"
EVENT_TELEGRAM_TEXT = "telegram_text"
EVENT_TELEGRAM_SENT = "telegram_sent"

PARSER_HTML = "html"
PARSER_MD = "markdown"
Expand Down Expand Up @@ -136,6 +138,7 @@
vol.Optional(ATTR_KEYBOARD): vol.All(cv.ensure_list, [cv.string]),
vol.Optional(ATTR_KEYBOARD_INLINE): cv.ensure_list,
vol.Optional(ATTR_TIMEOUT): cv.positive_int,
vol.Optional(ATTR_RESULT_CODE): vol.Coerce(int),
},
extra=vol.ALLOW_EXTRA,
)
Expand Down Expand Up @@ -500,6 +503,7 @@ def _make_row_inline_keyboard(row_keyboard):
ATTR_REPLY_TO_MSGID: None,
ATTR_REPLYMARKUP: None,
ATTR_TIMEOUT: None,
ATTR_RESULT_CODE: None,
}
if data is not None:
if ATTR_PARSER in data:
Expand All @@ -514,6 +518,8 @@ def _make_row_inline_keyboard(row_keyboard):
params[ATTR_DISABLE_WEB_PREV] = data[ATTR_DISABLE_WEB_PREV]
if ATTR_REPLY_TO_MSGID in data:
params[ATTR_REPLY_TO_MSGID] = data[ATTR_REPLY_TO_MSGID]
if ATTR_RESULT_CODE in data:
params[ATTR_RESULT_CODE] = data[ATTR_RESULT_CODE]
# Keyboards:
if ATTR_KEYBOARD in data:
keys = data.get(ATTR_KEYBOARD)
Expand All @@ -540,12 +546,21 @@ def _send_msg(self, func_send, msg_error, *args_msg, **kwargs_msg):
out = func_send(*args_msg, **kwargs_msg)
if not isinstance(out, bool) and hasattr(out, ATTR_MESSAGEID):
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(
"Last message ID: %s (from chat_id %s)",
self._last_message_id,
chat_id,
)

event_data = {}
event_data[ATTR_CHAT_ID] = chat_id
event_data[ATTR_MESSAGEID] = message_id
Comment thread
NikoM87 marked this conversation as resolved.
Outdated
result_code = kwargs_msg.get(ATTR_RESULT_CODE)
if result_code is not None:
Comment thread
NikoM87 marked this conversation as resolved.
Outdated
event_data[ATTR_RESULT_CODE] = result_code
self.hass.bus.async_fire(EVENT_TELEGRAM_SENT, event_data)
elif not isinstance(out, bool):
_LOGGER.warning(
"Update last message: out_type:%s, out=%s", type(out), out
Expand Down
18 changes: 18 additions & 0 deletions homeassistant/components/telegram_bot/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ send_message:
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"] or [[["Text button1", "/button1"], ["Text button2", "/button2"]], [["Text button3", "/button3"]]]'
result_code:
description: 'The response result code of the sent message. In telegram_sent event data: {{trigger.event.data.result_code}}'
example: 123

send_photo:
description: Send a photo.
Expand Down Expand Up @@ -67,6 +70,9 @@ send_photo:
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"]]]'
result_code:
description: 'The response result code of the sent message. In telegram_sent event data: {{trigger.event.data.result_code}}'
example: 123

send_sticker:
description: Send a sticker.
Expand Down Expand Up @@ -101,6 +107,9 @@ send_sticker:
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"]]]'
result_code:
description: 'The response result code of the sent message. In telegram_sent event data: {{trigger.event.data.result_code}}'
example: 123

send_video:
description: Send a video.
Expand Down Expand Up @@ -138,6 +147,9 @@ send_video:
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"]]]'
result_code:
description: 'The response result code of the sent message. In telegram_sent event data: {{trigger.event.data.result_code}}'
example: 123

send_document:
description: Send a document.
Expand Down Expand Up @@ -175,6 +187,9 @@ send_document:
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"]]]'
result_code:
description: 'The response result code of the sent message. In telegram_sent event data: {{trigger.event.data.result_code}}'
example: 123

send_location:
description: Send a location.
Expand All @@ -200,6 +215,9 @@ send_location:
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"]]]'
result_code:
description: 'The response result code of the sent message. In telegram_sent event data: {{trigger.event.data.result_code}}'
example: 123

edit_message:
description: Edit a previusly sent message.
Expand Down