~singpolyma/sgx-jmp

be92f94e8b95ea2e7aa06f1fdea978b26d4744ca — Stephen Paul Weber 1 year, 7 months ago 33ea52c + 2506431
Merge branch 'passthrough-commands'

* passthrough-commands:
  Pass through commands we know the SGX can handle
  Pass everything from SGX to user, not just <message/>
  Remove some of the noise from the command list
1 files changed, 28 insertions(+), 22 deletions(-)

M sgx_jmp.rb
M sgx_jmp.rb => sgx_jmp.rb +28 -22
@@ 19,6 19,7 @@ CONFIG =
	.new(safe: Dhall::Coder::JSON_LIKE + [Symbol, Proc])
	.load(ARGV[0], transform_keys: ->(k) { k&.to_sym })

Blather::Stanza.handler_list << :stanza
singleton_class.class_eval do
	include Blather::DSL
	Blather::DSL.append_features(self)


@@ 139,16 140,16 @@ message to: /\Aaccount@/ do |m|
	end
end

message to: /\Acustomer_/, from: /@#{CONFIG[:sgx]}(\/|\Z)/ do |m|
	sentry_hub = new_sentry_hub(m, name: "message_customer")
stanza to: /\Acustomer_/, from: /@#{CONFIG[:sgx]}(\/|\Z)/ do |s|
	sentry_hub = new_sentry_hub(s, name: "stanza_customer")
	Customer.for_customer_id(
		m.to.node.delete_prefix("customer_")
	).then { |customer|
		sentry_hub.current_scope.set_user(
			id: customer.customer_id,
			jid: m.from.stripped.to_s
			jid: s.from.stripped.to_s
		)
		customer.stanza_to(m)
		customer.stanza_to(s)
	}.catch { |e| panic(e, sentry_hub) }
end



@@ 242,29 243,21 @@ end
disco_items node: "http://jabber.org/protocol/commands" do |iq|
	reply = iq.reply
	reply.items = [
		{ node: "number-display", name: "Display JMP Number" },
		{ node: "configure-calls", name: "Configure Calls" },
		# TODO: don't show this item if no braintree methods available
		# TODO: don't show this item if no plan for this customer
		{ node: "buy-credit", name: "Buy account credit" },
		{ node: "jabber:iq:register", name: "Register" },
		{ node: "usage", name: "Show Monthly Usage" },
		{ node: "reset sip account", name: "Create or Reset SIP Account" }
	].map do |item|
		Blather::Stanza::DiscoItems::Item.new(
			iq.to,
			"buy-credit",
			"Buy account credit"
		),
		Blather::Stanza::DiscoItems::Item.new(
			iq.to,
			"jabber:iq:register",
			"Register"
		),
		Blather::Stanza::DiscoItems::Item.new(
			iq.to,
			"usage",
			"Show Monthly Usage"
		),
		Blather::Stanza::DiscoItems::Item.new(
			iq.to,
			"reset sip account",
			"Create or Reset SIP Account"
			item[:node],
			item[:name]
		)
	]
	end
	self << reply
end



@@ 302,6 295,19 @@ def reply_with_note(iq, text, type: :info)
	self << reply
end

# Commands that just pass through to the SGX
command node: ["number-display", "configure-calls"] do |iq|
	sentry_hub = new_sentry_hub(iq, name: iq.node)
	Customer.for_jid(iq.from.stripped).then { |customer|
		sentry_hub.current_scope.set_user(
			id: customer.customer_id,
			jid: iq.from.stripped.to_s
		)

		customer.stanza_from(iq)
	}.catch { |e| panic(e, sentry_hub) }
end

command :execute?, node: "buy-credit", sessionid: nil do |iq|
	sentry_hub = new_sentry_hub(iq, name: iq.node)
	reply = iq.reply