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		if @trust_level.support_call?(0, 0) && @trust_level.send_message?("+1", 0)
27			return
28		end
29
30		"\n\nYour account is activated for inbound calls and texts, but you " \
31		"won't be able to call out or send a text until you receive at least " \
32		"one text from a person at your new number, or port in a number from " \
33		"outside."
34	end
35
36	def message
37		m = Blather::Stanza::Message.new
38		m.from = CONFIG[:notify_from]
39		m.body =
40			"Welcome to JMP! Your JMP number is #{@tel}.#{warning}\n\nThis is an " \
41			"automated message, but anything you send here will go direct to real " \
42			"humans who will be happy to help you.  Such support requests will " \
43			"get a reply within 8 business hours.\n\n" \
44			"FAQ: https://jmp.chat/faq\n" \
45			"Account Settings: xmpp:cheogram.com?command"
46		m
47	end
48end