Lhc_fl
(Linca)
11월 12, 2023, 12:16오후
1
이제 PostCreator가 게시물의 작성자로 user를 지정하고, 게시 권한을 확인하기 위해 guardian을 사용할 수 있게 되었습니다. Discourse Chat에도 유사한 동작이 적용되기를 희망합니다. 이렇게 하면 플러그인이 사용자가 채팅 채널에 있는지 여부와 관계없이 시스템 사용자의 guardian을 사용하여 사용자를 대신해 메시지를 보낼 수 있게 됩니다.
channel.chatable.direct_message_users.find_or_create_by!(user: guardian.user)
end
end
end
def fetch_membership(guardian:, channel:)
channel.membership_for(guardian.user)
end
def fetch_reply(params:)
Chat::Message.find_by(id: params.in_reply_to_id)
end
def ensure_reply_consistency(channel:, params:, reply:)
return true if params.in_reply_to_id.blank?
reply&.chat_channel == channel
end
def fetch_thread(params:, reply:, channel:, options:)
return Chat::Thread.find_by(id: params.thread_id) if params.thread_id.present?
return unless reply
사용 예시: Discourse Automation 및 Chat 브리지에서는 플러그인에서 채팅 메시지를 보내야 합니다. 하지만 현재 이 스크립트는 지정된 사용자(예: DiscoBot)가 채널에 없을 가능성이 높기 때문에 전송에 실패할 가능성이 큽니다.
얼마 전, Discourse-Automation에서 채팅 메시지를 정기적으로 보내지 못하는 문제를 겪었습니다. 우리는 이를 사용하여 채팅 채널에 주간 뉴스를 보내고 있습니다. /logs를 확인해 보니 권한 문제로 인해 채팅 메시지 전송이 실패하고 있음을 발견했습니다.
discourse automation에 설정된 발신자는 관리자가 설정한 것이므로 채널의 권한 설정을 단순히 무시해야 한다고 생각합니다. 실제로 저는 메시징 사용자로서 DiscoBot을 사용하고 있습니다. DiscoBot은 채널에 바인딩된 카테고리에서 비활성 상태였기 때문에(물론) 자동으로 채널에서 제거되었고, 따라서 우리가 설정한 예약된 채팅 메시지는 전달할 수 없게 되었습니다.
잘 모르겠지만, 이건 #contribute:bug인 것 같습니다.
[discourse-automation] Chat message failed to send:
[1/25] [policy] 'no_silenced_user'
[2/25] …
script do |context, fields, automation|
sender = User.find_by(username: fields.dig("sender", "value")) || Discourse.system_user
channel = Chat::Channel.find_by(id: fields.dig("chat_channel_id", "value"))
placeholders = { channel_name: channel.title(sender) }.merge(context["placeholders"] || {})
creator =
::Chat::CreateMessage.call(
chat_channel_id: channel.id,
guardian: sender.guardian,
message: utils.apply_placeholders(fields.dig("message", "value"), placeholders),
)
if creator.failure?
Rails.logger.warn "[discourse-automation] Chat message failed to send:\n#{creator.inspect_steps.inspect}\n#{creator.inspect_steps.error}"
end
end
end
end
팀이 매우 바쁘다는 것을 알고 있으므로, 제가 직접 처리할 수 있습니다. Discourse 팀이 이 기능이 코어에 추가될 수 있다고 판단해 주신다면, 제가 시간을 내서 여기서 코드를 수정하고 풀 리퀘스트를 제출하겠습니다.
1개의 좋아요
Discourse Chatbot 은 코어에 특별한 변경 사항 없이 현재 코드로 유사한 문제를 해결했습니다. 제 해결책을 확인해 보셨나요?
module ::DiscourseChatbot
class MessageReplyCreator < ReplyCreator
def initialize(options = {})
super(options)
end
def create
::DiscourseChatbot.progress_debug_message("5. Creating a new Chat Nessage...")
begin
Chat::CreateMessage.call(
chat_channel_id: @topic_or_channel_id,
guardian: @guardian,
message: @message_body,
)
presence = PresenceChannel.new("/chat-reply/#{@topic_or_channel_id}")
presence.leave(user_id: @author.id, client_id: "12345")
::DiscourseChatbot.progress_debug_message("6. The Message has been created successfully")
rescue => e
1개의 좋아요
Lhc_fl
(Linca)
11월 14, 2023, 2:36오전
3
제안해 주셔서 정말 감사합니다! 한번 확인해 보겠습니다.
j.jaffeux
(Joffrey Jaffeux)
12월 4, 2023, 7:53오후
4
네, @merefield 님이 말씀하신 대로 채팅 서비스는 가디언을 허용하며, 가디언을 원하는 대로 설정할 수 있습니다.
1개의 좋아요
j.jaffeux
(Joffrey Jaffeux)
에 닫힘
12월 8, 2023, 7:54오후
5
이 주제는 마지막 답변 후 4일이 경과하여 자동으로 닫혔습니다. 더 이상 답변이 허용되지 않습니다.