Is it possible to get a list of boundary events from a execution listener?

Hi All!
Is it possible to get a list of boundary events from a execution listener javascript?
The scenario is as follows. I want to implement process transitions back and forth using boundary events. For example, a user selected a product in the first step and switched to the second. Then he wants to go back one step and change his choice. In order to realize the weak connectivity of the front and the bpms, I want to use the execution listener on start of the activity and get a list of boundary events type of ‘message’ and write the Message names in the process variable. When the process reaches a certain activity, front will read the variables and form the necessary links for transitions on their basis. As far as I know, getting a list of boundary events through REST API is now impossible.
I tried to do this in various ways, but nothing comes of it. The maximum that I achieved was a message that is configured for activity, but not its boundary events with the following code.

var runtimeService = execution.getProcessEngineServices().getRuntimeService();
var currentActivityId = execution.getCurrentActivityId();
var eventSubscriptionQuery = runtimeService.createEventSubscriptionQuery().activityId(currentActivityId);
var eventsList = eventSubscriptionQuery.list();
execution.setVariable('eventsList', eventsList);

Is it possible to implement this?

diagram.bpmn (3.8 KB)

@voltrun do you want to get boundary events attached to the activity which is in current execution (i.e token currently active in the activity) or boundary events attached in the more than one task types?

aravindhrs I want to get boundary events attached to the activity which is in current execution.

@voltrun you can try like this below:

public class LoggingTaskListener implements TaskListener {
  @Override
  public void notify(DelegateTask delegateTask) {
    UserTask userTask = (UserTask)delegateTask.getBpmnModelInstance();
	Collection<BoundaryEvent> boundaryEvents = userTask.getModelInstance().getModelElementsByType(BoundaryEvent.class);
	if (CollectionUtils.isNotEmpty(boundaryEvents)) {
	  boundaryEvents.forEach(boundaryEvent -> {
		if (boundaryEvent.getAttachedTo().getName().equals(userTask.getName())) {
		  boundaryEvent.getEventDefinitions().forEach(events -> {
			if (events instanceof ConditionalEventDefinition) {
			  //you can add logic
			}
		  });
		}
	  });
	}
  }
}

@aravindhrs Thanks for the reply!
Is it feasible in Java? I don’t see method “userTask.getModelInstance()” in the documentation.
Trying to repeat your code in javascript. “execution” (delegateTask in your code) implements the DelegateExecution interface. I call the getBpmnModelInstance() method and get an object that implements the BpmnModelInstance interface, which does not have the getModelInstance() method, only getModel(). In turn, the BpmnModelInstance interface inherits the getModelElementsByType() method.
I can’t get a list of elements with this method yet. My code:

var bpmnModelInstance = execution.getBpmnModelInstance();
var boundaryEvents = bpmnModelInstance.getModelElementsByType(org.camunda.bpm.model.bpmn.impl.instance.BoundaryEventImpl.class);

@voltrun it’s for Java api. I don’t think it’s supported in JavaScript.