|
| 1 | +require 'postmark/api' |
| 2 | +require 'ap' |
| 3 | + |
1 | 4 | # == Schema Information
|
2 | 5 | #
|
3 | 6 | # Table name: event_attendees
|
|
17 | 20 | class EventAttendee < ApplicationRecord
|
18 | 21 | belongs_to :event
|
19 | 22 | belongs_to :person, optional: true
|
| 23 | + |
| 24 | + after_save :send_confirmation_emails |
| 25 | + |
| 26 | + private |
| 27 | + |
| 28 | + def send_confirmation_emails |
| 29 | + log.info "✅ EventAttendee #{id} saved" |
| 30 | + |
| 31 | + return if email.nil? |
| 32 | + |
| 33 | + # TODO: Prevent this email from being sent upon every save... |
| 34 | + |
| 35 | + template_locale = locale == 'fr' ? 'fr' : 'en' |
| 36 | + |
| 37 | + log.info '✅ creating confirmation email' |
| 38 | + |
| 39 | + EmailAttempt.create!( |
| 40 | + to: email, |
| 41 | + from: 'Interflux Electronics <robot@interflux.com>', |
| 42 | + reply_to: 'Interflux Electronics <ask@interflux.com>', |
| 43 | + # provider: :postmark, |
| 44 | + postmark_stream: 'outbound', |
| 45 | + postmark_template_alias: "interflux-event-registration-1-#{template_locale}", |
| 46 | + postmark_template_model: { |
| 47 | + first_name: first_name, |
| 48 | + last_name: last_name, |
| 49 | + event_name: event.name, |
| 50 | + event_dates: event.start_to_end_date, |
| 51 | + event_location: event.location |
| 52 | + }, |
| 53 | + created_by: self |
| 54 | + ) |
| 55 | + |
| 56 | + log.info '✅ creating internal email' |
| 57 | + |
| 58 | + EmailAttempt.create!( |
| 59 | + to: 'Steven Teliszewski <s.teliszewski@interflux.com>', |
| 60 | + cc: 'Jan Werkhoven <jw@interflux.au>', |
| 61 | + from: 'Interflux Electronics <robot@interflux.com>', |
| 62 | + reply_to: 'Interflux Electronics <ask@interflux.com>', |
| 63 | + # provider: :postmark, |
| 64 | + postmark_stream: 'outbound', |
| 65 | + postmark_template_alias: 'interflux-event-registration-2-en', |
| 66 | + postmark_template_model: { |
| 67 | + receiver: { |
| 68 | + first_name: 'Steven' |
| 69 | + }, |
| 70 | + attendee: { |
| 71 | + first_name: first_name, |
| 72 | + last_name: last_name, |
| 73 | + role: role, |
| 74 | + company: company, |
| 75 | + email: email, |
| 76 | + locale: locale |
| 77 | + }, |
| 78 | + event: { |
| 79 | + name: event.name, |
| 80 | + dates: event.start_to_end_date, |
| 81 | + location: event.location |
| 82 | + } |
| 83 | + }, |
| 84 | + created_by: self |
| 85 | + ) |
| 86 | + end |
20 | 87 | end
|
0 commit comments