discourse/plugins/chat/spec/system
Joffrey JAFFEUX 582de0ffe3
DEV: adds blocks support to chat messages (#29782)
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)`
2024-11-19 07:07:58 +01:00
..
admin FEATURE: Convert chat plugin UI to new show plugin and admin UI guidelines (#28632) 2024-09-10 15:16:16 +10:00
chat/composer FIX: ensures thread panel closes on escape (#29651) 2024-11-08 09:19:24 +09:00
chat_message DEV: Try until success for clipboard copies (#27986) 2024-07-19 19:44:10 +08:00
drawer DEV: rename chat preferred mobile index to chat preferred index (#27953) 2024-07-30 10:25:22 -03:00
list_channels UX: update chat channel sorting to include unread threads (#29617) 2024-11-08 12:31:03 +04:00
page_objects UX: update chat channel sorting to include unread threads (#29617) 2024-11-08 12:31:03 +04:00
reply_to_message FEATURE: supports mark tag in chat messages (#28949) 2024-09-17 20:52:34 +02:00
select_message FEATURE: thread pagination (#22624) 2023-07-27 09:57:03 +02:00
shortcuts FEATURE: Add keyboard shortcuts for jumping to unread channels (#29734) 2024-11-18 11:18:58 +11:00
thread_list FIX: build chat message excerpt for thread preview (#26765) 2024-04-26 14:29:35 +08:00
thread_tracking FEATURE: Add ability to watch chat threads (#28639) 2024-09-02 16:45:55 +04:00
user_menu_notifications DEV: cleanup chat desktop notification data (#28943) 2024-10-03 12:43:17 +04:00
user_status DEV: Remove assertion causing test to be flaky (#25069) 2023-12-29 13:23:16 +08:00
about_page_site_acitivity_spec.rb FEATURE: Enable the new /about page for everyone (#29390) 2024-10-29 18:40:11 +03:00
admin_sidebar_navigation_spec.rb DEV: adds logo page component (#28276) 2024-08-08 13:52:48 +02:00
anonymous_spec.rb DEV: Allow fab! without block (#24314) 2023-11-09 16:47:59 -06:00
archive_channel_spec.rb PERF: cook message in background (#24227) 2023-11-06 15:45:30 +01:00
bookmark_message_spec.rb FIX: chat bookmarks in drawer mode (#29757) 2024-11-14 17:20:11 +01:00
browse_page_spec.rb FIX: set channels tab as default on mobile chat footer (#25296) 2024-01-17 17:12:55 +08:00
channel_members_page_spec.rb FIX: correctly shows as disabled a user who can't chat (#26010) 2024-03-05 09:13:42 +01:00
channel_message_upload_spec.rb DEV: Fix various rubocop lints (#24749) 2023-12-06 23:25:00 +01:00
channel_settings_page_spec.rb FEATURE: enable threading in chat DM channels (#29170) 2024-10-11 13:05:07 +04:00
channel_thread_message_echoing_spec.rb DEV: makes every spec use new messages helper (#23163) 2023-08-21 16:31:58 +02:00
chat_channel_spec.rb FIX: correctly render unicode in channel page title (#29653) 2024-11-08 09:41:14 +09:00
chat_composer_draft_spec.rb PERF: Reduce overhead from chat message excerpt (#26712) 2024-04-25 14:29:00 +02:00
chat_composer_spec.rb DEV: Fix flaky network-based upload spec (#23286) 2023-08-28 12:59:22 +08:00
chat_footer_spec.rb FIX: show chat thread notifications for direct message channels (#29414) 2024-10-31 10:50:11 +04:00
chat_message_creator_spec.rb FIX: chat direct message group user limit is off by 1 (#27014) 2024-06-03 12:11:49 +04:00
chat_message_interaction_spec.rb DEV: adds blocks support to chat messages (#29782) 2024-11-19 07:07:58 +01:00
chat_message_onebox_spec.rb
chat_new_message_spec.rb FIX: new chat from url flaky fix (#27414) 2024-06-11 14:13:08 +04:00
closed_channel_spec.rb
create_channel_spec.rb DEV: Remove experimental site setting for chat threads (#22720) 2023-07-26 12:46:23 +02:00
dates_separators_spec.rb DEV: Remove the use of Capybara::Session#quit (#24978) 2023-12-20 13:20:14 +08:00
deleted_channel_spec.rb PERF: cook message in background (#24227) 2023-11-06 15:45:30 +01:00
deleted_message_spec.rb FEATURE: Allow to bulk delete chat messages (#26586) 2024-05-22 08:57:00 -03:00
document_title_spec.rb DEV: Fix flaky system test (#26479) 2024-04-03 10:04:48 +08:00
drawer_spec.rb FIX: adds chat-draw-expanded class to body (#28490) 2024-08-22 17:46:41 +02:00
edited_message_spec.rb DEV: Remove the use of Capybara::Session#quit (#24978) 2023-12-20 13:20:14 +08:00
flag_message_spec.rb UX: enhances chat copy features (#23770) 2023-10-04 16:14:37 +02:00
hashtag_autocomplete_spec.rb FEATURE: allows browse page in chat drawer (#27919) 2024-07-16 12:34:37 +02:00
invite_users_to_channel_spec.rb DEV: Provide user input to services using params key 2024-10-25 09:57:59 +02:00
kick_user_from_channel_spec.rb
mention_warnings_spec.rb PERF: defer loading channels (#26155) 2024-03-18 08:35:07 +01:00
message_errors_spec.rb FIX: show too long message error on client (#27794) 2024-07-09 18:34:35 +02:00
message_notifications_mobile_spec.rb FEATURE: allows browse page in chat drawer (#27919) 2024-07-16 12:34:37 +02:00
message_notifications_with_sidebar_spec.rb FIX: chat activity indicator wasn't working for threads 2024-05-22 17:42:59 +02:00
message_thread_indicator_spec.rb DEV: skip flaky system chat spec (#27737) 2024-07-05 15:27:07 +02:00
message_user_info_spec.rb DEV: Fix RSpec/SpecFilePathSuffix / enable 3 chat spec files (#24750) 2023-12-06 22:25:11 +01:00
move_message_to_channel_spec.rb FEATURE: Support designating multiple groups as mods on category (#28655) 2024-09-04 04:38:46 +03:00
navigation_spec.rb DEV: adds logo page component (#28276) 2024-08-08 13:52:48 +02:00
react_to_message_spec.rb DEV: Remove the use of Capybara::Session#quit (#24978) 2023-12-20 13:20:14 +08:00
read_only_spec.rb
removing_channel_spec.rb PERF: defer loading channels (#26155) 2024-03-18 08:35:07 +01:00
restore_message_spec.rb DEV: Remove the use of Capybara::Session#quit (#24978) 2023-12-20 13:20:14 +08:00
reviewables_spec.rb FIX: 500 error when reviewable has a missing message (#25113) 2024-01-03 11:49:54 -03:00
send_message_spec.rb FIX: correctly pass topic/posts context (#26882) 2024-05-06 15:33:00 +02:00
separate_sidebar_mode_spec.rb DEV: adds logo page component (#28276) 2024-08-08 13:52:48 +02:00
sidebar_navigation_menu_spec.rb UX: new sidebar styling (#29119) 2024-10-08 11:28:36 +02:00
sidebars_spec.rb DEV: Allow fab! without block (#24314) 2023-11-09 16:47:59 -06:00
silenced_user_spec.rb
single_thread_spec.rb FEATURE: allows browse page in chat drawer (#27919) 2024-07-16 12:34:37 +02:00
thread_preview_spec.rb DEV: prevents flakey spec (#25855) 2024-02-26 09:43:29 +01:00
transcript_spec.rb DEV: Try until success for clipboard copies (#27986) 2024-07-19 19:44:10 +08:00
unfollow_dm_channel_spec.rb DEV: Remove the use of Capybara::Session#quit (#24978) 2023-12-20 13:20:14 +08:00
update_last_read_spec.rb FIX: ensures last read is updated on new message (#26772) 2024-04-26 18:27:39 +02:00
uploads_spec.rb FIX: _uploadDropTargetOptions is now public (#29246) 2024-10-17 13:10:01 +09:00
user_card_spec.rb FEATURE: add chat direct message button to user profile (#26135) 2024-03-18 11:17:37 +08:00
user_chat_preferences_spec.rb FIX: correctly check chat tab is present (#23200) 2023-08-23 13:06:29 +02:00
user_profile_spec.rb FEATURE: add chat direct message button to user profile (#26135) 2024-03-18 11:17:37 +08:00
user_threads_spec.rb UX: add illustrations for empty chat list + split into tabs on drawer (#26910) 2024-05-28 17:00:04 +04:00
visit_channel_spec.rb DEV: Upgrade Rails to version 7.1 2024-07-04 10:58:21 +02:00