Hi everybody!
I’m writing a decision plugin and facing undefined method error for CampaignModel.triggerEvent,
Here is the relevant documentation section:
https://developer.mautic.org/?php#extending-campaigns
The section calling triggerEvent
I have an hello world plugin for ease reproduction of problems and I updated it to reproduce this: GitHub - dhilst/HelloWorldBundle: Mautic plugin hello world with custom action
In the real case I have a chatbot and the lead will trigger decision as he/she talks to the bot, my backend will do a request to a custom API at Mautic to signal that a decision was taken by the lead. At this API I get the campaign.model
and try to call ->triggerEvent(...)
as shown in the documentation. This is where I got an Undefined method error
. I opened the CampaignModel class and there is no such triggerEvent there, so I’m thinking that the documentation is outdated. I willing to update the documentation once I find a way to solve my problem first, so I can use it as example.
I call trigger event here,
Here is the error
{"errors":[{"message":"Attempted to call an undefined method named \u0022triggerEvent\u0022 of class \u0022Mautic\\CampaignBundle\\Model\\EventModel\u0022.","code":500,"type":null}],"
Next I looked for an example of an decision being triggered on Mautic code, I decided to use email open decision because I’m using it daily. From what I could follow from code:
- It has a controller that receives the tracking pixel request
- It dispatches an EMAIL_HIT event
- EMAIL_HIT event is handled by QueueSubscriberEvent, I think this is a good pratice to not handle the event while blocking the request,
-
onEmailHit
callsEmailModel.hitEmail
-
hitEmail
does lots of tracking things but what seems to important to me is this->dispatcher->dispatch(EmailEvents::EMAIL_ON_OPEN, ...)
call -
EMAIL_ON_OPEN
is handled byEmailBundle\...\CampaignSubscriber.onEmailOpen()
and this'email.open'
is the same'email.open'
that was registered withaddDecision
so think this is how the campaign knows that this decision were triggered right?
So in the end I need to call realTimeExecutioner->execute('<my decision string id>, $passthrough, $channel, $channelId)
to tell Mautic that this decision were taken by the lead, right? Here I have some questions:
- Does channel can be anything other than email? In my real world case I have a chatbot and the user will trigger decisions as he/she progress over the chat. I have no chatbot channel in Mautic, and don’t want to add one as it will not be used to send messages etc, I don’t need one right? I mean, it’s safe to pass any string here as long is not ‘email’, or another channel natively used by Mautic, right?
- What is
$passthrough
at all? - And what is the purpose of the
$channelId
? What is a good example for it?