From 3c15e92c1776e80ef737aa4c7b8b8f43bb101021 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 21 Mar 2023 14:07:23 -0500 Subject: [PATCH] Welcome message for new users --- lib/registration.rb | 13 ++++++++++--- lib/welcome_message.rb | 25 +++++++++++++++++++++++++ test/test_registration.rb | 10 ++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 lib/welcome_message.rb diff --git a/lib/registration.rb b/lib/registration.rb index a5cc16ce3489f95a698e6256eee7959c2d4c0082..c50b806255d938128849854a76999c237159f156 100644 --- a/lib/registration.rb +++ b/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 diff --git a/lib/welcome_message.rb b/lib/welcome_message.rb new file mode 100644 index 0000000000000000000000000000000000000000..07b71208835ff119c44bc1b25a5aac67045d2353 --- /dev/null +++ b/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 diff --git a/test/test_registration.rb b/test/test_registration.rb index e947478089ba172506ceb0e9c2dd174bc97ed997..e04ce53b6847d8c98cbddfebfa7fdd17e6ad3443 100644 --- a/test/test_registration.rb +++ b/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