forked from RocketChat/Rocket.Chat.Android
-
Notifications
You must be signed in to change notification settings - Fork 6
Buttons Inside Attachment Object Spec
mr_kite edited this page Jul 26, 2018
·
33 revisions
This is an implementation of rich message buttons inside the current attachments
object found in the Rocket.Chat message object.
This document assumes that the reader already has knowledge of the current message
and attachments
objects.
This implementation is modeled after Slack's button implementation.
New fields will be added to the current attachments object
:
-
actions
: (Required when the attachment contains buttons) A collection of actions to include in the attachment (slack offers many actions, including custom actions, but this spec will only describe action type = button). A maximum of 5 actions per attachment may be provided. (Array) -
button_alignment
: (Optional) Buttons in the attachment will be vertical whenvertical
and horizontal whenhorizontal
. Default isvertical
. (String) -
temporary_buttons
: (Optional) Whentrue
, upon a button being clicked all active buttons disappear. (Boolean)
The Button action object contains these fields:
-
type
: (Required) Must bebutton
to tell Rocket Chat you want to render a button. (String) -
text
: (Required ifimage_url
is not used) A UTF-8 string label for this button. Be brief but descriptive and actionable. (String) -
url
: (Optional) The fully qualified http or https URL to deliver users to. Invalid URLs will result in a message posted with the button omitted. If present the url will be opened in what is configured inis_webview
. (String)-
is_webview
: (Required withurl
) Iftrue
, then the URL will open in a configurably sizable webview. Iffalse
, then it will open in an embedded web browser (chrome custom tab on Android and SFSafariViewController on IOS). (Boolean)-
webview_height_ratio
: (Optional withis_webview
) Sets the height of the webview when it opens. Size options arecompact
,tall
,full
. The default isfull
. (String)
-
-
-
image_url
: (Required iftext
is not used) Location of an image to be rendered as the button. (String) NOTE: Not represented in the example above. -
msg
: (Optional) A text message that will either be sent back into the chat window on behalf of the user or sent back to the bot. (String)-
msg_in_chat_window
: (Required withmsg
) Indicates where themsg
is to be sent. Iftrue
then it will go into the chat window. Iffalse
then it will be sent back to the bot but not appear in the chat window. (Boolean)
-
Example JSON using button actions.
{
"messages": [
{
"msg": "<@W1A2BC3DD> approved your travel request. Book any airline you like by continuing below.",
"attachments": [
{
"title": "example button actions",
"actions": [
{
"type": "button",
"text": "Book flights 🛫",
"url": "https://flights.example.com/book/r123456",
"is_webview": false
},
{
"type": "button",
"text": "Cancel travel request",
"url": "https://requests.example.com/cancel/r123456",
"is_webview": false
},
{
"type": "button",
"image_url": "http://www.emoji.co.uk/files/phantom-open-emojis/travel-places-phantom/12698-airplane.png",
"url": "https://flights.example.com/book/r123456",
"is_webview": true,
"webview_height_ratio": "compact"
},
{
"type": "button",
"text": "Say hello?",
"msg": "Hello.",
"msg_in_chat_window": true
},
]
},
]
},
]
}