mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-25 23:26:48 +09:00
feat: Add bot API endpoint for adding reactions (boosts) to messages
Adds a new endpoint that allows bots to add emoji reactions (boosts) to messages: POST /rooms/:room_id/:bot_key/messages/:message_id/boosts This enables bots to acknowledge messages with reactions like 👀 (eyes) when mentioned, providing immediate feedback to users before generating a full response. The endpoint: - Validates the bot is a member of the room - Validates the message exists in the room - Broadcasts the boost to connected clients via Turbo Streams - Returns 201 Created on success, 404 if room/message not found Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
1 parent
e8c1349aac
commit
20ab5b1bc6
3 files changed
+110
No files matched your search
@@ -0,0 +1,33 @@
|
||||
class Messages::Boosts::ByBotsController < ApplicationController
|
||||
allow_bot_access only: :create
|
||||
|
||||
def create
|
||||
set_message
|
||||
@boost = @message.boosts.create!(content: read_body)
|
||||
|
||||
broadcast_create
|
||||
head :created
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
head :not_found
|
||||
end
|
||||
|
||||
private
|
||||
def set_message
|
||||
@room = Current.user.rooms.find(params[:room_id])
|
||||
@message = @room.messages.find(params[:message_id])
|
||||
end
|
||||
|
||||
def read_body
|
||||
request.body.rewind
|
||||
request.body.read.force_encoding("UTF-8")
|
||||
ensure
|
||||
request.body.rewind
|
||||
end
|
||||
|
||||
def broadcast_create
|
||||
@boost.broadcast_append_to @boost.message.room, :messages,
|
||||
target: "boosts_message_#{@boost.message.client_message_id}",
|
||||
partial: "messages/boosts/boost",
|
||||
attributes: { maintain_scroll: true }
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user