Class: CustomerServiceIm::Message
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- CustomerServiceIm::Message
- Defined in:
- app/models/customer_service_im/message.rb
Instance Method Summary collapse
- #attachment_url ⇒ Object
- #broadcast_to_conversation ⇒ Object
- #from_staff? ⇒ Boolean
- #from_user? ⇒ Boolean
- #read! ⇒ Object
- #speech_recognize ⇒ Object
- #speech_unrecognized? ⇒ Boolean
- #target_receivable? ⇒ Boolean
Instance Method Details
#attachment_url ⇒ Object
66 67 68 69 70 |
# File 'app/models/customer_service_im/message.rb', line 66 def return if !.blob Rails.application.routes.url_helpers.rails_blob_url() end |
#broadcast_to_conversation ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'app/models/customer_service_im/message.rb', line 52 def broadcast_to_conversation = JSON.parse(ApplicationController.render partial: "customer_service_im/messages/message", locals: { message: self}) CustomerServiceIm::MessagesChannel.broadcast_to(conversation, ) if target_receivable? sent! end end |
#from_staff? ⇒ Boolean
44 45 46 |
# File 'app/models/customer_service_im/message.rb', line 44 def from_staff? receiver_type === 'User' end |
#from_user? ⇒ Boolean
40 41 42 |
# File 'app/models/customer_service_im/message.rb', line 40 def from_user? receiver_type === 'Staff' end |
#read! ⇒ Object
61 62 63 64 |
# File 'app/models/customer_service_im/message.rb', line 61 def read! conversation.(self) super end |
#speech_recognize ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/models/customer_service_im/message.rb', line 76 def speech_recognize result = TxAsr::SentenceRecognition.from() if result.success? update( content: result.data["Result"].presence || "[空白语音]" ) broadcast_to_conversation else logger = Logger.new Rails.root.join("log/speech_recognition.log") logger.error result.errors raise CustomerServiceIm::AsrRecognizeError.new(result.errors) end end |
#speech_unrecognized? ⇒ Boolean
72 73 74 |
# File 'app/models/customer_service_im/message.rb', line 72 def speech_unrecognized? .blob.present? && content.blank? end |
#target_receivable? ⇒ Boolean
48 49 50 |
# File 'app/models/customer_service_im/message.rb', line 48 def target_receivable? (from_user? && conversation.staff&.online?) || (from_staff? && user&.online?) end |