Skip to content

Application Integration Example

Konstantin Müller edited this page May 29, 2018 · 1 revision

In the following sections an example of a fictitious Web application called UploadYourHilariousImages.com for uploading and displaying images is given. Whenever an image is uploaded other users can be notified about the upload using another third-party Web application with the name SendMeNotifications.com. Think about a subscribe functionality and integration with a social-media network. This example illustrates how the Action Triggers framework can be integrated into an existing application and helps to understand how the different parts of the framework work together.

First the image upload application defines which Trigger Events are available by creating Trigger Event Definitions, such as the one shown below for uploaded images named ImageUploaded.

---
id: 810041ee-29f5-4c09-a432-11b214e3619a
service: UploadYourHilariousImages.com
name: ImageUploaded
publicPermission: ImageUploadedPublicAccess
roleBasedPermission: ImageUploadedRoleBasedAccess
privatePermission: ImageUploadedPrivateAccess
...

In addition, a Trigger Action Definition is specified which will be used to send notifications to the third-party notification application.

---
id: 2ac264d3-7826-45fa-9db3-d60a8aedca7b
name: WebHookAction
description: Action calling a Web hook
triggerActionClass: no.mnemonic.services.triggers.action.HttpClientAction
requiredPermission: AllowWebHookAction
triggerParameters:
  url:
    description: URL of the Web hook to call
    required: true
  method:
    description: HTTP method to be used when making requests
    required: false
    defaultValue: GET
  body:
    description: Body send in request
    required: false
  contentType:
    description: Media type of body data
    required: false
    defaultValue: text/plain
...

Now consider the following Trigger Event (only using YAML here for easier readability, the actual Trigger Event would not be a YAML document). It contains the service name and the defined ImageUploaded event. The access mode is Public and the organization could be a user group in this case, for example to only make this image available to a group of friends. Additionally, the Trigger Event contains a couple of context parameters, essentially meta data about the uploaded image, such as title, a category and a list of labels.

---
id: 4d16c37d-9afc-47b0-a452-09679b6d4d65
timestamp: 1527574814631
service: UploadYourHilariousImages.com
event: ImageUploaded
organization: 671b9d79-5680-46c0-a417-be6e7b8468ef
accessMode: Public
contextParameters:
  imageId: 0f4a51d9-c979-4024-9b84-7aeb220e4cdf
  imageTitle: Cat on a motorbike
  category: ImageOfTheDay
  labels: [ cats, motorbike, hilarious ]
  uploadedAt: 1527574814631
  uploadedBy:
    userName: biker42
    displayName: Mr. Biker 42
...

In order to be notified about new uploaded images of a specific category the following Trigger Rule can be used. Note that service, events, organizations and accessMode must agree with the generated Trigger Event in order for the rule to match. The expression property specifies that only images in the ImageOfTheDay category having the cats label will match the rule and therefore only notifications for those images will be created.

---
id: 0f1ce9c5-0f58-42be-a563-13192526163b
service: UploadYourHilariousImages.com
events: [ ImageUploaded ]
organizations: [ 671b9d79-5680-46c0-a417-be6e7b8468ef ]
accessMode: Public
expression: category == "ImageOfTheDay" && "cats" =~ labels
triggerAction: WebHookAction
triggerParameters:
  url: http://notify.sendmenotifications.com?recipient=CatEnthusiast
  method: POST
  contentType: text/plain
  body: |
    ${uploadedBy.displayName} has uploaded a new picture called ${imageTitle}!
    Click on the following link to view it: http://view.uploadyourhilariousimages.com?id=${imageId}
...

For every image uploaded which matches this Trigger Rule the predefined WebHookAction will be executed, sending a notification to the user CatEnthusiast registered at SendMeNotifications.com with the following notification text (note how the body template is substituted with the context parameters):

biker42 has uploaded a new picture called Cat on a motorbike!
Click on the following link to view it: http://view.uploadyourhilariousimages.com?id=0f4a51d9-c979-4024-9b84-7aeb220e4cdf
Clone this wiki locally