Put Chatwoot Link in Admin Info (and link to new JID)

Christopher Vollick created

We made a change with the "direct_targets" that made it so support no
longer talks to phone numbers, but customer_blah@sgx.example.com

So, we no longer need to link to the phone number version of the jid,
but we now have this new one.

And while we're at it we also have a ticketing system that's based on
that same JID, so I'll make a link to that too.

Change summary

config-schema.dhall  |  1 +
config.dhall.sample  |  4 +++-
forms/admin_info.rb  | 20 ++++++++++++--------
lib/customer_info.rb | 11 +++++++++--
test/test_helper.rb  |  3 ++-
5 files changed, 27 insertions(+), 12 deletions(-)

Detailed changes

config-schema.dhall 🔗

@@ -46,6 +46,7 @@
 , sip : { app : Text, realm : Text }
 , sip_host : Text
 , snikket_hosting_api : Text
+, support_link : forall (customer_jid : Text) -> Text
 , upstream_domain : Text
 , web : < Inet : { interface : Text, port : Natural } | Unix : Text >
 , web_register : { from : Text, to : Text }

config.dhall.sample 🔗

@@ -86,5 +86,7 @@ in
 	upstream_domain = "example.net",
 	approved_domains = toMap { `example.com` = Some "customer_id" },
 	keepgo = Some { api_key = "", access_token = "" },
-	simpleswap_api_key = ""
+	simpleswap_api_key = "",
+	support_link = \(customer_jid: Text) ->
+		"http://localhost:3002/app/accounts/2/contacts/custom_attributes/jid/${customer_jid}"
 }

forms/admin_info.rb 🔗

@@ -63,11 +63,15 @@ field(
 	value: @admin_info.api.to_s
 )
 
-if @admin_info.info.tel
-	field(
-		var: "link",
-		label: "Link",
-		type: "jid-single",
-		value: "#{@admin_info.info.tel}@#{CONFIG[:upstream_domain]}"
-	)
-end
+field(
+	var: "link",
+	label: "Link",
+	type: "jid-single",
+	value: @admin_info.backend_jid
+)
+
+field(
+	var: "support_link",
+	label: "Support Link",
+	value: @admin_info.support_link
+)

lib/customer_info.rb 🔗

@@ -112,12 +112,14 @@ class AdminInfo
 		api API
 		call_info String
 		trust_level String
+		backend_jid String
 	end
 
 	def self.for(
 		customer,
 		trust_level_repo: TrustLevelRepo.new,
-		call_attempt_repo: CallAttemptRepo.new
+		call_attempt_repo: CallAttemptRepo.new,
+		backend_repo: TrivialBackendSgxRepo.new
 	)
 		PromiseHash.all(
 			jid: customer.jid,
@@ -126,7 +128,8 @@ class AdminInfo
 			info: CustomerInfo.for(customer),
 			api: API.for(customer),
 			call_info: call_info(customer, call_attempt_repo),
-			trust_level: trust_level_repo.find(customer).then(&:to_s)
+			trust_level: trust_level_repo.find(customer).then(&:to_s),
+			backend_jid: backend_repo.get(customer.customer_id).from_jid.to_s
 		).then(&method(:new))
 	end
 
@@ -162,4 +165,8 @@ class AdminInfo
 			info.tel.gsub(/\A\+1/, "")
 		].join("/")
 	end
+
+	def support_link
+		CONFIG[:support_link].call(backend_jid)
+	end
 end

test/test_helper.rb 🔗

@@ -114,7 +114,8 @@ CONFIG = {
 	bandwidth_peer: "test_peer",
 	keepgo: { api_key: "keepgokey", access_token: "keepgotoken" },
 	adr: "A Mailing Address",
-	interac: "interac@example.com"
+	interac: "interac@example.com",
+	support_link: ->(*) { "https://support.com" }
 }.freeze
 
 def panic(e)