Support

Home Forums Event Espresso Premium Model System – relate custom Messages and Events

Model System – relate custom Messages and Events

Posted: April 29, 2021 at 10:33 pm

Viewing 6 reply threads


make_webmaster

April 29, 2021 at 10:33 pm

Hi,

We have created multiple ‘Automated Upcoming Event Notification’ messages using custom message templates that are triggered at different points prior to the Event occurring. For example, 20 days out, 2 weeks out, 2 days prior.

I am trying to relate these custom message templates to the event using the model system. I can create a new instance under EE_Event_Message_Template that includes the Event Message Template ID and the Event ID, but when I try to create a relationship to the event I receive the error:
“Uncaught EE_Error: Cannot get Event_Message_Template related to EE_Event. There is no model relation of that type. There is, however, Registration, Datetime, Question_Group, Event_Question_Group, Venue, Term_Relationship, Term_Taxonomy, Message_Template_Group, Attendee, WP_User, Post_Meta, Extra_Meta, Change_Log, Promotion_Object, Person, Person_Post..”

So my question how do I determine the Message_Template_Group for a custm message? Is the Message Template Group the message type of ‘Automated Upcoming Event Notification’? Can I assign multiple custom messages in the same message type to one event?


Tony

  • Support Staff

April 30, 2021 at 6:26 am

Hi there,

Unfortunately, I don’t think is going to work how you are expecting. I’ll answer your questions but EE doesn’t expect multiple of the same message type per event and the AUEN add-on also has checks to prevent it from triggering the message types more than one.

So my question how do I determine the Message_Template_Group for a custm message?

Whilst you can pull in the message groups based specific message types (MTP_message_type) and determine if they are custom or global (MTP_is_global) I’m not sure how you are going to determine the ‘correct’ group on the fly here.

Something like:


$where = array(
    'MTP_message_type' => $message_type,
    'MTP_messenger' => 'email',
);
$message_template_groups = EEM_Message_Template_Group::instance()->get_all(array($where));

Is going to pull the message template groups for the specific message type you set. For the AUEN add-on that’s going to be automate_upcoming_event or automate_upcoming_datetime.

EE displays those in a dropdown for the user to select one, then saves that value. You’re going to need some way to select the specific groups you need here, or hardcode them.

Can I assign multiple custom messages in the same message type to one event?

EE only expects a single record, so technically it’s possible to do so within the database but nowhere within EE expects multiple rows and will use
whichever it finds ‘first’.

The AUEN add-on also sets extra meta values in relation to the event so that the query skips events if it has already trigger notifications for that Event/DateTime so unfortunately I don’t think is going to work how you are expecting it to without further customizations.


make_webmaster

April 30, 2021 at 9:02 am

Thank you for the reply Tony. Do you have any suggestions on how I can get these to work or to bypass the AUEN checks that skip multiple events of the same type?


Tony

  • Support Staff

May 4, 2021 at 5:22 am

It’s not skipping multiple events of the same type, but rather skipping an event/DateTime if that entity has extra_meta data saved to show it’s already been triggered previously.

Even if you managed to save multiple templates to the event you’ll need to remove the extra meta value for this to work with the current add-on. We can’t provide support for this, the system is designed to be cautious over sending emails (we’ve had a lot of feedback over emails from EE3 and EE4) so hacking that up to allow for this is not something we can do.

However, I can point you in the direction I would look into this. So if this were me, I’d look into a way to delete that extra meta value around the days when you want the messages to trigger.

The Extra_Meta key (EXM_key) for the AUEN add-on is ee_auen_processed_ saved with either EXM_type Event or Datetime and then the ID of the entity.

So you could have a single template set at 20 days, that will run and then save the extra_meta values. Have a function that runs on a cron schedule that pulls in all of the events with that extra_meta value set within the highest number of days you use for the message buffer. Use the datetime(s) on those events and compare to today’s date and if it’s around the time you want the ‘next’ email to go out, remove the extra_meta value (you could also set the ‘next’ upcoming event template on those events at that point). Then let the AUEN add-on do its thing the next time it runs its check.

Be careful with this, getting this wrong could cause multiple emails to send and if you have many registrations on the event that could easily means hundreds/thousands of emails triggered (which is also one of the reasons it is not something we can provide support for).


make_webmaster

May 4, 2021 at 9:07 am

Thank you Tony. That is a HUGE help. As always, I appreciate the response.


make_webmaster

May 4, 2021 at 11:55 am

Tony

So back to my first question, I have a custom message template created for the message type of ‘Automated Upcoming Event Notification’. How do I assign that one custom message template to an event.

I can pull the Custom template with
$eMtemplate = EE_Event_Message_Template::new_instance(
array(‘EVT_ID’ => $event_id,
‘EMT_ID’ => 20
));
$eMtemplate->save();

And I can pull the group with
$where = array(
‘MTP_message_type’ => ‘automate_upcoming_event’,
‘MTP_messenger’ => ’email’,
);
$message_template_groups = EEM_Message_Template_Group::instance()->get_all(array($where));

But how do I relate these items to the event?


Tony

  • Support Staff

May 4, 2021 at 5:23 pm

Use _add_relation_to() and add a relation to Message_Template_Group with the GRP_ID. on the EE_Event.

So something like:

$event->_add_relation_to($GRP_ID, 'Message_Template_Group');

Viewing 6 reply threads

The support post ‘Model System – relate custom Messages and Events’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso