We are aware of an issue with the Search bar. Please use Advanced search for the time being while we troubleshoot. Thanks for your patience as we work on improving the community!

Engine Works

Under the hood of Alteryx: tips, tricks and how-tos.
grossal
14 - Magnetar
14 - Magnetar

Most business users stop listening right about when I first mention any coding language. I can’t code. You don’t need to know how to code in order to make code work. It doesn’t take much to make your own Python Scripts and Macros extend existing functions. This blog will show how you can build your own macro to send smartphone notifications with Alteryx.

 

In a recent LinkedIn post I showed off my tools to send notifications to your smartphone within an Alteryx workflow. I received many responses with great feedback on it and people asked me if I could make my original German blog also available to the English community. Well then here you go!

 

You prefer a video of the tools? I got you covered! I presented this a couple weeks ago at the Alteryx Dallas User Group (thank you @Deanna). The recording will be added as soon as it's available.

 

Let’s get some basics knocked out first and then we’ll follow a step-by-step guide how to create it yourself. You don’t need to know Python. It’s fine if you have never seen or written in Python or any language before. I’ll cover everything that you need to make it work, but to be clear, this blog also does not aim to teach you Python. I will show you how simple it is, and you can decide for yourself if you want to learn it.

 

Why Python?

Alteryx offers a lot of SDKs (Software Development Kits) to build custom tools, but why Python? One reason is, because we don’t need to use one of the SDKs, we can simply use the Python tool inside Alteryx Designer and can ignore all the stuff that comes with the SDK which will make our lives a bit simpler for now. Additionally, Python is one of the most popular coding languages and there are many open-source packages.

 

Why would I want to create a smartphone notification?

“I could also do this with an Email tool” – that’s totally true. It’s just not sexy. I also have to clean up my mailbox afterwards. I often start workflows while I take a break and want to know when they are done. To me, it’s just nasty to always have to setup an Email tool. I just want a quick note on my smartphone and then never see it again.

 

The start

Google_Python_Create_Phone_Notification.png

I hope you didn’t expect something sophisticated. Just like all of us, when I stumble across a challenge, I Google it. You’ll quickly see tools like Pushsaver, Pushbullet or Notify_Run – I personally decided to go with Pushbullet and give it a try. As a second step I Googled ‘Python Pushbullet’ and the first result is a PyPi-Site.

 

What’s PyPi?

Experienced coders might disagree, but I would simplify it and call PyPi the Alteryx Gallery for Python packages. PyPi also makes it super easy to install tools; we’ll see this in a minute.

 

Python Tool | Preparation

I always start the same way: I drop an empty Text Input tool into the canvas (fill it with an X to remove the error) and connect it to a Python tool (first introduced in 2018.3). Afterwards you need to run the workflow once to start. It doesn’t matter if you have the newest Alteryx Version (2021.1) with Python 3.8.1 or an older one – the latest Python features are not required.

2021-02-07 15-43-43.png

When we click on the Python tool we’ll find some boilerplate code that we don’t need. We can remove it by clicking on the scissors icon three times.

 

2021-02-07 15-45-33.png

 

Afterwards, it should look like this:

 

2021-02-07 15-46-37.png

 

Python Tool | Installing Packages

Let’s take a look at the PyPi-Guide and see what they say about installing packages:

 

2021-02-07 15-47-54.png

 

We can basically copy paste this into the Python tool, but we need to add an exclamation mark in front of it to make it work (I won’t go into the details of the why). You can execute the install command with SHIFT + ENTER.

 

2021-02-07 15-48-53.png

 

Python Tool | Import Package and write Code

After the installation of the package, we need to import it. The guide states the following:

 

from pushbullet import Pushbullet
pb = Pushbullet("YOUR_API_TOKEN")

 

We can copy and paste this one into the tool. We can also copy the next step of the guide. In between we can click on the whole block and hit ‘B’ once to create a new cell (we could also do this using the Insert menu at the top).

 

push = pb.push_note("This is the title", "This is the body")

 

The code should now look like this:

 

2021-03-14 17-24-32.png

 

Great job! You now have all the code you need for our task to send out notifications to our smartphone.

 

Pushbullet | What is this?

Pushbullet is an app that you can install on your smartphone, tablet or PC. The best part and also the reason why we are using it is simple: Pushbullet has an API that allows us to create messages that will be distributed to your devices and pop up as a notification. It’s especially simple, because Pushbullet allows us to login with our Google account and avoid creating another account.

  

Pushbullet | API Token

As you might have guessed it by one of the previous screenshots: we need a token to tell the API who we are. But how do we get it? After logging into the website, we can go to settings and click on “Create Access Token” – that’s it.  

 2021-02-07 15-55-25.png

 

We then must replace our text YOUR_API_TOKEN with our generated token (make sure you paste it into the quotation marks). If you now hit SHIFT+Enter in that block and the following, you should see a notification on your smartphone (obviously you need to install the app beforehand and make sure you login with the same account).

 

Did that work? That’s it! You did it!

 

Convert to macro and finetune

After our successful test run, we can work on filling out the details. First, we should convert our Text Input tool into a Macro Input, we can easily do this with a right click and the ‘convert to macro input’ option. I also like to choose the option ‘Optional Input Connection’, because we don’t reference the data coming into our macro anyway.

 

In the next step we want to update our static information like title, message text and API Token to be dynamic. We can do this using three Text Box and Action tools. Pro Tip: Connect the Text Box directly to the Python tool and it’ll automatically place an Action tool in between.

 

2021-02-07 15-59-09.png

 

