digest auth, explicit inline keyboards, more data in events (#2714)

This commit is contained in:
Eugenio Panadero 2017-05-26 22:54:09 +02:00 committed by Martin Hjelmare
parent a35de2ade5
commit 9c411db10e
2 changed files with 34 additions and 22 deletions

View File

@ -77,11 +77,11 @@ action:
service: notify.NOTIFIER_NAME
data:
title: '*Send a message*'
message: 'That's an example that _sends_ a *formatted* message with a custom keyboard.'
message: 'That's an example that _sends_ a *formatted* message with a custom inline keyboard.'
data:
keyboard:
- '/command1, /command2'
- '/command3, /command4'
inline_keyboard:
- 'Task 1:/command1, Task 2:/command2'
- 'Task 3:/command3, Task 4:/command4'
```
Configuration variables:
@ -115,8 +115,9 @@ Configuration variables:
- **url** or **file** (*Required*): For local or remote path to an image.
- **caption** (*Optional*): The title of the image.
- **username** (*Optional*): Username for a URL which require HTTP basic authentication.
- **password** (*Optional*): Username for a URL which require HTTP basic authentication.
- **username** (*Optional*): Username for a URL which require HTTP authentication.
- **password** (*Optional*): Username for a URL which require HTTP authentication.
- **authentication** (*Optional*): Set to 'digest' to use HTTP digest authentication, defaults to 'basic'.
- **keyboard** (*Optional*): List of rows of commands, comma-separated, to make a custom keyboard.
- **inline_keyboard** (*Optional*): List of rows of commands, comma-separated, to make a custom inline keyboard with buttons with asociated callback data.
@ -129,19 +130,23 @@ action:
service: notify.NOTIFIER_NAME
data:
title: Send a document
message: That's an example that sends a document.
message: That's an example that sends a document and a custom keyboard.
data:
document:
file: /tmp/whatever.odf
caption: Document Title xy
keyboard:
- '/command1, /command2'
- '/command3, /command4'
```
Configuration variables:
- **url** or **file** (*Required*): For local or remote path to a document.
- **caption** (*Optional*): The title of the document.
- **username** (*Optional*): Username for a URL which require HTTP basic authentication.
- **password** (*Optional*): Username for a URL which require HTTP basic authentication.
- **username** (*Optional*): Username for a URL which require HTTP authentication.
- **password** (*Optional*): Username for a URL which require HTTP authentication.
- **authentication** (*Optional*): Set to 'digest' to use HTTP digest authentication, defaults to 'basic'.
- **keyboard** (*Optional*): List of rows of commands, comma-separated, to make a custom keyboard.
- **inline_keyboard** (*Optional*): List of rows of commands, comma-separated, to make a custom inline keyboard with buttons with asociated callback data.
@ -163,7 +168,6 @@ action:
Configuration variables:
- **location** (*Required*): For local or remote path to an image.
- **latitude** (*Required*): The latitude to send.
- **longitude** (*Required*): The longitude to send.
- **keyboard** (*Optional*): List of rows of commands, comma-separated, to make a custom keyboard.

View File

@ -146,6 +146,7 @@ from_first: "<first name of the sender>"
from_last: "<last name of the sender>"
user_id: "<id of the sender>"
chat_id: "<origin chat id>"
chat: "<chat info>"
```
Any other message not starting with `/` will be processed as simple text, firing a `telegram_text` event on the event bus with the following `event_data`:
@ -156,6 +157,7 @@ from_first: "<first name of the sender>"
from_last: "<last name of the sender>"
user_id: "<id of the sender>"
chat_id: "<origin chat id>"
chat: "<chat info>"
```
if the message is sent from a [press from an inline button](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating), for example, a callback query is received, and Home Assistant will fire a `telegram_callback` event with:
@ -263,8 +265,8 @@ Text repeater:
message: 'You said: {% raw %}{{ trigger.event.data.text }}{% endraw %}'
disable_notification: true
inline_keyboard:
- '/edit,/NO'
- '/remove button'
- "Edit message:/edit_msg, Don't:/do_nothing"
- "Remove this button:/remove button"
```
Message editor:
@ -275,7 +277,7 @@ Message editor:
platform: event
event_type: telegram_callback
event_data:
data: '/edit'
data: '/edit_msg'
action:
- service: telegram_bot.answer_callback_query
data_template:
@ -288,8 +290,8 @@ Message editor:
chat_id: {% raw %}'{{ trigger.event.data.user_id }}'{% endraw %}
title: '*Message edit*'
inline_keyboard:
- '/edit,/NO'
- '/remove button'
- "Edit message:/edit_msg, Don't:/do_nothing"
- "Remove this button:/remove button"
message: >
{% raw %}Callback received from {% raw %}{{ trigger.event.data.from_first }}{% endraw %}.
Message id: {% raw %}{{ trigger.event.data.message.message_id }}{% endraw %}.
@ -315,7 +317,7 @@ Keyboard editor:
message_id: 'last'
chat_id: {% raw %}'{{ trigger.event.data.user_id }}'{% endraw %}
inline_keyboard:
- '/edit,/NO'
- "Edit message:/edit_msg, Don't:/do_nothing"
```
Only acknowledges the 'NO' answer:
@ -326,7 +328,7 @@ Only acknowledges the 'NO' answer:
platform: event
event_type: telegram_callback
event_data:
data: '/NO'
data: '/do_nothing'
action:
- service: telegram_bot.answer_callback_query
data_template:
@ -354,7 +356,9 @@ class TelegramBotEventListener(appapi.AppDaemon):
assert event_id == 'telegram_text'
user_id = payload_event['user_id']
msg = 'You said: ``` %s ```' % payload_event['text']
keyboard = ['/edit,/NO', '/remove button']
keyboard = [[("Edit message", "/edit_msg"),
("Don't", "/do_nothing")],
[("Remove this button", "/remove button")]]
self.call_service('telegram_bot/send_message',
title='*Dumb automation*',
target=user_id,
@ -368,8 +372,13 @@ class TelegramBotEventListener(appapi.AppDaemon):
data_callback = payload_event['data']
callback_id = payload_event['id']
user_id = payload_event['user_id']
# keyboard = ["Edit message:/edit_msg, Don't:/do_nothing",
# "Remove this button:/remove button"]
keyboard = [[("Edit message", "/edit_msg"),
("Don't", "/do_nothing")],
[("Remove this button", "/remove button")]]
if data_callback == '/edit': # Message editor:
if data_callback == '/edit_msg': # Message editor:
# Answer callback query
self.call_service('telegram_bot/answer_callback_query',
message='Editing the message!',
@ -381,7 +390,6 @@ class TelegramBotEventListener(appapi.AppDaemon):
user = payload_event['from_first']
title = '*Message edit*'
msg = 'Callback received from %s. Message id: %s. Data: ``` %s ```'
keyboard = ['/edit,/NO', '/remove button']
self.call_service('telegram_bot/edit_message',
chat_id=user_id,
message_id=msg_id,
@ -397,13 +405,13 @@ class TelegramBotEventListener(appapi.AppDaemon):
callback_query_id=callback_id)
# Edit the keyboard
new_keyboard = ['/edit,/NO']
new_keyboard = keyboard[:1]
self.call_service('telegram_bot/edit_replymarkup',
chat_id=user_id,
message_id='last',
inline_keyboard=new_keyboard)
elif data_callback == '/NO': # Only Answer to callback query
elif data_callback == '/do_nothing': # Only Answer to callback query
self.call_service('telegram_bot/answer_callback_query',
message='OK, you said no!',
callback_query_id=callback_id)