This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

The fourth use case in the Eventbrite business scenario is used for event reminders. This page describes the related tasks and the operations you use in the Eventbrite connector and the other ESB connectors.

Overview

The flow for marketing events is illustrated in the following diagram. The ESB connectors for Nexmo and Gmail will be used to connect to each service. 

  1. Retrieve events due tomorrow from the Eventbrite API using the getUserOwnedEventAttendees operation.
  2. Send reminders for the retrieved events as SMS through the sendMessage operation in the Nexmo API to attendees who have provided the mobile numbers in Eventbrite during event registration in order to be notified about the events (the number should be available in the order form).
  3. Send a notification for the retrieved events through an e-mail using the sendMail operation in the Gmail API to attendees who have provided the e-mail addresses in Eventbrite during event registration in order to be notified about the events  
Eventbrite operations
  • getUserOwnedEventAttendees

Nexmo operations
Gmail operations

Samples

Sample Template for Sending E-mail and SMS Reminders for the Given Details
<?xml version="1.0" encoding="UTF-8"?>
<!-- This template is used to send e-mail and SMS reminders for given details. -->
<template xmlns="http://ws.apache.org/ns/synapse" name="sendReminders">
   <!-- Nexmo Parameters -->
	<parameter name="nexmo.apiUrl" description="The url to access the Nexmo API." />
	<parameter name="nexmo.apiKey" description="The apiKey of a valid Nexmo account." />
	<parameter name="nexmo.apiSecret" description="The apiSecret of a valid Nexmo account." />
	<parameter name="nexmo.from" description="Name of the sender." />
	<parameter name="nexmo.to" description="Mobile number in international format and one recipient per request." />
	<parameter name="nexmo.text" description="Body of the text message." />
	<parameter name="nexmo.responseIds" description="Id as Key value pair(s) for response handler (Ex. id1:value1,id2:value2)." />
   
   <!-- Gmail Parameters -->
	<parameter name="gmail.username" description="Gmail user name to login to the user account." />
	<parameter name="gmail.oAuthAccessToken" description="OAuth access Token to access the Gmail API through the App." />	 
	<parameter name="gmail.subject" description="(Optional) Subject of the e-mail message." />
	<parameter name="gmail.toRecipients" description="A comma seperated list of recipients." />
	<parameter name="gmail.ccRecipients" description="A comma seperated list of cc recipients." />
	<parameter name="gmail.bccRecipients" description="A comma seperated list of bcc recipients." />
	<parameter name="gmail.textContent" description="(Optional) Text content of the mail." />
	<parameter name="gmail.responseIds" description="Id as Key value pair(s) for response handler (Ex. id1:value1,id2:value2)." />
   
   
   <sequence>
      <!-- Gmail Properties -->
		<property name="gmail.username" expression="$func:gmail.username"/>
        <property name="gmail.oAuthAccessToken" expression="$func:gmail.oAuthAccessToken"/>
        <property name="gmail.subject" expression="$func:gmail.subject" />
        <property name="gmail.toRecipients" expression="$func:gmail.toRecipients" />
        <property name="gmail.ccRecipients" expression="$func:gmail.ccRecipients" />
        <property name="gmail.bccRecipients" expression="$func:gmail.bccRecipients" />
        <property name="gmail.textContent" expression="$func:gmail.textContent" />
		<property name="gmail.responseIds" expression="$func:gmail.responseIds" />
        <!-- Nexmo Properties -->
		<property name="nexmo.apiUrl" expression="$func:nexmo.apiUrl" />
        <property name="nexmo.apiKey" expression="$func:nexmo.apiKey" />
        <property name="nexmo.apiSecret" expression="$func:nexmo.apiSecret" />
		<property name="nexmo.from" expression="$func:nexmo.from" />
        <property name="nexmo.to" expression="$func:nexmo.to" />
        <property name="nexmo.text" expression="$func:nexmo.text" />
		<property name="nexmo.responseIds" expression="$func:nexmo.responseIds" />
      
	  <!-- Send an e-mail through Gmail - executed only if both username and oAuthAccessToken of Gmail are given. -->
        <filter xpath="boolean(get-property('gmail.username')) and boolean(get-property('gmail.oAuthAccessToken'))">
            <then>
				<!-- Send e-mail through Gmail. -->
                <gmail.init>
					<username>{$ctx:gmail.username}</username>
					<oauthAccessToken>{$ctx:gmail.oAuthAccessToken}</oauthAccessToken>
				</gmail.init>
				<gmail.sendMail>
					<subject>{$ctx:gmail.subject}</subject>
					<toRecipients>{$ctx:gmail.toRecipients}</toRecipients>
					<ccRecipients>{$ctx:gmail.ccRecipients}</ccRecipients>
					<bccRecipients>{$ctx:gmail.bccRecipients}</bccRecipients>
					<textContent>{$ctx:gmail.textContent}</textContent>
				</gmail.sendMail>
				
				<!-- Remove unused headers by calling a sequence template. -->
				<sequence key="removeResponseHeaders" />
				
                <!-- Extract the recipients. -->
                <property name="gmail.responseRecipients" expression="json-eval($.sendMailResponse.message.recipients)" />
				<property name="gmail.id" expression="get-property('gmail.responseIds')" />
				
                <!-- If e-mails are sent to recipients successfully through Gmail, send a success message to the user. Else, send an error message with the API error response. -->
                <filter source="boolean(get-property('gmail.responseRecipients'))" regex="true">
                    <then>
                        <property name="gmail.status" value="Success" />
                        <property name="gmail.message" expression="fn:concat('A mail has been sent to - [', get-property('gmail.responseRecipients'), '] by Gmail.')" />
                    </then>
                    <else>
                        <property name="gmail.status" value="Error" />
                        <property name="gmail.message" expression="json-eval($)" />
                    </else>
                </filter>
				
                <!-- Call the responseHandler template. -->
                <property name="activity" value="gmail_sendEmailRemainder" />
                <call-template target="responseHandlerTemplate">
                    <with-param name="activity" value="{$ctx:activity}" />
                    <with-param name="id" value="{$ctx:gmail.id}" />
                    <with-param name="status" value="{$ctx:gmail.status}" />
                    <with-param name="message" value="{$ctx:gmail.message}" />
                </call-template>
				
				<property name="gmail.username" expression="$func:gmail.username" action="remove" />
				<property name="gmail.oauthAccessToken" expression="$func:gmail.oAuthAccessToken" action="remove" />
            </then>
        </filter>
	  
      <!-- Send an SMS through Nexmo - executed only if  apiUrl, apiSecret, apiSecret and to are given. -->
        <filter xpath="boolean(get-property('nexmo.apiUrl')) and boolean(get-property('nexmo.apiKey')) and boolean(get-property('nexmo.apiSecret')) and boolean(get-property('nexmo.to'))">
            <then>
			
				<!-- Send an SMS through Nexmo. -->
                <nexmo.init>
					<apiUrl>{$ctx:nexmo.apiUrl}</apiUrl>
					<apiSecret>{$ctx:nexmo.apiSecret}</apiSecret>
					<apiKey>{$ctx:nexmo.apiKey}</apiKey>
					<responseType>json</responseType>
				</nexmo.init>
				<nexmo.sendMessage>
					<to>{$ctx:nexmo.to}</to>
					<text>{$ctx:nexmo.text}</text>
					<from>{$ctx:nexmo.from}</from>
					<type>text</type>
				</nexmo.sendMessage>
				
				<!-- Remove unused headers by calling a sequence template. -->
				<sequence key="removeResponseHeaders" />
				 
                <!-- Extract the status code from the Nexmo response. -->
                <property name="nexmo.statusCode" expression="json-eval($.messages[0].status)" />
                <property name="nexmo.id" expression="get-property('nexmo.responseIds')" />
				
				<!-- Check the status of the send SMS operation - success only if the status code is 0. -->
                <filter source="get-property('nexmo.statusCode')" regex="0" >
                    <then>
                        <property name="nexmo.status" value="Success" />
                        <property name="nexmo.message" expression="fn:concat('A SMS has been sent to the attendee. [Mobile No -  ', get-property('nexmo.to'),']')" />
                    </then>
                    <else>
						<property name="apiErrorResponse" expression="json-eval($.messages[0]['error-text'])" />
                        <property name="nexmo.status" value="Error" />
                        <property name="nexmo.message" expression="fn:concat('Failed to send the message to the attendee: ',get-property('apiErrorResponse'))" />
                    </else>
                </filter>
				
                <!-- Call the Response Handler template -->
                <call-template target="responseHandlerTemplate">
                    <with-param name="activity" value="nexmo_sendSmsRemainder" />
                    <with-param name="id" value="{$ctx:nexmo.id}" />
                    <with-param name="status" value="{$ctx:nexmo.status}" />
                    <with-param name="message" value="{$ctx:nexmo.message}" />
                </call-template>
				
				<!-- Remove parameter values at the end of each iteration. -->
				<property name="nexmo.apiUrl" expression="$func:nexmo.apiUrl" action="remove" />
				<property name="nexmo.apiKey" expression="$func:nexmo.apiKey" action="remove" />
				<property name="nexmo.apiSecret" expression="$func:nexmo.apiSecret" action="remove" />
				<property name="nexmo.to" expression="$func:nexmo.to" action="remove" />
				
            </then>
        </filter>
   </sequence>
