Class: FlowChat::Ussd::Gateway::Nsano
- Inherits:
-
Object
- Object
- FlowChat::Ussd::Gateway::Nsano
- Includes:
- Instrumentation
- Defined in:
- lib/flow_chat/ussd/gateway/nsano.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #call(context) ⇒ Object
-
#initialize(app) ⇒ Nsano
constructor
A new instance of Nsano.
Methods included from Instrumentation
Constructor Details
#initialize(app) ⇒ Nsano
Returns a new instance of Nsano.
9 10 11 |
# File 'lib/flow_chat/ussd/gateway/nsano.rb', line 9 def initialize(app) @app = app end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/flow_chat/ussd/gateway/nsano.rb', line 7 def context @context end |
Instance Method Details
#call(context) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/flow_chat/ussd/gateway/nsano.rb', line 13 def call(context) @context = context controller = context["controller"] controller.request # Add timestamp for all requests context["request.timestamp"] = Time.current.iso8601 # Set a basic message_id (can be enhanced based on actual Nsano implementation) context["request.message_id"] = SecureRandom.uuid context["request.platform"] = :ussd # TODO: Implement Nsano-specific parameter parsing # For now, add basic instrumentation structure for when this is implemented # Placeholder instrumentation - indicates Nsano implementation is needed instrument(Events::MESSAGE_RECEIVED, { from: "TODO", # Would be parsed from Nsano params message: "TODO", # Would be actual user input session_id: "TODO", # Would be Nsano session ID gateway: :nsano, platform: :ussd, timestamp: context["request.timestamp"] }) # Process request with placeholder app call _, _, _, _ = @app.call(context) if @app # Placeholder response instrumentation instrument(Events::MESSAGE_SENT, { to: "TODO", # Would be actual phone number session_id: "TODO", # Would be Nsano session ID message: "TODO", # Would be actual response message message_type: "prompt", # Would depend on actual response type gateway: :nsano, platform: :ussd, content_length: 0, # Would be actual content length timestamp: context["request.timestamp"] }) # input = context["rack.input"].read # context["rack.input"].rewind # if input.present? # params = JSON.parse input # if params["network"].present? && params["UserSessionID"].present? # request_id = "nsano::request_id::#{params["UserSessionID"]}" # context["ussd.request"] = { # gateway: :nsano, # network: params["network"].to_sym, # msisdn: Phonelib.parse(params["msisdn"]).e164, # type: Config.cache&.read(request_id).present? ? :response : :initial, # input: params["msg"].presence, # network: params["network"] # } # end # end # status, headers, response = @app.call(context) # if context["ussd.response"].present? && context["ussd.request"][:gateway] == :nsano # if context["ussd.response"][:type] == :terminal # Config.cache&.write(request_id, nil) # else # Config.cache&.write(request_id, 1) # end # status = 200 # response = # { # USSDResp: { # action: (context["ussd.response"][:type] == :terminal) ? :prompt : :input, # menus: "", # title: context["ussd.response"][:body] # } # }.to_json # headers = headers.merge({"Content-Type" => "application/json", "Content-Length" => response.bytesize.to_s}) # response = [response] # end # [status, headers, response] end |