Skip to content
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

CRM: Add Send_Email action + create a typical real automation scenario for a business #33424

Merged
merged 5 commits into from
Oct 5, 2023

Conversation

cleacos
Copy link
Contributor

@cleacos cleacos commented Sep 29, 2023

Proposed changes:

With the goal of having a real example, this PR adds a basic Send_Email functionality. Most of the code was extracted from #33219 and updated/adapted in this one.

This is the automation we want to implement:

  • On new Contact with the status Lead, tag it as Prospect.
  • When the Contact Lead changes to Customer, add the New Client tag and remove the Prospect tag. Finally, send a Customer Welcome email with a special offer.

And these are the two Automation Workflows required:

$workflow_1 = new \Automattic\Jetpack\CRM\Automation\Automation_Workflow(
	[
		'name'         => 'New Contact Lead: Prospect',
		'description'  => 'On a new Contact Lead, apply the tag Prospect',
		'category'     => 'contact',
		'active'       => true,
		'triggers'     => [
			\Automattic\Jetpack\CRM\Automation\Triggers\Contact_Created::get_slug(),
		],
		'initial_step' => 1,
		'steps'        => [
			1 => [
				'slug'       => \Automattic\Jetpack\CRM\Automation\Conditions\Contact_Field_Changed::get_slug(),
				'attributes' => [
					'field'    => 'status',
					'operator' => 'is',
					'value'    => 'Lead'
				],
				'next_step_true'  => 2,
				'next_step_false' => null,
			],
			2 => [
				'slug'       => \Automattic\Jetpack\CRM\Automation\Actions\Add_Remove_Contact_Tag::get_slug(),
				'attributes' => [
					'mode'      => 'append',
					'tag_input' => ['Prospect'],
				],
				'next_step_true'  => null,
			],
		],
	]
);

$workflow_2 = new \Automattic\Jetpack\CRM\Automation\Automation_Workflow(
	[
		'name'         => 'Conversion Contact Lead to Customer',
		'description'  => 'This automation will remove/add tags and send a Welcome Email to the new customer.',
		'category'     => 'contact',
		'active'       => true,
		'triggers'     => [
			\Automattic\Jetpack\CRM\Automation\Triggers\Contact_Status_Updated::get_slug(),
		],
		'initial_step' => 1,
		'steps'        => [
			1 => [
				'slug'       => \Automattic\Jetpack\CRM\Automation\Conditions\Contact_Transitional_Status::get_slug(),
				'attributes' => [
					'operator'            => 'from_to',
					'previous_status_was' => 'Lead',
					'new_status_is'       => 'Customer'
				],
				'next_step_true'  => 2,
				'next_step_false' => null,
			],
			2 => [
				'slug'       => \Automattic\Jetpack\CRM\Automation\Actions\Add_Remove_Contact_Tag::get_slug(),
				'attributes' => [
					'mode'      => 'append',
					'tag_input' => ['New Client'],
				],
				'next_step_true'  => 3,
			],
			3 => [
				'slug'       => \Automattic\Jetpack\CRM\Automation\Actions\Add_Remove_Contact_Tag::get_slug(),
				'attributes' => [
					'mode'      => 'remove',
					'tag_input' => ['Prospect'],
				],
				'next_step_true'  => 4,
			],
			4 => [
				'slug'        => \Automattic\Jetpack\CRM\Automation\Actions\Send_Generic_Email::get_slug(),
				'attributes'  => [
					'subject' => 'Welcome to the store!',
					'body'    => 'Hey ##CONTACT-FNAME##!<br><p>Welcome to the App Services Store. We want to give you a special welcome offer, a 20% discount on your next month\'s renewal.</p><p>Kind Regards,<br>The App Services Store</p>',
				],
				'next_step_true'  => null,
			],
		],
	]
);

$repo = new \Automattic\Jetpack\CRM\Automation\Workflow\Workflow_Repository();
$repo->persist( $workflow_1 );
$repo->persist( $workflow_2 );

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  • Check the code of the action added.
  • Tests should pass.
  • In your JPCRM installation, remove any previous Workflow stored, and add the 2 Workflows defined in the description.
    • Create a Contact with status Lead (With name and email). Check that the Prospect tag was applied.
    • Then update the status of that Contact to Customer. Check that the Prospect tags was removed and the New Client tag was added.
    • Finally, check in your mail trapper app (Mailtrap or MailHog) the Welcome email to the Customer, with the Name placeholder changed by the Contact name.

