user_api/com/mdi/dialog/cloud_gate.rb
# Inject a message in the server queue on a specific channel (ie push a message to the server)
# @param [CloudConnectServices::Message] msg the message to inject
# @param [String] channel channel the message will be posted to
# @note Be wary of "infinite message loops" with this method.
Inject a message in the server queue on a specific channel
Inject a message in the server queue on a specific channel
def inject_message(msg, channel, origin_channel = default_origin_channel)
          begin
            PUNK.start('injectmsg','inject message in cloud ...')
            out_id = 00000
            user_api.mdi.dialog.protogen.protogen_encode(msg).each do |message|
              out_id = CC.indigen_next_id(message.asset)
              inject_hash = {
                "meta" => {
                  "account" =>     message.account,
                  "cookies" =>     message.cookies
                  },
                "payload" => {
                  "id" =>          out_id,     
                  "asset" =>       "ragent",
                  "sender" =>      send_channel,               
                  "recipient" =>   "@@server@@",               
                  "type" =>        "message",
                  "received_at" => Time.now.to_i,               
                  "channel" =>     channel,
                  "payload" =>     message.content,
                  "parent_id" =>   nil,                    
                  "timeout" =>     0                       
                }
              }
              inject_hash['meta'].delete_if { |k, v| v.nil? }
              inject_hash['payload'].delete_if { |k, v| v.nil? }
              CC.push(inject_hash,'messages')
            end
            PUNK.end('injectmsg','ok','out',"SERVER <- SERVER MSG[#{crop_ref(out_id,4)}]")
            SDK_STATS.stats['agents'][user_api.user_class.agent_name]['inject_to_cloud'] += 1
            SDK_STATS.stats['agents'][user_api.user_class.agent_name]['total_sent'] += 1
          rescue Exception => e
            user_api.mdi.tools.log.error("Error on inject message")
            user_api.mdi.tools.print_ruby_exception(e)
            PUNK.end('injectmsg','ko','out',"SERVER <- SERVER MSG")
            SDK_STATS.stats['agents'][user_api.user_class.agent_name]['err_on_inject'] += 1
            SDK_STATS.stats['agents'][user_api.user_class.agent_name]['total_error'] += 1
          end
        end
def inject_message ( msg , channel , origin_channel = default_origin_channel ) begin PUNK . start ( 'injectmsg' , 'inject message in cloud ...' ) out_id = 00000 user_api . mdi . dialog . protogen . protogen_encode ( msg ) . each do | message | out_id = CC . indigen_next_id ( message . asset ) inject_hash = { "meta" => { "account" => message . account , "cookies" => message . cookies } , "payload" => { "id" => out_id , "asset" => "ragent" , "sender" => send_channel , "recipient" => "@@server@@" , "type" => "message" , "received_at" => Time . now . to_i , "channel" => channel , "payload" => message . content , "parent_id" => nil , "timeout" => 0 } } inject_hash [ 'meta' ] . delete_if { | k , v | v . nil? } inject_hash [ 'payload' ] . delete_if { | k , v | v . nil? } CC . push ( inject_hash , 'messages' ) end PUNK . end ( 'injectmsg' , 'ok' , 'out' , "SERVER <- SERVER MSG[#{crop_ref(out_id,4)}]" ) SDK_STATS . stats [ 'agents' ] [ user_api . user_class . agent_name ] [ 'inject_to_cloud' ] += 1 SDK_STATS . stats [ 'agents' ] [ user_api . user_class . agent_name ] [ 'total_sent' ] += 1 rescue Exception => e user_api . mdi . tools . log . error ( "Error on inject message" ) user_api . mdi . tools . print_ruby_exception ( e ) PUNK . end ( 'injectmsg' , 'ko' , 'out' , "SERVER <- SERVER MSG" ) SDK_STATS . stats [ 'agents' ] [ user_api . user_class . agent_name ] [ 'err_on_inject' ] += 1 SDK_STATS . stats [ 'agents' ] [ user_api . user_class . agent_name ] [ 'total_error' ] += 1 end end
Inject a message in the server queue on a specific channel (ie push a message to the server)
Inject a message in the server queue on a specific channel ( ie push a message to the server )
# Indigen integer # Sender identifier (can be the same as the asset) # Recipient identifier (can be the same as the asset) # timestamp integer in seconds # nil | message_identifier # -1 | 0 | timeout integer. 0 -> instant # todo: put some limitation # success ! # stats:
msg
<not_specific>
channel
<not_specific>
origin_channel
<not_specific>
default_origin_channel
<not_specific>
<not_specific>
channel channel the message will be posted to
channel channel the message will be posted to
note
Be wary of "infinite message loops" with this method.
Be wary of " infinite message loops " with this method .