</template>                                                                               
Sample Proxy for Fetching Events which are due Tomorrow from Eventbrite and Sending Reminders to the Event Attendees via Nexmo and Gmail
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="eventbrite_sendEventReminders" transports="https,http" startOnLoad="true" trace="disable">
   <target>
      <inSequence onError="faultHandlerSeq"> 
        <!-- Eventbrite Properties -->
        <property name="eventBrite.apiUrl" expression="json-eval($.eventBriteApiUrl)" />
        <property name="eventBrite.accessToken" expression="json-eval($.eventBriteAccessToken)" />
        <property name="eventBrite.organizerId" expression="json-eval($.eventBriteOrganizerId)" />
		<property name="eventBrite.changedSince" expression="json-eval($.eventBriteChangedSince)" />
		 
		 
        <!-- Nexmo Properties -->
        <property name="nexmo.apiUrl" expression="json-eval($.nexmoApiUrl)" />
        <property name="nexmo.apiSecret" expression="json-eval($.nexmoApiSecret)" />
        <property name="nexmo.apiKey" expression="json-eval($.nexmoApiKey)" />
		 
        <!-- Gmail Properties -->
        <property name="gmail.username" expression="json-eval($.gmailUsername)" />
        <property name="gmail.oAuthAccessToken" expression="json-eval($.gmailOAuthAccessToken)" />
		 
		<!-- Operation Properties -->
        <property name="eventbrite.attendeesIndex" value="0"  scope="operation" />
		<property name="eventbrite.attendeesCount" value="0"  scope="operation" />
		<property name="eventbrite.isAnyReminder" value="false" scope="operation"/>
		<property name="attendee.idObject" value="{}" />
        
		<header name="Content-Type" scope="transport" action="remove"/>
		
		<!-- List all event attendees for the given organizer. -->
		<eventbrite.init>
            <apiUrl>{$ctx:eventBrite.apiUrl}</apiUrl>
            <accessToken>{$ctx:eventBrite.accessToken}</accessToken>
         </eventbrite.init>
        <eventbrite.getUserOwnedEventAttendees>
			<userId>{$ctx:eventBrite.organizerId}</userId>
			<changedSince>{$ctx:eventBrite.changedSince}</changedSince>
			<status>attending</status>
		</eventbrite.getUserOwnedEventAttendees>
		
		<property name="eventbrite.noOfAttendees" expression="json-eval($.pagination.object_count)"/>
		
		<!-- Remove unused headers by calling a sequence template. -->
		<sequence key="removeResponseHeaders" />
				
		<filter xpath="get-property('eventbrite.noOfAttendees') = 0">
			<then>
				<property name="status" value="Skipped"/>
				<property name="message" value="No attendees for the organizer."/>
				<call-template target="responseHandlerTemplate">
					<with-param name="id" value="{$ctx:attendee.idObject}"/>
					<with-param name="status" value="{$ctx:status}"/>
					<with-param name="message" value="{$ctx:message}"/>
				</call-template>
				<loopback />
			</then>
			<else>
				<property name="eventbrite.attendeesCount" expression="count(//attendees)" scope="operation"/>
				<!-- FOR EACH Attendee: BEGIN -->
				<iterate continueParent="true" id="attendees" expression="//attendees" sequential="true">
					<target>
						<sequence>
							<property name="eventbrite.attendeeId" expression="json-eval($.attendees.id)"/>
							<property name="eventbrite.isDuplicate" expression="(fn:contains(get-property('eventbrite.attendeeId'),'-'))"/>
							<!-- If a duplicate attendee is in Eventbrite, the duplicate will be ignored. -->
							<filter source="get-property('eventbrite.isDuplicate')" regex="false">
								<then>
									
									<property name="eventbrite.startDate" expression="json-eval($.attendees.event.start.local)" />
									<property name="eventbrite.eventStatus" expression="json-eval($.attendees.event.status)" />
									<property name="eventbrite.isTommorrowEvent" value="false" />
									<script language="js">
									<![CDATA[
										var eventStartDate = mc.getProperty('eventbrite.startDate');
										var tommorrow=new Date();
										tommorrow.setDate(tommorrow.getDate() + 1);
										var eventDateString ="";
										var tommorrowDay=""+tommorrow.getDate();
				
										if(tommorrowDay.length==1){
											tommorrowDay="0"+tommorrowDay;
										}
										var tommorrowString=tommorrow.getFullYear() + "-" + Number(tommorrow.getMonth()+1)+ "-" + tommorrowDay ;
										
										if (eventStartDate != null && eventStartDate != "") {
											eventDateString = eventStartDate.split('T')[0];
										}
										
										if(tommorrowString == eventDateString) {
											mc.setProperty("eventbrite.isTommorrowEvent", "true");
											mc.setProperty("eventbrite.isAnyReminder", "true");
										}
									]]></script>
									<!--<filter source="get-property('eventbrite.isTommorrowEvent')" regex="true">-->
									<filter xpath="get-property('eventbrite.isTommorrowEvent')='true' and get-property('eventbrite.eventStatus')='live'">
										<then>
											<property name="attendee.email" expression="json-eval($.attendees.profile.email)"/>
											<property name="attendee.firstName" expression="json-eval($.attendees.profile.first_name)"/>
											<property name="attendee.lastName" expression="json-eval($.attendees.profile.last_name)"/>
											<property name="attendee.cellPhone" expression="json-eval($.attendees.profile.cell_phone)"/>
											<property name="attendee.eventName" expression="json-eval($.attendees.event.name.text)"/>
											
											<property name="attendee.eventId" expression="json-eval($.attendees.event.id)"/>
											<property name="attendee.attendeeId" expression="json-eval($.attendees.id)"/>
											
											<property name="attendee.reminderSubject" expression="fn:concat(get-property('attendee.eventName'),' - Reminder')" />
											<property name="attendee.reminderText" expression="fn:concat('Reminder : ',get-property('attendee.eventName'),' will be held on ; ',get-property('eventbrite.startDate'))" />
											<property name="attendee.idObject" expression="fn:concat('event_id:',get-property('attendee.eventId'),',attendee_id:',get-property('attendee.attendeeId'))" />
											
											
											<call-template target="sendReminders">
                                                    <!-- Parameter values will be passed on to a sequence template. -->
                                                    (
                                                    <with-param name="nexmo.apiUrl" value="{$ctx:nexmo.apiUrl}" />
                                                    |
                                                    <with-param name="nexmo.apiSecret" value="{$ctx:nexmo.apiSecret}" />
                                                    |
                                                    <with-param name="nexmo.apiKey" value="{$ctx:nexmo.apiKey}" />
                                                    |
                                                    <with-param name="nexmo.to" value="{$ctx:attendee.cellPhone}" />
                                                    |
                                                    <with-param name="nexmo.from" value="{$ctx:attendee.eventName}" />
                                                    |
                                                    <with-param name="nexmo.text" value="{$ctx:attendee.reminderText}" />
													|
													<with-param name="nexmo.responseIds" value="{$ctx:attendee.idObject}" />
                                                    |
                                                    <with-param name="gmail.username" value="{$ctx:gmail.username}" />
                                                    |
                                                    <with-param name="gmail.oAuthAccessToken" value="{$ctx:gmail.oAuthAccessToken}" />
                                                    |
                                                    <with-param name="gmail.toRecipients" value="{$ctx:attendee.email}" />
                                                    |
                                                    <with-param name="gmail.subject" value="{$ctx:attendee.reminderSubject}" />
                                                    |
                                                    <with-param name="gmail.textContent" value="{$ctx:attendee.reminderText}" />
                                                    |
                                                    <with-param name="gmail.responseIds" value="{$ctx:attendee.idObject}" />
                                                    |
													) *
                                            </call-template>
										</then>
									</filter>	
								</then>
							</filter>	
							<property name="eventbrite.attendeesIndex" expression="get-property('operation','eventbrite.attendeesIndex') + 1" scope="operation"/>
							
						</sequence>
					</target>
				</iterate>
				<!-- FOR EACH Attendee: END -->
				<filter xpath="get-property('operation','eventbrite.attendeesCount') = get-property('operation','eventbrite.attendeesIndex')">
				<then>
					<loopback />
					
				</then>
			</filter>
			</else>
		</filter>
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2" />
		 
         <filter source="boolean(get-property('operation','responseString'))" regex="true">
            <then>
               <payloadFactory media-type="json">
                  <format>{
					"Response":{
						"process":"Eventbrite-sendEventReminders",
						"activityResponse":[$1]
					}
					}</format>
                  <args>
                     <arg evaluator="xml" expression="get-property('operation','responseString')"/>
                  </args>
               </payloadFactory>
            </then>
            <else>
               <payloadFactory media-type="json">
                  <format>{
					"Response":{
						"process":"Eventbrite-sendEventRemainders",
						"activityResponse":"There are no reminders to be sent."
					}
					}</format>
                  <args/>
               </payloadFactory>
            </else>
         </filter>
         <send />
      </outSequence>
   </target>
   <description />
</proxy>                                                                               
Sample Request for Fetching Events which are due Tomorrow from Eventbrite and Sending Reminders to the Event Attendees via Nexmo and Gmail
{
"eventBriteApiUrl":"https://www.eventbriteapi.com",
"eventBriteAccessToken":"4SMVCVGYVT2K3FYPMMLP",
"eventBriteOrganizerId":"129926182147",
"eventBriteChangedSince":"2014-12-10T13:18:40Z",
"gmailUsername" : "test@gmail.com",
"gmailOAuthAccessToken" : "ya29.3QCKj0LyISF9aBbuVHBS99O1V1r6iz_tx_FrPIIZyvNIPbm5RdqUc-FfkTj88iIQY-o--pmkodbStg",
"nexmoApiUrl":"https://rest.nexmo.com",
"nexmoApiSecret":"57c0d061",
"nexmoApiKey":"15e053e1"
}
  • No labels