Signed-off-by: cleacos <javacodia@gmail.com>
@cleacos cleacos self-assigned this Sep 29, 2023
@github-actions github-actions bot added [Plugin] CRM Issues about the Jetpack CRM plugin [Status] In Progress labels Sep 29, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 29, 2023

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Crm plugin:

  • Next scheduled release: November 7, 2023.
  • Scheduled code freeze: October 30, 2023.

Signed-off-by: cleacos <javacodia@gmail.com>
@cleacos cleacos changed the title Add/crm/automation send email action CRM: Add Send_Email action + create a typical real automation scenario for a business Sep 30, 2023
@cleacos cleacos marked this pull request as ready for review September 30, 2023 00:21
@cleacos cleacos requested a review from a team September 30, 2023 00:31
@tbradsha tbradsha self-requested a review October 3, 2023 05:00
@@ -140,6 +140,7 @@ protected function register_triggers(): void {
protected function register_conditions(): void {
$conditions = array(
\Automattic\Jetpack\CRM\Automation\Conditions\Contact_Field_Changed::class,
\Automattic\Jetpack\CRM\Automation\Conditions\Contact_Transitional_Status::class,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a previously-created condition, but perhaps we should rename it to something simple, like Contact_Status_Changed. Or better yet, remove it, since I assume it's covered already in Contact_Field_Changed?

@tbradsha
Copy link
Contributor

tbradsha commented Oct 5, 2023

I fixed a few typos in the workflows above.

Copy link
Contributor

@tbradsha tbradsha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing works as intended, except for triggering a PHP notice on the second workflow (it's a generic message, but it's definitely triggered by us):

Notice: Trying to get property 'ID' of non-object in /wp-includes/link-template.php on line 456

See inline comments as well. I think we should keep the email action generic (as the current class name indicates), but otherwise we need to rename it.

@tbradsha
Copy link
Contributor

tbradsha commented Oct 5, 2023

The PHP notice is pre-existing; see Automattic/zero-bs-crm#3357.

Signed-off-by: cleacos <javacodia@gmail.com>
@cleacos cleacos requested a review from tbradsha October 5, 2023 08:28
Copy link
Contributor

@tbradsha tbradsha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed some minor changes to comments/strings: ae4f83f

Looks good now!

@tbradsha tbradsha merged commit 0e8aa9a into trunk Oct 5, 2023
@tbradsha tbradsha deleted the add/crm/automation-send-email-action branch October 5, 2023 20:30
mikestottuk pushed a commit that referenced this pull request Oct 6, 2023
…o for a business (#33424)

* Add Send_Email action to Automation.

Signed-off-by: cleacos <javacodia@gmail.com>

* changelog

* Register Contact_Transitional_Status condition.

Signed-off-by: cleacos <javacodia@gmail.com>

* Rename Send_Generic_Email to Send_Contact_Email

Signed-off-by: cleacos <javacodia@gmail.com>

* Tweaks to comments/strings

---------

Signed-off-by: cleacos <javacodia@gmail.com>
Co-authored-by: tbradsha <32492176+tbradsha@users.noreply.github.com>
n3f pushed a commit that referenced this pull request Oct 6, 2023
…o for a business (#33424)

* Add Send_Email action to Automation.

Signed-off-by: cleacos <javacodia@gmail.com>

* changelog

* Register Contact_Transitional_Status condition.

Signed-off-by: cleacos <javacodia@gmail.com>

* Rename Send_Generic_Email to Send_Contact_Email

Signed-off-by: cleacos <javacodia@gmail.com>

* Tweaks to comments/strings

---------

Signed-off-by: cleacos <javacodia@gmail.com>
Co-authored-by: tbradsha <32492176+tbradsha@users.noreply.github.com>
@tbradsha tbradsha added this to the crm/6.2.0 milestone Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] CRM Issues about the Jetpack CRM plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants