sgx_jmp.rb

  1# frozen_string_literal: true
  2
  3require "pg/em/connection_pool"
  4require "bandwidth"
  5require "bigdecimal"
  6require "blather/client/dsl" # Require this first to not auto-include
  7require "blather/client"
  8require "braintree"
  9require "date"
 10require "dhall"
 11require "em-hiredis"
 12require "em_promise"
 13require "ougai"
 14require "ruby-bandwidth-iris"
 15require "sentry-ruby"
 16require "statsd-instrument"
 17
 18$stdout.sync = true
 19LOG = Ougai::Logger.new($stdout)
 20LOG.level = ENV.fetch("LOG_LEVEL", "info")
 21LOG.formatter = Ougai::Formatters::Readable.new(
 22	nil,
 23	nil,
 24	plain: !$stdout.isatty
 25)
 26Blather.logger = LOG
 27EM::Hiredis.logger = LOG
 28StatsD.logger = LOG
 29LOG.info "Starting"
 30
 31Sentry.init do |config|
 32	config.logger = LOG
 33	config.breadcrumbs_logger = [:sentry_logger]
 34end
 35
 36module SentryOugai
 37	class SentryLogger
 38		include Sentry::Breadcrumb::SentryLogger
 39		include Singleton
 40	end
 41
 42	def _log(severity, message=nil, ex=nil, data=nil, &block)
 43		super
 44		SentryLogger.instance.add_breadcrumb(severity, message || ex.to_s, &block)
 45	end
 46end
 47LOG.extend SentryOugai
 48
 49CONFIG =
 50	Dhall::Coder
 51	.new(safe: Dhall::Coder::JSON_LIKE + [Symbol, Proc])
 52	.load(
 53		"(#{ARGV[0]}) : #{__dir__}/config-schema.dhall",
 54		transform_keys: ->(k) { k&.to_sym }
 55	)
 56WEB_LISTEN =
 57	if CONFIG[:web].is_a?(Hash)
 58		[CONFIG[:web][:interface], CONFIG[:web][:port]]
 59	else
 60		[CONFIG[:web]]
 61	end
 62
 63singleton_class.class_eval do
 64	include Blather::DSL
 65	Blather::DSL.append_features(self)
 66end
 67
 68require_relative "lib/polyfill"
 69require_relative "lib/alt_top_up_form"
 70require_relative "lib/add_bitcoin_address"
 71require_relative "lib/backend_sgx"
 72require_relative "lib/bwmsgsv2_repo"
 73require_relative "lib/bandwidth_iris_patch"
 74require_relative "lib/bandwidth_tn_order"
 75require_relative "lib/btc_sell_prices"
 76require_relative "lib/buy_account_credit_form"
 77require_relative "lib/configure_calls_form"
 78require_relative "lib/command"
 79require_relative "lib/command_list"
 80require_relative "lib/customer"
 81require_relative "lib/customer_info_form"
 82require_relative "lib/customer_repo"
 83require_relative "lib/electrum"
 84require_relative "lib/expiring_lock"
 85require_relative "lib/em"
 86require_relative "lib/form_to_h"
 87require_relative "lib/low_balance"
 88require_relative "lib/port_in_order"
 89require_relative "lib/payment_methods"
 90require_relative "lib/paypal_done"
 91require_relative "lib/registration"
 92require_relative "lib/transaction"
 93require_relative "lib/tel_selections"
 94require_relative "lib/session_manager"
 95require_relative "lib/statsd"
 96require_relative "web"
 97
 98ELECTRUM = Electrum.new(**CONFIG[:electrum])
 99EM::Hiredis::Client.load_scripts_from("./redis_lua")