Before we configure the Action tools, we should switch our Python tool to production mode, this will boost the performance by 1-2 seconds because the tool doesn’t need to load the interactive layer. If you want, you can also leave it in the interactive mode. It’s just a slight performance boost.

 

2021-02-07 16-02-33.png

 

Afterwards we need to set up our Action tools. Important are the following aspects:

  • Select “ProductionModeScript – value” (only if you switched to production-mode)
  • Use the “Replace a specific string” option and replace in every action tool only the portion you want to replace (ie. title, message, token)

 

2021-02-07 16-01-30.png

 

That’s it. We are done. Now we can choose an Icon if we want – but you can also leave it that way.

 

Spoiler

Tip: It’s best practice to rename the texts before you update them with action tools.

2021-03-07 21-12-46.png

 

Result

2021-02-07 16-07-32.png

 

Because I only use the tool for myself, I personally set up my own token as a default value in the Token text box. This makes it very convenient to use the tools. 

 

Closing Thoughts

Compared to other tools that send / generate notifications, Pushbullet has a limit of 100 messages per month that can be sent without making a purchase – to me that’s totally fine. If you need more, you might also look at Pushsaver and Notify_Run. Both are similar, and I also made myself a Notify_Run tool.

 

While writing this blog, I also noticed that Pushbullet stopped its service on iOS because of recent Apple changes. In case of Apple smartphones, you might want to give Pushsaver or Notify_Run a shot.

 

“Can I also reference data from the workflow?” – Yes you can. I’d recommend using the Alteryx way of handling it and building the Pushbullet macro into a Batch Macro. If you are familiar with coding, you could also adapt the code, but I want to keep it as simple as possible for everyone here.

 

"I am not allowed to install packages - what should I do?" I got you! Check out the spoiler box below 🙂

 

Spoiler
You could improve / remove the error handling if you want, but you don't have to.

If you followed my previous tip and used __token__, __title__ and __message__ - you can leave all Action tools unchanged.
#################################
import requests
import json
def pushbullet_message(title, body):
    msg = {"type": "note", "title": title, "body": body}
    TOKEN = '__token__'
    resp = requests.post('https://api.pushbullet.com/v2/pushes', 
                         data=json.dumps(msg),
                         headers={'Authorization': 'Bearer ' + TOKEN,
                                  'Content-Type': 'application/json'})
    if resp.status_code != 200:
        raise Exception('Error',resp.status_code)
    else:
        print ('Message sent') 

#################################
pushbullet_message("__title__","__message__")

Credit goes to this article on Medium (you'll also find other interesting ways to create notifications in this article).

Last words? Thank you @Deanna for giving me the opportunity to present this at the Dallas User Group and thank you @joshuaburkhow and @Aguisande for proofreading this blog.

 

Feel free to get in contact with me in the comments, here on the Community or on LinkedIn if you have further questions.

Comments
Qiu
17 - Castor

@grossal 

Thank you for sharing this good insight. 

Will definitely give a try.

sparksun
7 - Meteor

It works,awesome!

Sergio_Avalos
5 - Atom

Thanks for sharing! 

StephJ
Community Manager
Community Manager

Thanks for sharing @grossal

Emil_Kos
16 - Nebula

@grossal this is super cool. I will definitely use this knowledge in a near future!

the_jake_tool
12 - Quasar

Thank you thank you thank you @grossal  for sharing this in this post!

kelly_gilbert
12 - Quasar

This is a neat use case to help ease someone into using the Python tool. I feel like some of my colleagues are intimidated by it, like they feel like they need to fully learn all of the syntax first.

 

@grossal also makes a great point that even if you are restricted from downloading new packages, there is a ton you can do with just the packages that are automatically installed when you install Alteryx!

fpinchon
8 - Asteroid

That's a great concept, fun to setup... 

Just note that Pushbullet is not available on IOS anymore, so if you have an iPhone, you might consider free https://www.pushsafer.com/ instead or cheap  https://pushover.net/ instead, both supported on IOS...

Kenda
15 - Aurora
15 - Aurora

Cool stuff @grossal

ArtiRajput
8 - Asteroid

Amazing!

Shifty
11 - Bolide

Really enjoyed this @grossal. Thanks for posting. 

ThomasT
7 - Meteor

Hi @grossal 

great blog. I've been doing the most dodgy things to bypass python macros as I coulnd't figure it out and it also never works to feed line by line into a python macro, so I was quite excited to get this going, but again I can't manage to make it work. 

 

The macro that I've created worked (no errors) but the values that I have selected didn't get updated. The original value in the script worked when running the macro, but the ones that came in through the control parameters didn't. I've tried both in 'Interactive' and 'Production' mode and even tried to update both at the same time, but it just doesn't work. 

 

My script (highlighted in yellow the two items that I'm trying to update for each iteration):

ThomasT_0-1621376233846.png

 

Two control parameters that I have set up as below to replace the specific part of the string only (only for the production mode):

ThomasT_1-1621375471069.png

ThomasT_3-1621375688872.pngThomasT_4-1621375765981.png

 

Macro input of row 2 is the same as the baseline script in the macro which is executed when running the workflow, row 1 and row 3 which are supposed to be iterated in, are not executed. Unfortunately i don't get any error to check what went wrong. It simply seems as if the values don't get updated as they should. 

 

Any ideas?

 

Gruss,

Thomas

 

Thableaus
17 - Castor
17 - Castor

Clean and simple. Loved your solution, @grossal 


Thanks for sharing, fav'd that for sure.