welcome_message.rb

 1# frozen_string_literal: true
 2
 3require_relative "trust_level_repo"
 4
 5class WelcomeMessage
 6	def self.for(customer, tel, trust_level_repo: TrustLevelRepo.new)
 7		trust_level_repo.find(customer).then do |tl|
 8			new(customer, tel, tl)
 9		end
10	end
11
12	def initialize(customer, tel, trust_level)
13		@customer = customer
14		@tel = tel
15		@trust_level = trust_level
16	end
17
18	def welcome
19		EM.promise_timer(10).then do
20			# Wait for cheogram to get the finish and set up the route
21			@customer.stanza_to(message)
22		end
23	end
24
25	def warning
26		return if @trust_level.support_call?(0, 0) && @trust_level.send_message?(0)
27
28		"\n\nYour account is activated for inbound calls and texts, but you " \
29		"won't be able to call out or send a text until you receive at least " \
30		"one text from a person at your new number, or port in a number from " \
31		"outside."
32	end
33
34	def message
35		m = Blather::Stanza::Message.new
36		m.from = CONFIG[:notify_from]
37		m.body =
38			"Welcome to JMP! Your JMP number is #{@tel}.#{warning}\n\nThis is an " \
39			"automated message, but anything you send here will go direct to real " \
40			"humans who will be happy to help you.  Such support requests will " \
41			"get a reply within 8 business hours.\n\n" \
42			"FAQ: https://jmp.chat/faq\n" \
43			"Account Settings: xmpp:cheogram.com?command"
44		m
45	end
46end