~singpolyma/sgx-jmp

ref: 94766da41ffc065551de1aa7a268edf4f379f6da sgx-jmp/lib/backend_sgx.rb -rw-r--r-- 1.3 KiB
94766da4Stephen Paul Weber Support transcription disablement option 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
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
# frozen_string_literal: true

class BackendSgx
	VOICEMAIL_TRANSCRIPTION_DISABLED = 0

	def initialize(customer_id, jid=CONFIG[:sgx], creds=CONFIG[:creds])
		@customer_id = customer_id
		@jid = jid
		@creds = creds
	end

	def register!(tel)
		ibr = mkibr(:set)
		ibr.nick = @creds[:account]
		ibr.username = @creds[:username]
		ibr.password = @creds[:password]
		ibr.phone = tel
		IQ_MANAGER.write(ibr)
	end

	def registered?
		IQ_MANAGER.write(mkibr(:get)).catch { nil }.then do |result|
			if result&.respond_to?(:registered?) && result&.registered?
				result
			else
				false
			end
		end
	end

	def stanza(s)
		s.dup.tap do |stanza|
			stanza.to = stanza.to.with(domain: @jid)
			stanza.from = from_jid.with(resource: stanza.from.resource)
		end
	end

	def ogm_url
		REDIS.get("catapult_ogm_url-#{from_jid}")
	end

	def catapult_flag(flagbit)
		REDIS.getbit(
			"catapult_setting_flags-#{from_jid}",
			flagbit
		).then { |x| x != 1 }
	end

	def fwd_timeout
		REDIS.get("catapult_fwd_timeout-#{from_jid}")
	end

	def set_fwd_timeout(timeout)
		REDIS.set("catapult_fwd_timeout-#{from_jid}", timeout)
	end

protected

	def from_jid
		Blather::JID.new(
			"customer_#{@customer_id}",
			CONFIG[:component][:jid]
		)
	end

	def mkibr(type)
		ibr = IBR.new(type, @jid)
		ibr.from = from_jid
		ibr
	end
end