com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Using the Gmail Connector

In this tutorial, you will use the Gmail connector to send an email containing the response received from SettlePaymentEP in the previous tutorial.

See the following topics for descriptions of the concepts that you need to know when creating ESB artifacts:

Before you begin,

  • Download the product installer from here, and run the installer.
    Let's call the installation location of your product the <EI_HOME> directory. This is located in a place specific to your OS as shown below:
    OSHome directory
    Mac OS/Library/WSO2/EnterpriseIntegrator/6.6.0
    WindowsC:\Program Files\WSO2\EnterpriseIntegrator\6.6.0\
    Ubuntu/usr/lib/wso2/EnterpriseIntegrator/6.6.0
    CentOS/usr/lib64/EnterpriseIntegrator/6.6.0
  • Select the relevant WSO2 Integration Studio based on your operating system and download it from here.
    The path to this folder is referred to as <EI_TOOLING> throughout this tutorial.

    Getting an error message? See the troubleshooting tips given under Installing WSO2 Integration Studio.

  • If you did not try the Storing and Forwarding Messages tutorial yet,
    1. Download the pre-packaged project that contains the configurations of the Storing and Forwarding Messages tutorial.
    2. Open WSO2 Integration Studio, click File, and click Import.
    3. Next, expand the WSO2 category and select Existing WSO2 Projects into workspace, click Next, and upload the project file.

Let's get started!

Setting up the Message Broker profile

Open the <EI_HOME>/conf/jndi.properties file and add the following line after queue.MyQueue = example.MyQueue:

queue.PaymentRequestJMSMessageStore=PaymentRequestJMSMessageStore

Creating the credentials for using the Gmail connector

Creating a Client ID and Client Secret

Follow the steps below if you want to use your own email address for sending emails.

  1. As the email sender, navigate to the https://console.developers.google.com/projectselector/apis/credentials URL and log in to your Google account. 
  2. If you do not already have a project, create a new project.

  3. Click Google APIs -> Credentials -> Create Credential -> OAuth client ID.

    At this point, if the consent screen name is not provided, you will be prompted to do so.

  4. Select Web Application and create a client.

  5. Provide https://developers.google.com/oauthplayground as the redirect URL under Authorized redirect URIs and click Create.
    The client ID and client secret will then be displayed. 

    See Gmail API documentation for details on creating the Client ID and Client Secret.

  6. Click Library on the side menu, and select Gmail API

  7. Click Enable.

Obtaining the Access Token and Refresh Token

Follow these steps to automatically refresh the expired token when connecting to Google API:

  1. Navigate to the https://developers.google.com/oauthplayground URL, click at the top-right corner of the screen, and select Use your own OAuth credentials
  2. Provide the client ID and client secret you previously created and click Close.
  3. Now under Step 1, select Gmail API v1 from the list of APIs, select all the scopes listed under it, and click  Authorize APIs.
  4. You will then be prompted to allow permission, click Allow.
  5. Under Step 2, click Exchange authorization code for tokens to generate and display the access token and refresh token. 

Importing the Gmail connector into WSO2 Integration Studio

  1. Right-click Sample Services in the project explorer and select Add or Remove Connector
  2. Select Add Connector and click Next.
  3. Scroll down and select Gmail from the list of connectors. Then, click the Download icon to download the Gmail connector.

  4. Click Finish.  to close the store view. The connector is now downloaded into your WSO2 Integration Studio and the connector operations will be available in the Gmail Connector palette.

Let's use these connector operations in the configuration.

Creating the Deployable Artifacts

