Skip to content

FIX: editing for AI generated images in chat #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion lib/discourse_chatbot/message/message_reply_creator.rb
Original file line number Diff line number Diff line change
@@ -20,17 +20,38 @@ def create
end
end

# if the message is picture, lets get the upload
upload = find_upload_from_markdown(@message_body)

# if the message is a picture, message body is just a placeholder
params = {
chat_channel_id: @topic_or_channel_id,
message: @message_body
}

params.merge!(thread_id: @thread_id) if @thread_id.present?

message = nil

Chat::CreateMessage.call(
params: params,
guardian: @guardian
)
) do
on_success { |message_instance:| message = message_instance }
end

# if there's an upload
# associate the upload with the message and
# remove the redundant message body
if upload && message
message.message = ""
message.cooked = ""
message.excerpt = ""
message.save!
message.uploads = [upload]
message.save!
end

begin
presence = PresenceChannel.new("/chat-reply/#{@topic_or_channel_id}")
presence.leave(user_id: @author.id, client_id: "12345")
@@ -44,5 +65,21 @@ def create
Rails.logger.error("Chatbot: There was a problem: #{e}")
end
end

private

def find_upload_from_markdown(string)
regex = /\A!\[([^\]]+)\|690x460\]\((upload:\/\/[^\s)]+)\)\z/
match = string.match(regex)
return nil unless match

short_url = match[2]

# Find the upload using the short_url
# This is a bit of a hack because short_url is not a field but a method
Upload.order(id: :desc).limit(5).each do |upload|
return upload if upload.short_url == short_url
end
end
end
end
4 changes: 1 addition & 3 deletions plugin.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# frozen_string_literal: true
# name: discourse-chatbot
# about: a plugin that allows you to have a conversation with a configurable chatbot in Discourse Chat, Topics and Private Messages
# version: 1.5.3
# version: 1.5.4
# authors: merefield
# url: https://github.com/merefield/discourse-chatbot

gem 'mime-types-data', '3.2025.0422', { require: false }
gem 'mime-types', '3.6.2', { require: false }
gem 'multipart-post', '2.4.0', { require: false }
gem 'faraday-multipart', '1.0.4', { require: false }
gem 'event_stream_parser', '1.0.0', { require: false }
Loading