Repository navigation
feat: Mautic add-on - #36
Open
eastagiletracker wants to merge 1 commit into
Open
eastagiletracker wants to merge 1 commit into
eastagiletracker wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR proposes a Mautic add-on that turns form submissions into Mautic contacts and adds them to segments (Fixes #20). We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/1151. You can sign in with your GitHub ID to claim ownership of the project.
What changed
Issue #20 asks for a Mautic add-on, and on current
mainthere is none:ls forms-bridge/addons/mauticfails, andAddon::addon( 'mautic' )returns null. This PR addsforms-bridge/addons/mautic/, built the same way as the Listmonk and Zulip add-ons, soAddon::registry()picks it up from the add-ons directory with no other wiring needed.Basiccredential (Mautic user and password). The field description reminds the user to enable the API and HTTP basic auth in Mautic's API settings.Mautic_Form_Bridge: onPOST /api/contacts/newit takes thesegmentsfield off the payload, creates the contact, and then callsPOST /api/segments/{id}/contact/{contactId}/addfor each segment.segmentscan be an array or a comma-separated string, and duplicates are dropped. A failed segment call,success: 0, or anerrorsbody returned with a 2xx status is passed back as aWP_Error. Mautic returns collections as objects keyed by entity ID, so GET responses forcontacts,companies,listsandfieldsare turned into plain lists. Without that, the template'slists[].idfinger cannot read the segments.Mautic_Addon:ping()callsGET /api/contacts?limit=1.get_endpoints()returns the contact, company, segment and field endpoints, filtered by method.get_endpoint_schema()reads/api/fields/contactor/api/fields/company, so the mapper offers the instance's own published custom field aliases with their types and required flags, plustags,segments,owner,ipAddressandoverwriteWithBlank./api/segmentsand an optional tags field. Aforms_bridge_template_datahook expands the selected segments into integersegments[i]custom fields, the same way the Listmonk template handleslists.This is all new code, so no existing add-on or caller is affected.
Verification
tests/addons/test-mautic.phpadds 21 tests that use the samepre_http_requestinterception as the Listmonk tests. They cover the Basic auth header, contact creation with no segments, with array segments and with comma-separated segments, the segments field being left alone on other endpoints, segment and contact error paths (no segment calls after a failed contact create), errors returned with a 2xx status, an unknown backend, the keyed-collection normalization against the realJSON_Finger, ping success and failure, endpoint listing, the schema built from/api/fields/contact(unpublished fields are skipped), the template data hook, template validity, and a bridge running its owncustom_fieldsand integer mutations throughsubmit().Run against current
mainwithout the add-on, every test fails withError: Class "FORMS_BRIDGE\Mautic_Form_Bridge" not found. If only the segment loop and the collection normalization are reverted while the classes stay in place, 5 behaviour tests fail and the rest still pass.I ran the full
vendor/bin/phpunitsuite before and after the change on a local WordPress test install. Before:Tests: 352, Errors: 5, Failures: 3. After:Tests: 373, Errors: 5, Failures: 3. The failures are the same tests both times: the Gravity Forms tests (I stubbed the plugin locally) and three Formidable serialization tests that also fail on a cleanmainre-run.vendor/bin/phpcs forms-bridge/addons/mautic tests/addons/test-mautic.phpis clean.The tests use mocked API responses, not a live Mautic. To check it against a real instance: enable the API and basic auth, use the Contacts template with a segment selected, submit the form, and the contact should show up in Mautic in that segment. The logo is Mautic's own app icon from the mautic/mautic repository. I left
README.mdandreadme.txtunchanged so you can link the add-on from your documentation when you choose.How this was managed
This work was tracked as story https://eastagiletracker.com/projects/1151/stories/1349679 on a board imported from this repo's issues and pull requests (35 stories): https://eastagiletracker.com/projects/1151
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com