The connector operations are used in the PaymentRequestProcessingSequence. Select this sequence and do the following updates:

  1. Add a Property mediator just before the Call mediator to retrieve and store the patient's email address. 


    With the Property mediator selected, access the Property tab of the mediator and fill in the information in the following table:

    FieldValue
    Property NameSelect New Property
    New Property Nameemail_id
    Property ActionSelect Set
    Value TypeSelect Expression
    Value Expressionjson-eval($.patient.email)
    DescriptionGet Email ID
  2. Add another Property mediator just after the Log mediator to retrieve and store the response sent from SettlePaymentEP. This will be used within the body of the email.

    With the Property mediator selected, access the Property tab and fill in the information in the following table:

    FieldValue
    Property NameSelect New Property
    New Property Namepayment_response
    Property ActionSelect Set
    Value TypeSelect Expression
    Value Expressionjson-eval($.)
    DescriptionGet Payment Response
  3. Drag and drop the init method (from the Gmail Connector palette) next to the Property mediator you added in the previous step.


  4. With the init method selected, access the Property tab. Update the properties as follows:

    • Select inline as the Parameter Editor Type.
    • In the Connector Parameters section, when you click a parameter the Call Template Parameter dialog will open as shown below. Use this dialog to specify the parameter value.

      Specify values for the following parameters:

      userIdThe sender's email address. Use the email address that you used to configure the client ID and secret.
      accessTokenThe access token you obtained.
      apiUrlhttps://www.googleapis.com/gmail
      clientIdThe client ID you created.
      clientSecretThe client secret you created.
      refreshTokenThe refresh token you obtained.
  5. Add the sendMail method from the Gmail Connector palette after the init method. The updated PaymentRequestProcessingSequence should now look like this:

  6. With the sendMail method selected, access the Property tab. Update the properties as follows:

    • Select sendMail as the Parameter Editor Type.
    • In the Connector Parameters section, when you click a parameter the Call Template Parameter dialog will open. Use this dialog to specify the following parameter values:

      FieldValue/ExpressionDescription
      to{$ctx:email_id}Retrieves the patient email address that was stored in the relevant Property mediator.
      subjectPayment StatusThe subject line in the email that is sent out.
      messageBody{$ctx:payment_response}Retrieves the payment response that was stored in the relevant Property mediator.
  7. Save the updated sequence configuration.
  8. Right-click SampleServicesConnectorExporter, navigate to New →  Other → Add/Remove Connectors, select Add connector, and click Next. Select Workspace to list down the connectors that were added.

  9. Select the Gmail connector from the list, click OK, and then Finish.

Packaging the artifacts

Package the artifacts you created above in the SampleServicesCompositeApplication project: 

  1. Open the pom.xml file of the SampleServicesCompositeApplication project, which is already included in the project explorer.
  2. Select the artifact that needs to be included into the CAR file.

Ensure the following artifact check boxes are selected in the Composite Application Project POM Editor.

  • SampleServices
    • HealthcareAPI
    • ClemencyEP
    • GrandOakEP
    • PineValleyEP
    • ChannelingFeeEP
    • SettlePaymentEP
  • SampleServicesRegistry
  • SampleServicesConnectorExporter

Starting the Message Broker profile

Start the Message Broker profile as follows:


The Message Broker profile is now ready to receive messages from the ESB profile.

Starting the ESB profile and deploying the artifacts

If you do not already have an ESB server added to WSO2 Integration Studio, follow the instructions in the previous tutorial.

If you have already added the ESB profile server and deployed SampleServicesCompositeApplication (in a previous tutorial):

  1. Go to the Servers tab and click  to start the server. 
  2. Right-click SampleServicesCompositeApplication and click Redeploy as shown below.

The server Console will indicate that the CApp has been redeployed successfully.

Starting the back-end service

Download and start the back-end service that will process appointment requests:

  1. Download the JAR file of the back-end service.
  2. Open a terminal and navigate to the location where your saved the back-end service.

  3. Execute the following command to start the service:

    java -jar Hospital-Service-JDK11-2.0.0.jar

The Healthcare service is now active and you can start sending requests to the service.

Sending requests to the ESB

  1. Create a JSON file named request.json with the following request payload. Make sure you provide a valid email address so that you can test the email being sent to the patient. 

    {
    "name": "John Doe",
    "dob": "1940-03-19",
    "ssn": "234-23-525",
    "address": "California",
    "phone": "8770586755",
    "email": "johndoe@gmail.com",
    "doctor": "thomas collins",
    "hospital": "grand oak community hospital",
    "cardNo": "7844481124110331",
    "appointment_date": "2025-04-02"
    }
  2. Open a command line terminal and execute the following command from the location where the request.json file you created is saved:

    curl -v -X POST --data @request.json http://localhost:8280/healthcare/categories/surgery/reserve --header "Content-Type:application/json"

    This is derived from the URI-Template defined when creating the API resource.

    http://<host>:<port>/categories/{category}/reserve

    You will see the response as follows:

    {"message":"Payment request successfully submitted. Payment confirmation will be sent via email."}

    An email will be sent to the provided patient email address with the following details:

    Subject: Payment Status
     
    Message:
    {"appointmentNo":2,"doctorName":"thomas collins","patient":"John
    Doe","actualFee":7000.0,"discount":20,"discounted":5600.0,"paymentID":"8458c75a-c8e0-4d49-8da4-5e56043b1a20","status":"Settled"}

You have now explored how to import the Gmail connector to the ESB profile of WSO2 EI and then use the connector operation to send emails.

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.