• Medium One

Create a Workflow to Send Email Triggered by the Mobile App


Let’s get you started creating your own workflow:

In this short tutorial you will build your own workflow which sends an email report.  You will also utilize the mobile app and dashboard to send JSON events to trigger the workflow.

Prerequisite:

Getting Started Guide

Mobile App Quick Starting Guide

STEP 1: CREATING THE TAG

We’ll be using a tag that doesn’t exist in the account.  To create a tag, you first need to send an event with the JSON key representing that tag.  The key and tag will automatically be detected and created.

Let’s use the mobile app to send an event to create the tag.

Please refer to the Mobile App Quick Starting Guide to learn the basics of the Mobile App.

Login with the mobile API credentials for your account.

Using the mobile app, select a JSON input widget to send an event with the following:

stream = raw

tag = send_email

value = <your name>

Send this event once using the mobile app by clicking on “Send”

STEP 2: ACTIVATING THE TAG

Next, will need to activate the tag.  From your Medium One web account, click Config ->DataStream and click the raw stream.  Look for the send_email tag you just created, check it to activate it, then Save at the bottom.

STEP 3: CREATE A NEW WORKFLOW

Now we’re going to create a workflow.

  1. Go to Workflow Studio, and click Create.

  1. To specify the name for this workflow, enter “Send Email” in the top input box.

Note: Workflows save automatically.

STEP 4: ADDING A TAG AS TRIGGER

Select the Tag & Triggers option on the Right menu, expand the raw stream input and drag thesend_email tag onto the canvas.  Note: If you do not see send_email, that tag may not have been activated in Step 2 or you may need to refresh your browser to reload all available tags.

STEP 5: ADD A WORKFLOW MODULE

On the right panel, click the Modules menu, open Foundation and drag the Base Python module onto the canvas

STEP 6: CONNECT THE TAG TO THE BASE PYTHON MODULE

Click the tag node output anchor and drag a connection to the input node anchor on the Base Python module.

STEP 7: EDIT THE PYTHON CODE

Double click on the Base Python module to open the code editor.

Paste the following code into the code editor, making sure the indentation is preserved.  Note: Python is sensitive to indentation and Copy/Paste may modify the alignment.

—— copy below this line —–

# import Email library

import Email

# Get input data from input named 'in1'

name = IONode.get_input('in1')['event_data']['value']

# build a basic html message

html = "<html><body>Hello, my name is {}</body></html>".format(name)

try:

    email = Email.Email("support@medium.one", 'My workflow', '<your-email-here>', "You've got mail!")

    email.html_message(html)

    email.send()

except Exception:

      log("Unable to send Email")

—— copy above this line —– Enter your own email in place of ‘<your-email-here>‘ inside the ‘quotes’.  Example: ‘me@medium.one’.

The code above simply gets the data from the input, which will contain the data in the keysend_email.  It then uses it to build a simple html message, and send an email.

See the Email Library reference http://docs.mediumone.com/ for more details on how this library works.

Click Check Syntax and make sure it passes.  If the syntax fails, you may have an indentation issue or no ‘quotes’ around your email.  If the syntax check passes, click Save and Activate.   This will save your workflow and activate it so it’s ‘live’ on your project.

You can check that the workflow was activated by looking into the Revision menu.  Note the green box is “activated”. Previous revisions of your workflow are stored here as well.

STEP 8: TEST YOUR WORKFLOW

Now we are going to test our workflow by sending a debug event.  To test your workflow, let’s activate debug mode: go to the debug menu and click the Debug Logging Enabled toggle.  This will allow logs to be captured while Workflows are run.  Important Note: workflows in debug mode will consume 1 extra Workflow credit and may impact performance while running, be sure to disable debug mode when it’s no longer required.

In the debugger, you can send a test event. Those events do not get propagated through or show in the data; they are just for testing.

Under ‘Stream’ select raw and under user select any API user.  Note: workflows are run in context to a specific user.  The commands in the Python code are executed with respect to that user, for example, analytics.  Reference http://docs.mediumone.com/ to learn more about how Workflows work.

Specify the test JSON event to send with your name in place of your name

{"send_email": "your name"}

Click Send to send the test event.

Since the raw stream was selected, sending an event that includes the send_email key will trigger our workflow that gets triggered by the raw:send_email key.

STEP 9: CHECK THE LOGS

Now let’s check that everything went fine by looking at the logs.

Click the refresh button in the same debug panel, you should see a new log appear.

If there are errors, they will show in the error log below

If your workflow log is under “Last 10 logs” then you have successfully created the workflow!  Check your email to make sure you received it.  Note, your account will allow up to 10 emails per hour to be sent.  After that, they will queue up.  If you require more, you can link your own mailchimp account.  Refer to http://docs.mediumone.com/.

TIP: To help troubleshoot issues, you can use log statements in the code:

For example, not the two added lines beginning with log:

# Get input data from input named ‘in1’

name = IONode.get_input(‘in1’)[‘event_data’][‘value’]

log(name) #log name

# build a basic html message

html = “<html><body>Hello, you just triggered an email.</body></html>“.format(name)

log(html) #log html

The log data will appear under the log on debug panel, simply click on the log to view.

Note: Although debug events will trigger workflow they will not be saved in the database.

STEP 10: RUN THE WORKFLOW

You can go back to the mobile app to send the same event again to test the workflow.  However for demonstration purposes, let’s see how we can send an event directly from the Dashboard using the dashboard User Input widget.

Go to Dashboard and scroll down the page to the widget selection toolbox.

It will create a new User Input widget. Select a user in the drop down.

Then click the gear icon to configure the tag to send data to:

You can type in the search box to find the raw:send_email tag

The widget will show a String Input box:

Type in your name, and click Send to send the event.

Back at the top of Dashboard, click the Save icon to save this view; we will come back here later.

If you go back to your workflow, with debug activated, you should see another new log created.

TIP: You can add additional input triggers by opening the Base Python, click the Inputs / Outputsdrop down and click Add Input.

The rest is up to your imagination!

1 view

© 2018 Medium One   All Rights Reserved

4633 Old Ironsides Dr. #280, Santa Clara, CA  95054                

info@mediumone.com

|

  • LinkedIn - White Circle
  • Twitter - White Circle
  • YouTube - White Circle
  • Google+ - White Circle