Welcome message for new users

Stephen Paul Weber created

Change summary

lib/registration.rb       | 13 ++++++++++---
lib/welcome_message.rb    | 25 +++++++++++++++++++++++++
test/test_registration.rb | 10 ++++++++++
3 files changed, 45 insertions(+), 3 deletions(-)

Detailed changes

lib/registration.rb 🔗

@@ -13,6 +13,7 @@ require_relative "./invites_repo"
 require_relative "./oob"
 require_relative "./proxied_jid"
 require_relative "./tel_selections"
+require_relative "./welcome_message"
 
 class Registration
 	def self.for(customer, tel_selections)
@@ -488,15 +489,21 @@ class Registration
 			)
 		end
 
+		def put_default_fwd
+			Bwmsgsv2Repo.new.put_fwd(@customer.customer_id, @tel, CustomerFwd.for(
+				uri: "xmpp:#{@customer.jid}",
+				voicemail_enabled: true
+			))
+		end
+
 		def customer_active_tel_purchased
 			@customer.register!(@tel).catch(&method(:raise_setup_error)).then {
 				EMPromise.all([
 					REDIS.del("pending_tel_for-#{@customer.jid}"),
-					Bwmsgsv2Repo.new.put_fwd(@customer.customer_id, @tel, CustomerFwd.for(
-						uri: "xmpp:#{@customer.jid}", voicemail_enabled: true
-					))
+					put_default_fwd
 				])
 			}.then do
+				WelcomeMessage.new(@customer, @tel).welcome
 				Command.finish("Your JMP account has been activated as #{@tel}")
 			end
 		end

lib/welcome_message.rb 🔗

@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class WelcomeMessage
+	def initialize(customer, tel)
+		@customer = customer
+		@tel = tel
+	end
+
+	def welcome
+		@customer.stanza_to(message)
+	end
+
+	def message
+		m = Blather::Stanza::Message.new
+		m.from = CONFIG[:notify_from]
+		m.body =
+			"Welcome to JMP!  Your JMP number is #{@tel}. This is an automated " \
+			"message, but anything you send here will go direct to real humans " \
+			"who will be happy to help you.  Such support requests will get a " \
+			"reply within 8 business hours.\n\n" \
+			"FAQ: https://jmp.chat/faq\n\n" \
+			"Account Settings: xmpp:cheogram.com?command"
+		m
+	end
+end

test/test_registration.rb 🔗

@@ -711,6 +711,7 @@ class RegistrationTest < Minitest::Test
 	end
 
 	class FinishTest < Minitest::Test
+		Customer::BLATHER = Minitest::Mock.new
 		Command::COMMAND_MANAGER = Minitest::Mock.new
 		Registration::Finish::TEL_SELECTIONS = FakeTelSelections.new
 		Registration::Finish::REDIS = Minitest::Mock.new
@@ -772,6 +773,14 @@ class RegistrationTest < Minitest::Test
 				nil,
 				["catapult_fwd_timeout-customer_test@component", 25]
 			)
+			Customer::BLATHER.expect(
+				:<<,
+				nil,
+				[Matching.new do |m|
+					assert_equal :chat, m.type
+					assert m.body =~ /^Welcome to JMP/
+				end]
+			)
 			blather = Minitest::Mock.new
 			blather.expect(
 				:<<,
@@ -802,6 +811,7 @@ class RegistrationTest < Minitest::Test
 			assert_mock @sgx
 			assert_mock Registration::Finish::REDIS
 			assert_mock Bwmsgsv2Repo::REDIS
+			assert_mock Customer::BLATHER
 			assert_mock blather
 		end
 		em :test_write