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.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 form = Blather::Stanza::X.new(:result)
438 form.title = "Account Info"
439 form.fields = info.fields
440 reply.command << form
441 end
442 end
443}.register(self).then(&CommandList.method(:register))
444
445Command.new(
446 "usage",
447 "Show Monthly Usage"
448) {
449 report_for = (Date.today..(Date.today << 1))
450
451 Command.customer.then { |customer|
452 customer.usage_report(report_for)
453 }.then do |usage_report|
454 Command.finish do |reply|
455 reply.command << usage_report.form
456 end
457 end
458}.register(self).then(&CommandList.method(:register))
459
460Command.new(
461 "configure calls",
462 "Configure Calls",
463 customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
464) {
465 Command.customer.then do |customer|
466 cc_form = ConfigureCallsForm.new(customer)
467 Command.reply { |reply|
468 reply.allowed_actions = [:next]
469 reply.command << cc_form.render
470 }.then { |iq|
471 EMPromise.all(cc_form.parse(iq.form).map { |k, v|
472 Command.execution.customer_repo.public_send("put_#{k}", customer, v)
473 })
474 }.then { Command.finish("Configuration saved!") }
475 end
476}.register(self).then(&CommandList.method(:register))
477
478Command.new(
479 "ogm",
480 "Record Voicemail Greeting",
481 list_for: ->(fwd: nil, **) { !!fwd },
482 customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
483) {
484 Command.customer.then do |customer|
485 customer.fwd.create_call(CONFIG[:creds][:account]) do |cc|
486 cc.from = customer.registered?.phone
487 cc.application_id = CONFIG[:sip][:app]
488 cc.answer_url = "#{CONFIG[:web_root]}/ogm/start?" \
489 "customer_id=#{customer.customer_id}"
490 end
491 Command.finish("You will now receive a call.")
492 end
493}.register(self).then(&CommandList.method(:register))
494
495Command.new(
496 "migrate billing",
497 "Switch from PayPal or expired trial to new billing",
498 list_for: ->(tel:, customer:, **) { tel && !customer&.currency },
499 customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
500) {
501 EMPromise.all([
502 Command.customer,
503 Command.reply do |reply|
504 reply.allowed_actions = [:next]
505 reply.command << FormTemplate.render("migrate_billing")
506 end
507 ]).then do |(customer, iq)|
508 Registration::Payment.for(
509 iq, customer, customer.registered?.phone,
510 final_message: PaypalDone::MESSAGE,
511 finish: PaypalDone
512 ).then(&:write).catch_only(Command::Execution::FinalStanza) do |s|
513 BLATHER.join(CONFIG[:notify_admin], "sgx-jmp")
514 BLATHER.say(
515 CONFIG[:notify_admin],
516 "#{customer.customer_id} migrated to #{customer.currency}",
517 :groupchat
518 )
519 EMPromise.reject(s)
520 end
521 end
522}.register(self).then(&CommandList.method(:register))
523
524Command.new(
525 "credit cards",
526 "Credit Card Settings and Management"
527) {
528 Command.customer.then do |customer|
529 url = CONFIG[:credit_card_url].call(
530 customer.jid.to_s.gsub("\\", "%5C"),
531 customer.customer_id
532 )
533 desc = "Manage credits cards and settings"
534 Command.finish("#{desc}: #{url}") do |reply|
535 oob = OOB.find_or_create(reply.command)
536 oob.url = url
537 oob.desc = desc
538 end
539 end
540}.register(self).then(&CommandList.method(:register))
541
542Command.new(
543 "top up",
544 "Buy Account Credit by Credit Card",
545 list_for: ->(payment_methods: [], **) { !payment_methods.empty? },
546 format_error: ->(e) { "Failed to buy credit, system said: #{e.message}" }
547) {
548 Command.customer.then { |customer|
549 BuyAccountCreditForm.for(customer).then do |credit_form|
550 Command.reply { |reply|
551 reply.allowed_actions = [:complete]
552 credit_form.add_to_form(reply.form)
553 }.then do |iq|
554 Transaction.sale(customer, **credit_form.parse(iq.form))
555 end
556 end
557 }.then { |transaction|
558 transaction.insert.then do
559 Command.finish("#{transaction} added to your account balance.")
560 end
561 }.catch_only(BuyAccountCreditForm::AmountValidationError) do |e|
562 Command.finish(e.message, type: :error)
563 end
564}.register(self).then(&CommandList.method(:register))
565
566Command.new(
567 "alt top up",
568 "Buy Account Credit by Bitcoin, Mail, or Interac eTransfer",
569 list_for: ->(customer:, **) { !!customer&.currency }
570) {
571 Command.customer.then { |customer|
572 EMPromise.all([AltTopUpForm.for(customer), customer])
573 }.then do |(alt_form, customer)|
574 Command.reply { |reply|
575 reply.allowed_actions = [:complete]
576 reply.command << alt_form.form
577 }.then do |iq|
578 AddBitcoinAddress.for(iq, alt_form, customer).write
579 end
580 end
581}.register(self).then(&CommandList.method(:register))
582
583Command.new(
584 "referral codes",
585 "Refer a friend for free credit"
586) {
587 Command.customer.then(&:unused_invites).then do |invites|
588 if invites.empty?
589 Command.finish("You have no more invites right now, try again later.")
590 else
591 Command.finish do |reply|
592 reply.form.type = :result
593 reply.form.title = "Unused Invite Codes"
594 reply.form.instructions =
595 "Each of these codes is single use and gives the person using " \
596 "them a free month of JMP service. You will receive credit " \
597 "equivalent to one month of free service if they later become " \
598 "a paying customer."
599 FormTable.new(
600 invites.map { |i| [i] },
601 code: "Invite Code"
602 ).add_to_form(reply.form)
603 end
604 end
605 end
606}.register(self).then(&CommandList.method(:register))
607
608Command.new(
609 "reset sip account",
610 "Create or Reset SIP Account",
611 customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
612) {
613 Command.customer.then do |customer|
614 sip_account = customer.reset_sip_account
615 Command.reply { |reply|
616 reply.allowed_actions = [:next]
617 form = sip_account.form
618 form.type = :form
619 form.fields += [{
620 type: :boolean, var: "change_fwd",
621 label: "Should inbound calls forward to this SIP account?"
622 }]
623 reply.command << form
624 }.then do |fwd|
625 if ["1", "true"].include?(fwd.form.field("change_fwd")&.value.to_s)
626 Command.execution.customer_repo.put_fwd(
627 customer,
628 customer.fwd.with(uri: sip_account.uri)
629 ).then { Command.finish("Inbound calls will now forward to SIP.") }
630 else
631 Command.finish
632 end
633 end
634 end
635}.register(self).then(&CommandList.method(:register))
636
637Command.new(
638 "lnp",
639 "Port in your number from another carrier",
640 list_for: ->(**) { true }
641) {
642 using FormToH
643
644 EMPromise.all([
645 Command.customer,
646 Command.reply do |reply|
647 reply.allowed_actions = [:next]
648 reply.command << FormTemplate.render("lnp")
649 end
650 ]).then do |(customer, iq)|
651 order = PortInOrder.new(iq.form.to_h.slice(
652 "BillingTelephoneNumber", "Subscriber", "WirelessInfo"
653 ).merge("CustomerOrderId" => customer.customer_id))
654 order_id = BandwidthIris::PortIn.create(order.to_h)[:order_id]
655 url = "https://dashboard.bandwidth.com/portal/r/a/" \
656 "#{CONFIG[:creds][:account]}/orders/portIn/#{order_id}"
657 BLATHER.join(CONFIG[:notify_admin], "sgx-jmp")
658 BLATHER.say(
659 CONFIG[:notify_admin],
660 "New port-in request for #{customer.customer_id}: #{url}",
661 :groupchat
662 )
663 Command.finish(
664 "Your port-in request has been accepted, " \
665 "support will contact you with next steps"
666 )
667 end
668}.register(self).then(&CommandList.method(:register))
669
670Command.new(
671 "customer info",
672 "Show Customer Info",
673 list_for: ->(customer: nil, **) { customer&.admin? }
674) {
675 Command.customer.then do |customer|
676 raise AuthError, "You are not an admin" unless customer&.admin?
677
678 customer_info = CustomerInfoForm.new
679 Command.reply { |reply|
680 reply.allowed_actions = [:next]
681 reply.command << customer_info.picker_form
682 }.then { |response|
683 customer_info.find_customer(response)
684 }.then do |target_customer|
685 target_customer.admin_info.then do |info|
686 Command.finish do |reply|
687 form = Blather::Stanza::X.new(:result)
688 form.title = "Customer Info"
689 form.fields = info.fields
690 reply.command << form
691 end
692 end
693 end
694 end
695}.register(self).then(&CommandList.method(:register))
696
697def reply_with_note(iq, text, type: :info)
698 reply = iq.reply
699 reply.status = :completed
700 reply.note_type = type
701 reply.note_text = text
702
703 self << reply
704end
705
706command :execute?, node: "web-register" do |iq|
707 StatsD.increment("command", tags: ["node:#{iq.node}"])
708
709 sentry_hub = new_sentry_hub(iq, name: iq.node)
710
711 begin
712 jid = iq.form.field("jid")&.value.to_s.strip
713 tel = iq.form.field("tel")&.value.to_s.strip
714 sentry_hub.current_scope.set_user(jid: jid, tel: tel)
715 if iq.from.stripped != CONFIG[:web_register][:from]
716 BLATHER << iq.as_error("forbidden", :auth)
717 elsif jid == "" || tel !~ /\A\+\d+\Z/
718 reply_with_note(iq, "Invalid JID or telephone number.", type: :error)
719 else
720 IQ_MANAGER.write(Blather::Stanza::Iq::Command.new.tap { |cmd|
721 cmd.to = CONFIG[:web_register][:to]
722 cmd.node = "push-register"
723 cmd.form.fields = [{ var: "to", value: jid }]
724 cmd.form.type = "submit"
725 }).then { |result|
726 TEL_SELECTIONS.set(result.form.field("from")&.value.to_s.strip, tel)
727 }.then {
728 BLATHER << iq.reply.tap { |reply| reply.status = :completed }
729 }.catch { |e| panic(e, sentry_hub) }
730 end
731 rescue StandardError => e
732 sentry_hub.capture_exception(e)
733 end
734end
735
736command sessionid: /./ do |iq|
737 COMMAND_MANAGER.fulfill(iq)
738end
739
740iq type: [:result, :error] do |iq|
741 IQ_MANAGER.fulfill(iq)
742end
743
744iq type: [:get, :set] do |iq|
745 StatsD.increment("unknown_iq")
746
747 self << Blather::StanzaError.new(iq, "feature-not-implemented", :cancel)
748end