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