mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 22:25:03 +08:00
582de0ffe3
Blocks allow BOTS to augment the capacities of a chat message. At the moment only one block is available: `actions`, accepting only one type of element: `button`. <img width="708" alt="Screenshot 2024-11-15 at 19 14 02" src="https://github.com/user-attachments/assets/63f32a29-05b1-4f32-9edd-8d8e1007d705"> # Usage ```ruby Chat::CreateMessage.call( params: { message: "Welcome!", chat_channel_id: 2, blocks: [ { type: "actions", elements: [ { value: "foo", type: "button", text: { text: "How can I install themes?", type: "plain_text" } } ] } ] }, guardian: Discourse.system_user.guardian ) ``` # Documentation ## Blocks ### Actions Holds interactive elements: button. #### Fields | Field | Type | Description | Required? | |--------|--------|--------|--------| | type | string | For an actions block, type is always `actions` | Yes | | elements | array | An array of interactive elements, maximum 10 elements | Yes | | block_id | string | An unique identifier for the block, will be generated if not specified. It has to be unique per message | No | #### Example ```json { "type": "actions", "block_id": "actions_1", "elements": [...] } ``` ## Elements ### Button #### Fields | Field | Type | Description | Required? | |--------|--------|--------|--------| | type | string | For a button, type is always `button` | Yes | | text | object | A text object holding the type and text. Max 75 characters | Yes | | value | string | The value returned after the interaction has been validated. Maximum length is 2000 characters | No | | style | string | Can be `primary` , `success` or `danger` | No | | action_id | string | An unique identifier for the action, will be generated if not specified. It has to be unique per message | No | #### Example ```json { "type": "actions", "block_id": "actions_1", "elements": [ { "type": "button", "text": { "type": "plain_text", "text": "Ok" }, "value": "ok", "action_id": "button_1" } ] } ``` ## Interactions When a user interactions with a button the following flow will happen: - We send an interaction request to the server - Server checks if the user can make this interaction - If the user can make this interaction, the server will: * `DiscourseEvent.trigger(:chat_message_interaction, interaction)` * return a JSON document ```json { "interaction": { "user": { "id": 1, "username": "j.jaffeux" }, "channel": { "id": 1, "title": "Staff" }, "message": { "id": 1, "text": "test", "user_id": -1 }, "action": { "text": { "text": "How to install themes?", "type": "plain_text" }, "type": "button", "value": "click_me_123", "action_id": "bf4f30b9-de99-4959-b3f5-632a6a1add04" } } } ``` * Fire a `appEvents.trigger("chat:message_interaction", interaction)` |
||
---|---|---|
.. | ||
admin | ||
chat/composer | ||
chat_message | ||
drawer | ||
list_channels | ||
page_objects | ||
reply_to_message | ||
select_message | ||
shortcuts | ||
thread_list | ||
thread_tracking | ||
user_menu_notifications | ||
user_status | ||
about_page_site_acitivity_spec.rb | ||
admin_sidebar_navigation_spec.rb | ||
anonymous_spec.rb | ||
archive_channel_spec.rb | ||
bookmark_message_spec.rb | ||
browse_page_spec.rb | ||
channel_members_page_spec.rb | ||
channel_message_upload_spec.rb | ||
channel_settings_page_spec.rb | ||
channel_thread_message_echoing_spec.rb | ||
chat_channel_spec.rb | ||
chat_composer_draft_spec.rb | ||
chat_composer_spec.rb | ||
chat_footer_spec.rb | ||
chat_message_creator_spec.rb | ||
chat_message_interaction_spec.rb | ||
chat_message_onebox_spec.rb | ||
chat_new_message_spec.rb | ||
closed_channel_spec.rb | ||
create_channel_spec.rb | ||
dates_separators_spec.rb | ||
deleted_channel_spec.rb | ||
deleted_message_spec.rb | ||
document_title_spec.rb | ||
drawer_spec.rb | ||
edited_message_spec.rb | ||
flag_message_spec.rb | ||
hashtag_autocomplete_spec.rb | ||
invite_users_to_channel_spec.rb | ||
kick_user_from_channel_spec.rb | ||
mention_warnings_spec.rb | ||
message_errors_spec.rb | ||
message_notifications_mobile_spec.rb | ||
message_notifications_with_sidebar_spec.rb | ||
message_thread_indicator_spec.rb | ||
message_user_info_spec.rb | ||
move_message_to_channel_spec.rb | ||
navigation_spec.rb | ||
react_to_message_spec.rb | ||
read_only_spec.rb | ||
removing_channel_spec.rb | ||
restore_message_spec.rb | ||
reviewables_spec.rb | ||
send_message_spec.rb | ||
separate_sidebar_mode_spec.rb | ||
sidebar_navigation_menu_spec.rb | ||
sidebars_spec.rb | ||
silenced_user_spec.rb | ||
single_thread_spec.rb | ||
thread_preview_spec.rb | ||
transcript_spec.rb | ||
unfollow_dm_channel_spec.rb | ||
update_last_read_spec.rb | ||
uploads_spec.rb | ||
user_card_spec.rb | ||
user_chat_preferences_spec.rb | ||
user_profile_spec.rb | ||
user_threads_spec.rb | ||
visit_channel_spec.rb |