mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Telegram webhooks new text event (#6301)
* new TELEGRAM_TEXT * telegram command event renamed in 'telegram_command' * fire telegram_text event anyway
This commit is contained in:
parent
d17733427b
commit
30bed8341a
@ -24,7 +24,8 @@ REQUIREMENTS = ['python-telegram-bot==5.3.0']
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
EVENT_TELEGRAM_COMMAND = 'telegram.command'
|
EVENT_TELEGRAM_COMMAND = 'telegram_command'
|
||||||
|
EVENT_TELEGRAM_TEXT = 'telegram_text'
|
||||||
|
|
||||||
TELEGRAM_HANDLER_URL = '/api/telegram_webhooks'
|
TELEGRAM_HANDLER_URL = '/api/telegram_webhooks'
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ DEFAULT_TRUSTED_NETWORKS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
ATTR_COMMAND = 'command'
|
ATTR_COMMAND = 'command'
|
||||||
|
ATTR_TEXT = 'text'
|
||||||
ATTR_USER_ID = 'user_id'
|
ATTR_USER_ID = 'user_id'
|
||||||
ATTR_ARGS = 'args'
|
ATTR_ARGS = 'args'
|
||||||
|
|
||||||
@ -118,15 +120,24 @@ class BotPushReceiver(HomeAssistantView):
|
|||||||
return self.json_message('Invalid user', HTTP_BAD_REQUEST)
|
return self.json_message('Invalid user', HTTP_BAD_REQUEST)
|
||||||
|
|
||||||
_LOGGER.debug("Received telegram data: %s", data)
|
_LOGGER.debug("Received telegram data: %s", data)
|
||||||
if not data['text'] or data['text'][:1] != '/':
|
if not data['text']:
|
||||||
_LOGGER.warning('no command')
|
_LOGGER.warning('no text')
|
||||||
return self.json({})
|
return self.json({})
|
||||||
|
|
||||||
pieces = data['text'].split(' ')
|
if data['text'][:1] == '/':
|
||||||
|
# telegram command "/blabla arg1 arg2 ..."
|
||||||
|
pieces = data['text'].split(' ')
|
||||||
|
|
||||||
request.app['hass'].bus.async_fire(EVENT_TELEGRAM_COMMAND, {
|
request.app['hass'].bus.async_fire(EVENT_TELEGRAM_COMMAND, {
|
||||||
ATTR_COMMAND: pieces[0],
|
ATTR_COMMAND: pieces[0],
|
||||||
ATTR_ARGS: " ".join(pieces[1:]),
|
ATTR_ARGS: " ".join(pieces[1:]),
|
||||||
|
ATTR_USER_ID: data['from']['id'],
|
||||||
|
})
|
||||||
|
|
||||||
|
# telegram text "bla bla"
|
||||||
|
request.app['hass'].bus.async_fire(EVENT_TELEGRAM_TEXT, {
|
||||||
|
ATTR_TEXT: data['text'],
|
||||||
ATTR_USER_ID: data['from']['id'],
|
ATTR_USER_ID: data['from']['id'],
|
||||||
})
|
})
|
||||||
|
|
||||||
return self.json({})
|
return self.json({})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user