2023-03-17 21:24:38 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
Chat::Engine.routes.draw do
|
|
|
|
namespace :api, defaults: { format: :json } do
|
|
|
|
get "/chatables" => "chatables#index"
|
|
|
|
get "/channels" => "channels#index"
|
2023-12-11 14:38:07 +08:00
|
|
|
get "/me/channels" => "current_user_channels#index"
|
|
|
|
get "/me/threads" => "current_user_threads#index"
|
2023-03-17 21:24:38 +08:00
|
|
|
post "/channels" => "channels#create"
|
2024-04-25 16:47:54 +08:00
|
|
|
put "/channels/read" => "channels_read#update_all"
|
|
|
|
put "/channels/:channel_id/read" => "channels_read#update"
|
2023-11-29 01:24:09 +08:00
|
|
|
post "/channels/:channel_id/messages/:message_id/flags" => "channels_messages_flags#create"
|
2023-11-22 18:54:23 +08:00
|
|
|
post "/channels/:channel_id/drafts" => "channels_drafts#create"
|
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 14:07:58 +08:00
|
|
|
post "/channels/:channel_id/messages/:message_id/interactions" =>
|
|
|
|
"channels_messages_interactions#create"
|
2023-03-17 21:24:38 +08:00
|
|
|
delete "/channels/:channel_id" => "channels#destroy"
|
|
|
|
put "/channels/:channel_id" => "channels#update"
|
|
|
|
get "/channels/:channel_id" => "channels#show"
|
|
|
|
put "/channels/:channel_id/status" => "channels_status#update"
|
2023-07-27 15:57:03 +08:00
|
|
|
get "/channels/:channel_id/messages" => "channel_messages#index"
|
2023-10-23 16:40:30 +08:00
|
|
|
put "/channels/:channel_id/messages/:message_id" => "channel_messages#update"
|
2023-03-17 21:24:38 +08:00
|
|
|
post "/channels/:channel_id/messages/moves" => "channels_messages_moves#create"
|
2024-02-20 16:49:19 +08:00
|
|
|
delete "/channels/:channel_id/messages/:message_id/streaming" =>
|
|
|
|
"channels_messages_streaming#destroy"
|
2023-10-25 00:51:33 +08:00
|
|
|
post "/channels/:channel_id/invites" => "channels_invites#create"
|
2023-03-17 21:24:38 +08:00
|
|
|
post "/channels/:channel_id/archives" => "channels_archives#create"
|
|
|
|
get "/channels/:channel_id/memberships" => "channels_memberships#index"
|
2023-11-10 18:29:28 +08:00
|
|
|
post "/channels/:channel_id/memberships" => "channels_memberships#create"
|
2023-03-17 21:24:38 +08:00
|
|
|
delete "/channels/:channel_id/memberships/me" => "channels_current_user_membership#destroy"
|
2023-11-30 00:48:14 +08:00
|
|
|
delete "/channels/:channel_id/memberships/me/follows" =>
|
|
|
|
"channels_current_user_membership_follows#destroy"
|
|
|
|
put "/channels/:channel_id/memberships/me" => "channels_current_user_membership#update"
|
2023-03-17 21:24:38 +08:00
|
|
|
post "/channels/:channel_id/memberships/me" => "channels_current_user_membership#create"
|
|
|
|
put "/channels/:channel_id/notifications-settings/me" =>
|
|
|
|
"channels_current_user_notifications_settings#update"
|
|
|
|
|
|
|
|
# Category chatables controller hints. Only used by staff members, we don't want to leak category permissions.
|
|
|
|
get "/category-chatables/:id/permissions" => "category_chatables#permissions",
|
|
|
|
:format => :json,
|
|
|
|
:constraints => StaffConstraint.new
|
|
|
|
|
|
|
|
# Hints for JIT warnings.
|
|
|
|
get "/mentions/groups" => "hints#check_group_mentions", :format => :json
|
|
|
|
|
2023-05-10 17:42:32 +08:00
|
|
|
get "/channels/:channel_id/threads" => "channel_threads#index"
|
2023-09-16 00:09:45 +08:00
|
|
|
post "/channels/:channel_id/threads" => "channel_threads#create"
|
2023-05-10 17:42:32 +08:00
|
|
|
put "/channels/:channel_id/threads/:thread_id" => "channel_threads#update"
|
2023-03-17 21:24:38 +08:00
|
|
|
get "/channels/:channel_id/threads/:thread_id" => "channel_threads#show"
|
2023-07-27 15:57:03 +08:00
|
|
|
get "/channels/:channel_id/threads/:thread_id/messages" => "channel_thread_messages#index"
|
2024-04-25 16:47:54 +08:00
|
|
|
put "/channels/:channel_id/threads/:thread_id/read" => "channels_threads_read#update"
|
2023-11-22 18:54:23 +08:00
|
|
|
post "/channels/:channel_id/threads/:thread_id/drafts" => "channels_threads_drafts#create"
|
2023-06-16 10:08:26 +08:00
|
|
|
put "/channels/:channel_id/threads/:thread_id/notifications-settings/me" =>
|
|
|
|
"channel_threads_current_user_notifications_settings#update"
|
2024-04-29 17:20:01 +08:00
|
|
|
post "/channels/:channel_id/threads/:thread_id/mark-thread-title-prompt-seen/me" =>
|
|
|
|
"channel_threads_current_user_title_prompt_seen#update"
|
2023-07-03 08:18:37 +08:00
|
|
|
post "/direct-message-channels" => "direct_messages#create"
|
|
|
|
|
2023-04-24 07:32:04 +08:00
|
|
|
put "/channels/:channel_id/messages/:message_id/restore" => "channel_messages#restore"
|
2023-04-04 07:30:38 +08:00
|
|
|
delete "/channels/:channel_id/messages/:message_id" => "channel_messages#destroy"
|
2024-05-22 19:57:00 +08:00
|
|
|
delete "/channels/:channel_id/messages" => "channel_messages#bulk_destroy"
|
2023-03-17 21:24:38 +08:00
|
|
|
end
|
|
|
|
|
2023-06-21 20:13:36 +08:00
|
|
|
namespace :admin, defaults: { format: :json, constraints: StaffConstraint.new } do
|
|
|
|
post "export/messages" => "export#export_messages"
|
|
|
|
end
|
|
|
|
|
2023-03-17 21:24:38 +08:00
|
|
|
# direct_messages_controller routes
|
|
|
|
get "/direct_messages" => "direct_messages#index"
|
|
|
|
|
|
|
|
# incoming_webhooks_controller routes
|
|
|
|
post "/hooks/:key" => "incoming_webhooks#create_message"
|
|
|
|
|
|
|
|
# incoming_webhooks_controller routes
|
|
|
|
post "/hooks/:key/slack" => "incoming_webhooks#create_message_slack_compatible"
|
|
|
|
|
|
|
|
# chat_controller routes
|
|
|
|
get "/" => "chat#respond"
|
2024-02-20 18:08:57 +08:00
|
|
|
get "/new-message" => "chat#respond"
|
2024-01-16 14:29:33 +08:00
|
|
|
get "/direct-messages" => "chat#respond"
|
|
|
|
get "/channels" => "chat#respond"
|
2023-12-11 14:38:07 +08:00
|
|
|
get "/threads" => "chat#respond"
|
2023-03-17 21:24:38 +08:00
|
|
|
get "/browse" => "chat#respond"
|
|
|
|
get "/browse/all" => "chat#respond"
|
|
|
|
get "/browse/closed" => "chat#respond"
|
|
|
|
get "/browse/open" => "chat#respond"
|
|
|
|
get "/browse/archived" => "chat#respond"
|
|
|
|
post "/dismiss-retention-reminder" => "chat#dismiss_retention_reminder"
|
|
|
|
put ":chat_channel_id/react/:message_id" => "chat#react"
|
|
|
|
put "/:chat_channel_id/:message_id/rebake" => "chat#rebake"
|
|
|
|
post "/:chat_channel_id/quote" => "chat#quote_messages"
|
|
|
|
put "/user_chat_enabled/:user_id" => "chat#set_user_chat_status"
|
2023-09-07 14:57:29 +08:00
|
|
|
post "/:chat_channel_id" => "api/channel_messages#create"
|
2023-11-29 01:24:09 +08:00
|
|
|
|
2023-03-17 21:24:38 +08:00
|
|
|
get "/emojis" => "emojis#index"
|
|
|
|
|
|
|
|
base_c_route = "/c/:channel_title/:channel_id"
|
|
|
|
get base_c_route => "chat#respond", :as => "channel"
|
|
|
|
get "#{base_c_route}/:message_id" => "chat#respond"
|
|
|
|
|
|
|
|
%w[info info/about info/members info/settings].each do |route|
|
|
|
|
get "#{base_c_route}/#{route}" => "chat#respond"
|
|
|
|
end
|
|
|
|
|
|
|
|
# /channel -> /c redirects
|
|
|
|
get "/channel/:channel_id", to: redirect("/chat/c/-/%{channel_id}")
|
|
|
|
|
|
|
|
get "#{base_c_route}/t/:thread_id" => "chat#respond"
|
2023-07-27 15:57:03 +08:00
|
|
|
get "#{base_c_route}/t/:thread_id/:message_id" => "chat#respond"
|
2023-03-17 21:24:38 +08:00
|
|
|
|
|
|
|
base_channel_route = "/channel/:channel_id/:channel_title"
|
|
|
|
redirect_base = "/chat/c/%{channel_title}/%{channel_id}"
|
|
|
|
|
|
|
|
get base_channel_route, to: redirect(redirect_base)
|
|
|
|
|
|
|
|
%w[info info/about info/members info/settings].each do |route|
|
|
|
|
get "#{base_channel_route}/#{route}", to: redirect("#{redirect_base}/#{route}")
|
|
|
|
end
|
|
|
|
end
|