notify chatwoot on port-in req

Phillip Davis created

Change summary

sgx_jmp.rb | 42 +++++++++++++++++++++++-------------------
1 file changed, 23 insertions(+), 19 deletions(-)

Detailed changes

sgx_jmp.rb 🔗

@@ -838,29 +838,33 @@ Command.new(
 Command.new(
 	"lnp",
 	"#️⃣ Port in your number from another carrier",
-	list_for: ->(**) { true }
+	list_for: ->(**) { true },
+	customer_repo: CustomerRepo.new(
+		sgx_repo: TrivialBackendSgxRepo.new(jid: notify_to)
+	)
 ) {
-	EMPromise.all([
-		Command.customer,
-		Command.reply do |reply|
+	Command.customer.then do |customer|
+		Command.reply { |reply|
 			reply.allowed_actions = [:next]
 			reply.command << FormTemplate.render("lnp")
+		}.then { |iq|
+			PortInOrder.parse(customer, iq.form).complete_with do |form|
+				Command.reply { |reply|
+					reply.allowed_actions = [:next]
+					reply.command << form
+				}.then(&:form)
+			end
+		}.then do |order|
+			order_id = BandwidthIris::PortIn.create(order.to_h)[:order_id]
+			customer.stanza_from(Blather::Stanza::Message.new(
+				"",
+				order.message(order_id)
+			))
+			Command.finish(
+				"Your port-in request has been accepted, " \
+				"support will contact you with next steps"
+			)
 		end
-	]).then { |(customer, iq)|
-		PortInOrder.parse(customer, iq.form).complete_with do |form|
-			Command.reply { |reply|
-				reply.allowed_actions = [:next]
-				reply.command << form
-			}.then(&:form)
-		end
-	}.then do |order|
-		order_id = BandwidthIris::PortIn.create(order.to_h)[:order_id]
-		BLATHER.join(CONFIG[:notify_admin], "sgx-jmp")
-		BLATHER.say(CONFIG[:notify_admin], order.message(order_id), :groupchat)
-		Command.finish(
-			"Your port-in request has been accepted, " \
-			"support will contact you with next steps"
-		)
 	end
 }.register(self).then(&CommandList.method(:register))