Class: A2A::Operation::SendMessage

Inherits:
Object
  • Object
show all
Includes:
Executable
Defined in:
lib/a2a/operation/send_message.rb,
lib/a2a/operation/send_message/configuration.rb

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

METHOD =
"SendMessage"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Executable

#execute

Constructor Details

#initialize(message, configuration: {}, metadata: nil, tenant: nil) ⇒ SendMessage

Returns a new instance of SendMessage.



14
15
16
17
18
19
20
21
22
23
# File 'lib/a2a/operation/send_message.rb', line 14

def initialize(message, configuration: {}, metadata: nil, tenant: nil)
  @message = message.is_a?(Message) ? message : Message.from_h(message)
  @configuration = if configuration.is_a?(Configuration)
                     configuration
                   else
                     Configuration.new(**configuration.transform_keys(&:to_sym))
                   end
  @metadata = 
  @tenant = tenant
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



12
13
14
# File 'lib/a2a/operation/send_message.rb', line 12

def configuration
  @configuration
end

#messageObject (readonly)

Returns the value of attribute message.



12
13
14
# File 'lib/a2a/operation/send_message.rb', line 12

def message
  @message
end

#metadataObject (readonly)

Returns the value of attribute metadata.



12
13
14
# File 'lib/a2a/operation/send_message.rb', line 12

def 
  @metadata
end

#tenantObject (readonly)

Returns the value of attribute tenant.



12
13
14
# File 'lib/a2a/operation/send_message.rb', line 12

def tenant
  @tenant
end

Instance Method Details

#execute_http_json(protocol) ⇒ Object



32
33
34
# File 'lib/a2a/operation/send_message.rb', line 32

def execute_http_json(protocol)
  parse_result(protocol.post("/message:send", body: params))
end

#execute_json_rpc(protocol) ⇒ Object



25
26
27
28
29
30
# File 'lib/a2a/operation/send_message.rb', line 25

def execute_json_rpc(protocol)
  raw = protocol.post(METHOD, params)
  raise A2A.from_json_rpc_error(raw["error"]) if raw["error"]

  parse_result(Hash(raw["result"]))
end

#paramsObject



36
37
38
39
40
41
42
43
# File 'lib/a2a/operation/send_message.rb', line 36

def params
  p = { "message" => message.to_h }
  config_h = configuration.to_h
  p["configuration"] = config_h unless config_h.empty?
  p["metadata"] =  if 
  p["tenant"] = tenant if tenant
  p
end