100
101Faraday.default_adapter = :em_synchrony
102BandwidthIris::Client.global_options = {
103	account_id: CONFIG[:creds][:account],
104	username: CONFIG[:creds][:username],
105	password: CONFIG[:creds][:password]
106}
107BANDWIDTH_VOICE = Bandwidth::Client.new(
108	voice_basic_auth_user_name: CONFIG[:creds][:username],
109	voice_basic_auth_password: CONFIG[:creds][:password]
110).voice_client.client
111
112def new_sentry_hub(stanza, name: nil)
113	hub = Sentry.get_current_hub&.new_from_top
114	raise "Sentry.init has not been called" unless hub
115
116	hub.push_scope
117	hub.current_scope.clear_breadcrumbs
118	hub.current_scope.set_transaction_name(name) if name
119	hub.current_scope.set_user(jid: stanza.from.stripped.to_s)
120	hub
121end
122
123class AuthError < StandardError; end
124
125# Braintree is not async, so wrap in EM.defer for now
126class AsyncBraintree
127	def initialize(environment:, merchant_id:, public_key:, private_key:, **)
128		@gateway = Braintree::Gateway.new(
129			environment: environment,
130			merchant_id: merchant_id,
131			public_key: public_key,
132			private_key: private_key
133		)
134		@gateway.config.logger = LOG
135	end
136
137	def respond_to_missing?(m, *)
138		@gateway.respond_to?(m) || super
139	end
140
141	def method_missing(m, *args)
142		return super unless respond_to_missing?(m, *args)
143
144		EM.promise_defer(klass: PromiseChain) do
145			@gateway.public_send(m, *args)
146		end
147	end
148
149	class PromiseChain < EMPromise
150		def respond_to_missing?(*)
151			false && super # We don't actually know what we respond to...
152		end
153
154		def method_missing(m, *args)
155			return super if respond_to_missing?(m, *args)
156
157			self.then { |o| o.public_send(m, *args) }
158		end
159	end
160end
161
162BRAINTREE = AsyncBraintree.new(**CONFIG[:braintree])
163
164def panic(e, hub=nil)
165	(Thread.current[:log] || LOG).fatal(
166		"Error raised during event loop: #{e.class}",
167		e
168	)
169	if e.is_a?(::Exception)
170		(hub || Sentry).capture_exception(e, hint: { background: false })
171	else
172		(hub || Sentry).capture_message(e.to_s, hint: { background: false })
173	end
174	exit 1
175end
176
177EM.error_handler(&method(:panic))
178
179def poll_for_notify(db)
180	db.wait_for_notify_defer.then { |notify|
181		CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new).find(notify[:extra])
182	}.then(&LowBalance.method(:for)).then(&:notify!).then {
183		poll_for_notify(db)
184	}.catch(&method(:panic))
185end
186
187when_ready do
188	LOG.info "Ready"
189	BLATHER = self
190	REDIS = EM::Hiredis.connect
191	TEL_SELECTIONS = TelSelections.new
192	BTC_SELL_PRICES = BTCSellPrices.new(REDIS, CONFIG[:oxr_app_id])
193	DB = PG::EM::ConnectionPool.new(dbname: "jmp") { |conn|
194		conn.type_map_for_results = PG::BasicTypeMapForResults.new(conn)
195		conn.type_map_for_queries = PG::BasicTypeMapForQueries.new(conn)
196	}
197
198	DB.hold do |conn|
199		conn.query("LISTEN low_balance")
200		conn.query("SELECT customer_id FROM balances WHERE balance < 5").each do |c|
201			conn.query("SELECT pg_notify('low_balance', $1)", c.values)
202		end
203		poll_for_notify(conn)
204	end
205
206	EM.add_periodic_timer(3600) do
207		ping = Blather::Stanza::Iq::Ping.new(:get, CONFIG[:server][:host])
208		ping.from = CONFIG[:component][:jid]
209		self << ping
210	end
211
212	Web.run(LOG.child, *WEB_LISTEN)
213end
214
215# workqueue_count MUST be 0 or else Blather uses threads!
216setup(
217	CONFIG[:component][:jid],
218	CONFIG[:component][:secret],
219	CONFIG[:server][:host],
220	CONFIG[:server][:port],
221	nil,
222	nil,
223	workqueue_count: 0
224)
225
226message to: /\Aaccount@/, body: /./ do |m|
227	StatsD.increment("deprecated_account_bot")
228
229	self << m.reply.tap { |out|
230		out.body = "This bot is deprecated. Please talk to xmpp:cheogram.com"
231	}
232end
233
234before(
235	:iq,
236	type: [:error, :result],
237	to: /\Acustomer_/,
238	from: /(\A|@)#{CONFIG[:sgx]}(\/|\Z)/
239) { |iq| halt if IQ_MANAGER.fulfill(iq) }
240
241before nil, to: /\Acustomer_/, from: /(\A|@)#{CONFIG[:sgx]}(\/|\Z)/ do |s|
242	StatsD.increment("stanza_customer")
243
244	sentry_hub = new_sentry_hub(s, name: "stanza_customer")
245	CustomerRepo.new.find(
246		s.to.node.delete_prefix("customer_")
247	).then { |customer|
248		sentry_hub.current_scope.set_user(
249			id: customer.customer_id,
250			jid: s.from.stripped.to_s
251		)
252		customer.stanza_to(s)
253	}.catch { |e| panic(e, sentry_hub) }
254	halt
255end
256
257ADDRESSES_NS = "http://jabber.org/protocol/address"
258message(
259	to: /\A#{CONFIG[:component][:jid]}\Z/,
260	from: /(\A|@)#{CONFIG[:sgx]}(\/|\Z)/
261) do |m|
262	StatsD.increment("inbound_group_text")
263	sentry_hub = new_sentry_hub(m, name: "inbound_group_text")
264
265	address = m.find("ns:addresses", ns: ADDRESSES_NS).first
266		&.find("ns:address", ns: ADDRESSES_NS)
267		&.find { |el| el["jid"].to_s.start_with?("customer_") }
268	pass unless address
269
270	CustomerRepo.new.find_by_jid(address["jid"]).then { |customer|
271		m.from = m.from.with(domain: CONFIG[:component][:jid])
272		m.to = m.to.with(domain: customer.jid.domain)
273		address["jid"] = customer.jid.to_s
274		BLATHER << m
275	}.catch_only(CustomerRepo::NotFound) { |e|
276		BLATHER << m.as_error("forbidden", :auth, e.message)
277	}.catch { |e| panic(e, sentry_hub) }
278end
279
280# Ignore groupchat messages
281# Especially if we have the component join MUC for notifications
282message(type: :groupchat) { true }
283
284def billable_message(m)
285	(m.body && !m.body.empty?) || m.find("ns:x", ns: OOB.registered_ns).first
286end
287
288message do |m|
289	StatsD.increment("message")
290
291	sentry_hub = new_sentry_hub(m, name: "message")
292	today = Time.now.utc.to_date
293	CustomerRepo.new.find_by_jid(m.from.stripped).then { |customer|
294		sentry_hub.current_scope.set_user(
295			id: customer.customer_id, jid: m.from.stripped.to_s
296		)
297		EMPromise.all([
298			(customer.incr_message_usage if billable_message(m)),
299			customer.stanza_from(m)
300		]).then { customer }
301	}.then { |customer|
302		customer.message_usage((today..(today - 30))).then do |usage|
303			next unless usage > 500
304
305			ExpiringLock.new("jmp_usage_notify-#{customer.customer_id}").with do
306				BLATHER.join(CONFIG[:notify_admin], "sgx-jmp")
307				BLATHER.say(
308					CONFIG[:notify_admin], "#{customer.customer_id} has used #{usage} " \
309					"messages since #{today - 30}", :groupchat
310				)
311			end
312		end
313	}.catch_only(CustomerRepo::NotFound) { |e|
314		BLATHER << m.as_error("forbidden", :auth, e.message)
315	}.catch { |e| panic(e, sentry_hub) }
316end
317
318message :error? do |m|
319	StatsD.increment("message_error")
320
321	LOG.error "MESSAGE ERROR", stanza: m
322end
323
324IQ_MANAGER = SessionManager.new(self, :id)
325COMMAND_MANAGER = SessionManager.new(
326	self,
327	:sessionid,
328	timeout: 60 * 60,
329	error_if: ->(s) { s.cancel? }
330)
331
332disco_info to: Blather::JID.new(CONFIG[:component][:jid]) do |iq|
333	reply = iq.reply
334	reply.identities = [{
335		name: "JMP.chat",
336		type: "sms",
337		category: "gateway"
338	}]
339	reply.features = [
340		"http://jabber.org/protocol/disco#info",
341		"http://jabber.org/protocol/commands"
342	]
343	form = Blather::Stanza::X.find_or_create(reply.query)
344	form.type = "result"
345	form.fields = [
346		{
347			var: "FORM_TYPE",
348			type: "hidden",
349			value: "http://jabber.org/network/serverinfo"
350		}
351	] + CONFIG[:xep0157]
352	self << reply
353end
354
355disco_info do |iq|
356	reply = iq.reply
357	reply.identities = [{
358		name: "JMP.chat",
359		type: "sms",
360		category: "client"
361	}]
362	reply.features = [
363		"urn:xmpp:receipts"
364	]
365	self << reply
366end
367
368disco_items node: "http://jabber.org/protocol/commands" do |iq|
369	StatsD.increment("command_list")
370
371	sentry_hub = new_sentry_hub(iq, name: iq.node)
372	reply = iq.reply
373	reply.node = "http://jabber.org/protocol/commands"
374
375	CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new).find_by_jid(
376		iq.from.stripped
377	).catch {
378		nil
379	}.then { |customer|
380		CommandList.for(customer)
381	}.then { |list|
382		reply.items = list.map { |item|
383			Blather::Stanza::DiscoItems::Item.new(
384				iq.to,
385				item[:node],
386				item[:name]
387			)
388		}
389		self << reply
390	}.catch { |e| panic(e, sentry_hub) }
391end
392
393iq "/iq/ns:services", ns: "urn:xmpp:extdisco:2" do |iq|
394	StatsD.increment("extdisco")
395
396	reply = iq.reply
397	reply << Nokogiri::XML::Builder.new {
398		services(xmlns: "urn:xmpp:extdisco:2") do
399			service(
400				type: "sip",
401				host: CONFIG[:sip_host]
402			)
403		end
404	}.doc.root
405
406	self << reply
407end
408
409Command.new(
410	"jabber:iq:register",
411	"Register",
412	list_for: ->(*) { true },
413	customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
414) {
415	Command.customer.catch {
416		Sentry.add_breadcrumb(Sentry::Breadcrumb.new(message: "Customer.create"))
417		Command.execution.customer_repo.create(Command.execution.iq.from.stripped)
418	}.then { |customer|
419		Sentry.add_breadcrumb(Sentry::Breadcrumb.new(message: "Registration.for"))
420		Registration.for(customer, TEL_SELECTIONS).then(&:write)
421	}.then {
422		StatsD.increment("registration.completed")
423	}.catch_only(Command::Execution::FinalStanza) do |e|
424		StatsD.increment("registration.completed")
425		EMPromise.reject(e)
426	end
427}.register(self).then(&CommandList.method(:register))
428
429Command.new(
430	"info",
431	"Show Account Info",
432	list_for: ->(*) { true },
433	customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
434) {
435	Command.customer.then(&:info).then do |info|
436		Command.finish do |reply|
437			reply.command << info.form
438		end
439	end
440}.register(self).then(&CommandList.method(:register))
441
442Command.new(
443	"usage",
444	"Show Monthly Usage"
445) {
446	report_for = (Date.today..(Date.today << 1))
447
448	Command.customer.then { |customer|
449		customer.usage_report(report_for)
450	}.then do |usage_report|
451		Command.finish do |reply|
452			reply.command << usage_report.form
453		end
454	end
455}.register(self).then(&CommandList.method(:register))
456
457Command.new(
458	"configure calls",
459	"Configure Calls",
460	customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
461) {
462	Command.customer.then do |customer|
463		cc_form = ConfigureCallsForm.new(customer)
464		Command.reply { |reply|
465			reply.allowed_actions = [:next]
466			reply.command << cc_form.render
467		}.then { |iq|
468			EMPromise.all(cc_form.parse(iq.form).map { |k, v|
469				Command.execution.customer_repo.public_send("put_#{k}", customer, v)
470			})
471		}.then { Command.finish("Configuration saved!") }
472	end
473}.register(self).then(&CommandList.method(:register))
474
475Command.new(
476	"ogm",
477	"Record Voicemail Greeting",
478	list_for: ->(fwd: nil, **) { !!fwd },
479	customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
480) {
481	Command.customer.then do |customer|
482		customer.fwd.create_call(CONFIG[:creds][:account]) do |cc|
483			cc.from = customer.registered?.phone
484			cc.application_id = CONFIG[:sip][:app]
485			cc.answer_url = "#{CONFIG[:web_root]}/ogm/start?" \
486			                "customer_id=#{customer.customer_id}"
487		end
488		Command.finish("You will now receive a call.")
489	end
490}.register(self).then(&CommandList.method(:register))
491
492Command.new(
493	"migrate billing",
494	"Switch from PayPal or expired trial to new billing",
495	list_for: ->(tel:, customer:, **) { tel && !customer&.currency },
496	customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
497) {
498	EMPromise.all([
499		Command.customer,
500		Command.reply do |reply|
501			reply.allowed_actions = [:next]
502			reply.command << FormTemplate.render("migrate_billing")
503		end
504	]).then do |(customer, iq)|
505		Registration::Payment.for(
506			iq, customer, customer.registered?.phone,
507			final_message: PaypalDone::MESSAGE,
508			finish: PaypalDone
509		).then(&:write).catch_only(Command::Execution::FinalStanza) do |s|
510			BLATHER.join(CONFIG[:notify_admin], "sgx-jmp")
511			BLATHER.say(
512				CONFIG[:notify_admin],
513				"#{customer.customer_id} migrated to #{customer.currency}",
514				:groupchat
515			)
516			EMPromise.reject(s)
517		end
518	end
519}.register(self).then(&CommandList.method(:register))
520
521Command.new(
522	"credit cards",
523	"Credit Card Settings and Management"
524) {
525	Command.customer.then do |customer|
526		url = CONFIG[:credit_card_url].call(
527			customer.jid.to_s.gsub("\\", "%5C"),
528			customer.customer_id
529		)
530		desc = "Manage credits cards and settings"
531		Command.finish("#{desc}: #{url}") do |reply|
532			oob = OOB.find_or_create(reply.command)
533			oob.url = url
534			oob.desc = desc
535		end
536	end
537}.register(self).then(&CommandList.method(:register))
538
539Command.new(
540	"top up",
541	"Buy Account Credit by Credit Card",
542	list_for: ->(payment_methods: [], **) { !payment_methods.empty? },
543	format_error: ->(e) { "Failed to buy credit, system said: #{e.message}" }
544) {
545	Command.customer.then { |customer|
546		BuyAccountCreditForm.for(customer).then do |credit_form|
547			Command.reply { |reply|
548				reply.allowed_actions = [:complete]
549				credit_form.add_to_form(reply.form)
550			}.then do |iq|
551				Transaction.sale(customer, **credit_form.parse(iq.form))
552			end
553		end
554	}.then { |transaction|
555		transaction.insert.then do
556			Command.finish("#{transaction} added to your account balance.")
557		end
558	}.catch_only(BuyAccountCreditForm::AmountValidationError) do |e|
559		Command.finish(e.message, type: :error)
560	end
561}.register(self).then(&CommandList.method(:register))
562
563Command.new(
564	"alt top up",
565	"Buy Account Credit by Bitcoin, Mail, or Interac eTransfer",
566	list_for: ->(customer:, **) { !!customer&.currency }
567) {
568	Command.customer.then { |customer|
569		EMPromise.all([AltTopUpForm.for(customer), customer])
570	}.then do |(alt_form, customer)|
571		Command.reply { |reply|
572			reply.allowed_actions = [:complete]
573			reply.command << alt_form.form
574		}.then do |iq|
575			AddBitcoinAddress.for(iq, alt_form, customer).write
576		end
577	end
578}.register(self).then(&CommandList.method(:register))
579
580Command.new(
581	"referral codes",
582	"Refer a friend for free credit"
583) {
584	Command.customer.then(&:unused_invites).then do |invites|
585		if invites.empty?
586			Command.finish("You have no more invites right now, try again later.")
587		else
588			Command.finish do |reply|
589				reply.form.type = :result
590				reply.form.title = "Unused Invite Codes"
591				reply.form.instructions =
592					"Each of these codes is single use and gives the person using " \
593					"them a free month of JMP service. You will receive credit " \
594					"equivalent to one month of free service if they later become " \
595					"a paying customer."
596				FormTable.new(
597					invites.map { |i| [i] },
598					code: "Invite Code"
599				).add_to_form(reply.form)
600			end
601		end
602	end
603}.register(self).then(&CommandList.method(:register))
604
605Command.new(
606	"reset sip account",
607	"Create or Reset SIP Account",
608	customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
609) {
610	Command.customer.then do |customer|
611		sip_account = customer.reset_sip_account
612		Command.reply { |reply|
613			reply.allowed_actions = [:next]
614			form = sip_account.form
615			form.type = :form
616			form.fields += [{
617				type: :boolean, var: "change_fwd",
618				label: "Should inbound calls forward to this SIP account?"
619			}]
620			reply.command << form
621		}.then do |fwd|
622			if ["1", "true"].include?(fwd.form.field("change_fwd")&.value.to_s)
623				Command.execution.customer_repo.put_fwd(
624					customer,
625					customer.fwd.with(uri: sip_account.uri)
626				).then { Command.finish("Inbound calls will now forward to SIP.") }
627			else
628				Command.finish
629			end
630		end
631	end
632}.register(self).then(&CommandList.method(:register))
633
634Command.new(
635	"lnp",
636	"Port in your number from another carrier",
637	list_for: ->(**) { true }
638) {
639	using FormToH
640
641	EMPromise.all([
642		Command.customer,
643		Command.reply do |reply|
644			reply.allowed_actions = [:next]
645			reply.command << FormTemplate.render("lnp")
646		end
647	]).then do |(customer, iq)|
648		order = PortInOrder.new(iq.form.to_h.slice(
649			"BillingTelephoneNumber", "Subscriber", "WirelessInfo"
650		).merge("CustomerOrderId" => customer.customer_id))
651		order_id = BandwidthIris::PortIn.create(order.to_h)[:order_id]
652		url = "https://dashboard.bandwidth.com/portal/r/a/" \
653		      "#{CONFIG[:creds][:account]}/orders/portIn/#{order_id}"
654		BLATHER.join(CONFIG[:notify_admin], "sgx-jmp")
655		BLATHER.say(
656			CONFIG[:notify_admin],
657			"New port-in request for #{customer.customer_id}: #{url}",
658			:groupchat
659		)
660		Command.finish(
661			"Your port-in request has been accepted, " \
662			"support will contact you with next steps"
663		)
664	end
665}.register(self).then(&CommandList.method(:register))
666
667Command.new(
668	"customer info",
669	"Show Customer Info",
670	list_for: ->(customer: nil, **) { customer&.admin? }
671) {
672	Command.customer.then do |customer|
673		raise AuthError, "You are not an admin" unless customer&.admin?
674
675		Command.reply { |reply|
676			reply.allowed_actions = [:next]
677			reply.command << FormTemplate.render("customer_picker")
678		}.then { |response|
679			CustomerInfoForm.new.find_customer(response)
680		}.then do |target_customer|
681			target_customer.admin_info.then do |info|
682				Command.finish do |reply|
683					reply.command << info.form
684				end
685			end
686		end
687	end
688}.register(self).then(&CommandList.method(:register))
689
690def reply_with_note(iq, text, type: :info)
691	reply = iq.reply
692	reply.status = :completed
693	reply.note_type = type
694	reply.note_text = text
695
696	self << reply
697end
698
699command :execute?, node: "web-register" do |iq|
700	StatsD.increment("command", tags: ["node:#{iq.node}"])
701
702	sentry_hub = new_sentry_hub(iq, name: iq.node)
703
704	begin
705		jid = iq.form.field("jid")&.value.to_s.strip
706		tel = iq.form.field("tel")&.value.to_s.strip
707		sentry_hub.current_scope.set_user(jid: jid, tel: tel)
708		if iq.from.stripped != CONFIG[:web_register][:from]
709			BLATHER << iq.as_error("forbidden", :auth)
710		elsif jid !~ /\./ || tel !~ /\A\+\d+\Z/
711			reply_with_note(iq, "Invalid JID or telephone number.", type: :error)
712		else
713			IQ_MANAGER.write(Blather::Stanza::Iq::Command.new.tap { |cmd|
714				cmd.to = CONFIG[:web_register][:to]
715				cmd.node = "push-register"
716				cmd.form.fields = [{ var: "to", value: jid }]
717				cmd.form.type = "submit"
718			}).then { |result|
719				TEL_SELECTIONS.set(result.form.field("from")&.value.to_s.strip, tel)
720			}.then {
721				BLATHER << iq.reply.tap { |reply| reply.status = :completed }
722			}.catch { |e| panic(e, sentry_hub) }
723		end
724	rescue StandardError => e
725		sentry_hub.capture_exception(e)
726	end
727end
728
729command sessionid: /./ do |iq|
730	COMMAND_MANAGER.fulfill(iq)
731end
732
733iq type: [:result, :error] do |iq|
734	IQ_MANAGER.fulfill(iq)
735end
736
737iq type: [:get, :set] do |iq|
738	StatsD.increment("unknown_iq")
739
740	self << Blather::StanzaError.new(iq, "feature-not-implemented", :cancel)
741end