-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delay trigger of salesforce integration until after user has activated their account #1555
Comments
That’s an interesting one. Provided there’s a webhook from Salesforce when an account is activated, it should be possible with some effort. The tricky part will be delaying the queue job until this webhook is received. you could use a module and the payload events to firstly return |
@engram-design Yep this makes sense. Point of clarification, we are waiting for the user to verify their email through Craft, so we don't need to listen to a Salesforce webhook, we simply need to listen to Craft's Anyway, knowing that I can call When it comes time to running the integration once the user has activated their account, we have the How do we go about getting the correct integration for the submission in question, to call |
@engram-design I think I figured it out, pretty straightforward in the end:
But LMK if there's a better way, but that seems right?! |
Oh, my mistake! There's a slightly similar option with how element integrations need to be handled when we're talking about users. I think I'll bundle this with that issue. But that's exactly the way to go about it for the moment! |
@engram-design So I've been able to test this further, and while the result of Let me know if you want me to raise a separate ticket, but here's what's happening, from the top: To recap, we have a configured a "Register" form that asks for the users email & password, and then have configured 2 integrations: 1 to create a Craft user, and 1 to send the submission to Salesforce as a Lead. Without any custom module code, both integrations run fine. However, we don't want the Salesforce integration to be run until the user has activated their Craft account, by following the verification link that is sent to their inbox. To accomplish this, in our module we first hook into the /**
* Do not send Salesforce Lead if user is not yet verified
*/
\yii\base\Event::on(
\verbb\formie\services\Submissions::class,
\verbb\formie\services\Submissions::EVENT_BEFORE_TRIGGER_INTEGRATION,
static function(\verbb\formie\events\TriggerIntegrationEvent $event) {
$submission = $event->submission;
$type = $event->type;
$form = $submission->getForm();
if($type != 'verbb\formie\integrations\crm\Salesforce' || $form->handle != 'register') {
return;
}
$user = \craft\elements\User::find()
->email($submission->email)
->status(null)
->one();
if(!$user || $user->status != \craft\elements\User::STATUS_ACTIVE) {
$event->isValid = false;
}
}
); Then, we listen to /**
* When a user is activated (e.g. they have verified email), trigger Salesforce integration
*/
Event::on(
Users::class,
Users::EVENT_AFTER_ACTIVATE_USER,
static function(UserEvent $event) {
$user = $event->user;
$submissionId = $user->submissionId;
if(!$submissionId) {
return;
}
$submission = Formie::getInstance()->getSubmissions()->getSubmissionById($submissionId);
if(!$submission) {
return;
}
$integration = Formie::$plugin->getIntegrations()->getIntegrationByHandle('salesforce');
if(!$integration) {
return;
}
$result = $integration->sendPayload($submission);
}
); Using xdebug, I've set a breakpoint inside $leadValues = $this->getFieldMappingValues($submission, $this->leadFieldMapping, 'lead'); And found that the content of But in a normal run of the Salesforce integration, So the question becomes, how does Is there something else I need to call after |
Ah, yes this is actually a slight limitation of things at the moment that I forgot to mention. You'll need to populate an integration with settings from the form, which is usually done automatically when you trigger running all integrations when a submission is placed. Specifically the But if you want to pick one integration to run specifically, you'll need to prep the integration. For the moment, you can do the following before Formie::$plugin->getIntegrations()->getAllEnabledIntegrationsForForm($submission->form); I'll look at improving this. |
@engram-design That did it! Thanks as always for all of your help. |
Question
We are using Formie for our front-end user registration forms, and we need this registration information sent to Salesforce. However, user accounts are not activated immediately; rather we send an activation email for them to verify their account.
So it would be ideal if we could delay sending the registration info to Salesforce until after the activation has occurred.
Is that possible?
Could we write custom module code that waits for a user to be activated, and then triggers the Salesforce integration on the related submission?
Additional context
No response
The text was updated successfully, but these errors were encountered: