Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mautic Plugin Development using Integration Framework

Mohit Aghera
November 17, 2020

Mautic Plugin Development using Integration Framework

Mautic Plugin Development using Integration Framework - MautiCon 2020

Mohit Aghera

November 17, 2020
Tweet

More Decks by Mohit Aghera

Other Decks in Technology

Transcript

  1. 2 axelerant.com Prateek Jain Director, Consulting & Acquia Services mr_prateekjain

    prateekjain prateekjain87 Mohit Aghera Technical Architect mohit_rocks mohit-rocks mohitaghera About Us
  2. 4 axelerant.com Integration Framework • Why do we need Integration

    Framework? • Can’t Zapier Zap does all the things?
  3. 5 axelerant.com Integration Framework • Definition, Configuration and features •

    Webhooks • Event Listeners • Filters • Data Sync • Authentication
  4. 6 axelerant.com Bundle Definition & Configuration • Overview of what

    we are building - Simple plugin for “Demio Webinar” • Setup bundle class • Setup Integration class ◦ Define additional attributes like name, icon, display name etc. • Setup config file
  5. 7 axelerant.com Key Points for Basic Configuration • Have a

    service with proper tags in “Config.php”. ◦ mautic.integration ◦ mautic.basic_integration • Other necessary class files for Integrations like ◦ DemioIntegration.php ◦ DemioBundle.php
  6. 8 axelerant.com Bundle Definition & Configuration DemioBundle ┣ Assets ┃

    ┗ img ┃ ┗ demio.png ┃ ┣ Config ┃ ┗ config.php ┃ ┣ Integration ┃ ┣ Config.php ┃ ┗ DemioIntegration.php ┃ ┗ DemioBundle.php
  7. 9 axelerant.com Features and Sync Configuration • Provides information about

    features of the bundle • Configuration support. • Configuration for the object integration
  8. 10 axelerant.com Bundle Definition & Configuration DemioBundle ┣ Assets ┃

    ┗ img ┃ ┗ demio.png ┃ ┣ Config ┃ ┗ config.php ┃ ┣ Integration ┃ ┣ Support ┃ ┃ ┣ ConfigSupport.php ┃ ┃ ┗ SyncSupport.php ┃ ┃ ┃ ┣ Config.php ┃ ┗ DemioIntegration.php ┃ ┗ DemioBundle.php
  9. 11 axelerant.com Scaffolding for Features and Field Mapping • Provide

    form for storing keys and secret key • Store other configurations depending on requirements • Provide field mapping for source and destination
  10. 12 axelerant.com Bundle Definition & Configuration DemioBundle ┣ Assets ┃

    ┗ img ┃ ┗ demio.png ┃ ┣ Config ┃ ┗ config.php ┃ ┣ Form ┃ ┗ Type ┃ ┣ ConfigAuthType.php ┃ ┣ ConfigFeaturesType.php ┃ ┣ Integration ┃ ┣ Support ┃ ┃ ┣ ConfigSupport.php ┃ ┃ ┗ SyncSupport.php ┃ ┃ ┃ ┣ Config.php ┃ ┗ DemioIntegration.php ┃ ┗ DemioBundle.php
  11. 15 axelerant.com Parameter Based API Keys Authentication • Parameter based

    API Authentication • Use mautic.integrations.auth_provider. api_key service. • Implements ParameterCredentialsInterface class.
  12. 16 axelerant.com Header Based API Key Authentication • Header based

    API Authentication uses header keys for API • Use mautic.integrations.auth_provider.api _key service. • Implements HeaderCredentialsInterface
  13. 17 axelerant.com Basic Authentication • Basic Auth uses combination of

    username and password for authentication • Use mautic.integrations.auth_provid er.basic_auth service. • Implements CredentialsInterface
  14. 18 axelerant.com OAuth Authentication • OAuth 1 ◦ OAuth 1a

    Two Legged • OAuth 2 ◦ OAuth 2 Two Legged ◦ OAuth 2 Three Legged
  15. 19 axelerant.com OAuth2 Two Legged Authentication • Also known as

    “Application-Only Authentication” • Two step process: ◦ Request the access token ◦ Use token in next requests
  16. 20 axelerant.com Authentication DemioBundle ┃ ┣ Config ┃ ┗ config.php

    ┃ ┣ Connection ┃ ┣ ApiConsumer.php ┃ ┣ Client.php ┃ ┗ Credentials.php ┃ ┣ Form ┃ ┗ Type ┃ ┣ ConfigAuthType.php ┃ ┣ ConfigFeaturesType.php ┃ ┗ DemioEventActivities.php ┃ ┣ Integration ┃ ┣ Support ┃ ┃ ┣ ConfigSupport.php ┃ ┃ ┗ SyncSupport.php ┃ ┃ ┃ ┣ Config.php ┃ ┗ DemioIntegration.php ┃ ┗ DemioBundle.php
  17. 22 axelerant.com Field Mapping • Ensure that fields are specified

    in the configuration • Map Mautic lead fields with API response fields • Define sync direction
  18. 23 axelerant.com Sync Field Mapping • Field Repository • Fields

    Sync Direction • Field Mapping Factory DemioBundle ┣ Assets ┃ ┗ img ┃ ┗ demio.png ┃ ┣ ….Other Files….. ┃ ┣ Sync ┃ ┗ Mapping ┃ ┣ Field ┃ ┃ ┣ Field.php ┃ ┃ ┣ FieldRepository.php ┃ ┃ ┗ MappedFieldInfo.php ┃ ┣ Manual ┃ ┃ ┗ MappingManualFactory.php ┃ ┗ FieldMapping.json ┃ ┣ Integration ┃ ┣ Support ┃ ┃ ┣ ConfigSupport.php ┃ ┃ ┗ SyncSupport.php ┃ ┃ ┃ ┣ Config.php ┃ ┗ DemioIntegration.php ┃ ┗ DemioBundle.php
  19. 24 axelerant.com Building Sync Report and Running Sync • Define

    and implement report builder class • Identifies objects created and updated between two sync • Typically we use API to fetch data between two duration • To Run: php bin/console mautic:integrations:sync demio
  20. 25 axelerant.com Sync Field and Data Exchange DemioBundle ┣ Assets

    ┃ ┗ img ┃ ┗ demio.png ┣ ….Other Files….. ┃ ┣ Sync ┃ ┣ DataExchange ┃ ┃ ┣ ReportBuilder.php ┃ ┃ ┣ SyncDataExchange.php ┃ ┃ ┗ ValueNormalizer.php ┃ ┃ ┃ ┗ Mapping ┃ ┃ ┣ Field ┃ ┃ ┃ ┣ Field.php ┃ ┃ ┃ ┣ FieldRepository.php ┃ ┃ ┃ ┗ MappedFieldInfo.php ┃ ┃ ┃ ┃ ┃ ┣ Manual ┃ ┃ ┃ ┗ MappingManualFactory.php ┃ ┃ ┗ FieldMapping.json ┃ ┣ Integration ┃ ┣ Support ┃ ┃ ┣ ….Other Files…. ┃ ┃ ┃ ┣ ….Other Files... ┃ ┗ DemioBundle.php • ReportBuilder service • SyncDataExchange services
  21. 26 axelerant.com Creating and Using Filters for Segments • We

    need to segment the users based on various criteria • Add new filters while creating the segments
  22. 27 axelerant.com Creating Filters • Create EventListeners that listens LIST_FILTERS_CHOICES_ON_GE

    NERATE event. • Create another service to map filter and related query builder. It listens SEGMENT_DICTIONARY_ON_GE NERATE event. • Create Query Builder to build and run query. DemioBundle ┣ EventListener ┃ ┣ DemioSegmentFiltersDictionarySubscriber.php ┃ ┗ SegmentFiltersChoiceSubscriber.php ┃ ┣ Form ┃ ┗ Type ┃ ┃ ┣ ….Other Files….. ┣ Integration ┃ ┣ Support ┃ ┃ ┣ ….Other Files…. ┃ ┣ Config.php ┃ ┗ DemioIntegration.php ┃ ┣ Segment ┃ ┗ Query ┃ ┃ ┗ Filter ┃ ┃ ┃ ┗ DemioContactFilterQueryBuilder.php ┃ ┣ Services ┃ ┣ ….Other Files….. ┣ Sync ┃ ┣ ….Other Directories Files….. ┗ DemioBundle.php 3 2 1
  23. 28 axelerant.com Point Actions • Use case: Once user attends

    certain events assign points. • We can implement this behaviour using event listeners.
  24. 29 axelerant.com Create Point Actions • Subscribe PointEvents::POINT_ON_BUILD • Provide

    form type class to generate options • Trigger event from relevant methods DemioBundle ┣ EventListener ┃ ┣ DemioObjectCreator.php ┃ ┣ DemioSegmentFiltersDictionarySubscriber.php ┃ ┣ EventPointsSubscriber.php ┃ ┗ SegmentFiltersChoiceSubscriber.php ┃ ┣ Form ┃ ┗ Type ┃ ┃ ┣ ConfigAuthType.php ┃ ┃ ┣ ConfigFeaturesType.php ┃ ┃ ┗ DemioEventActivities.php ┃ ┣ Segment ┃ ┗ Query ┃ ┃ ┗ Filter ┃ ┃ ┃ ┗ DemioContactFilterQueryBuilder.php ┃ ┣ Services ┃ ┣ DemioContactStore.php ┃ ┣ SyncObjectMapping.php ┃ ┗ SyncObjectProcessor.php ┃ ┗ DemioBundle.php 1 2 3
  25. 30 axelerant.com Code Repositories and Further Reading Code Repositories: •

    Authorization Code Grant Example: https://github.com/mautic/plugin-helloworld /tree/mautic-3-authorization-code-grant-exa mple • Hello World Plugin: https://github.com/mautic/plugin-helloworld /tree/mautic-3 • Demio Plugin Discussed in Session: https://github.com/mohit-rocks/DemioBund le Further Reading: • https://github.com/mautic-inc/plugin-integr ations/wiki/
  26. 32 axelerant.com Prateek Jain Director, Consulting & Acquia Services mr_prateekjain

    prateekjain prateekjain87 Mohit Aghera Technical Architect mohit_rocks mohit-rocks mohitaghera About Us