I work with XMPP, and I have a message callback that is activated in the event of each sent message. My goal is to send the data arriving as a message to the API in the callback, and based on the response, send something back using the XMPP client.
- User type message (browser chat client)
- The message is sent to the server via XMPP
- The message is sent to the API
- Answer received.
- The response is sent back to the chat client.
My code for this is as follows
admin_muc_client.activate_message_callbacks do |m|
sender = m.from.resource
room_slug = m.from.node
message = m.body
r = HTTParty.get('http://example.com/api/v1/query?msg=message')
Rails.logger.debug(r.inspect)
admin_muc_client.send_message("Message #{r.body}") if m.from.resource != 'admin'
end
, , , API , .
- AJAX Javascript, , , . Ruby?
delayed_job backgroundrb, . -, .
, . , RabbitMQ, , , .