Jump to content
paulminors

[SOLVED] Alfred notification message

Recommended Posts

Hi everyone.

 

I have a workflow that I use to create tasks in Asana using Alfred. I have a notification that I'd like to show the task (Query) when it's done. It used to work, but now the notification shows as this:

 

886619096_AlredNotification.png.6cbdd246a900d9f39a75782d2afbc24f.png

 

Here's the setting:

 

1069665984_Screenshot2019-01-0910_46_26.png.f086654ba4db6089944f862abe0a13ea.png

 

Thanks in advance for any advice :)

Share this post


Link to post

Hi Paul,

 

I'm going to move this to the Workflow Help & Question forum. If you're not talking about your own workflow, then it probably really belongs in the actual workflow's thread, where people who know the workflow (not least its developer) can provide a proper answer.

 

The problem is that the workflow is sending a bunch of JSON to a Post Notification element. I can't possibly say more than that based on screenshots.

 

 

Share this post


Link to post
2 minutes ago, paulminors said:

Does this screenshot help?

 

Not in the slightest, I'm afraid. Please read and follow the "Reporting Problems with Workflows" I just linked.

 

As I said, you're seeing a bunch of JSON in the notification because your workflow is sending a bunch of JSON to the Post Notification element.

 

I can't possibly give you a more precise answer specific to the workflow you're talking about because I do not have the workflow you're talking about.

Share this post


Link to post
Posted (edited)

And what exactly do you want to see in the notification?

 

I think I just added a note or three called "deans-test" to your thing. I've tried messing with the URL/query, but it doesn't seem to make much difference to the API response.

 

From my reading of the API docs, however, a bad call should return a 4xx response.

 

I can't get it to, but you're not checking for failure in any case.

 

Changing your Run Script to the following should help (replace success with whatever you want to be shown in the notification body):

curl -sSL $ZAP_URL?note="{query}" >/dev/null
echo -n "success"

 

That sends whatever curl returns to /dev/null (i.e. a blackhole) and you'll only see what's echoed in the notification.

 

If that's okay for you, delete the above workflow from your Dropbox, so Internet randos can't spam your Zapier with stuff.

Edited by deanishe

Share this post


Link to post
Posted (edited)

To confirm, your tests came through to my account so they all worked fine.

 

Thanks, that seems to be working better. However, in the notification to show, I'd like the Alfred query to show. So the notification should be:

 

Task Created!

deans-test

Edited by paulminors

Share this post


Link to post

Thanks for that, it's working perfectly now.

 

Weird though - when I put in {query} before, it wasn't working. I must have done something wrong. 

 

Thanks again!

Share this post


Link to post

Ah sorry, just one more thing on this. I notice that with an Alfred Query that has spaces, the notification comes through encoded. Do you know how I would avoid this?

 

1543441816_Screenshot2019-01-1014_14_00.png.6be639a9760d068e23d1c932e2535ca7.png

Share this post


Link to post
7 hours ago, paulminors said:

Do you know how I would avoid this?

 

You're doing the encoding yourself in the workflow:

 

1187876489_Screenshot2019-01-10at11_09_16.png.82d7d510f8c3de43e3a4c4233ce4d803.png

 

That's not a good way to URL-encode a query: spaces aren't the only characters that need replacing.

 

Here's a fixed version that shows the query in the notification and properly URL-encodes the query.

Share this post


Link to post

Sorry to open this old thread up but @deanishe, I am trying to convert the post notification into a clickable notification so upon clicking, it would go to the newly created Asana task. 

But I've found that it can't be done as people have requested it as a feature.

 

So I resorted to using "Open URL" as output. All I have to do is put this as static: https://app.asana.com/0/45482574283XXX/{taskID} and take the taskid returned by the successful zapier run. Except I can't figure out how to get that return and put it in there.. using just the variable from Zapier doesn't work either.

 

 

Screen Shot 2019-09-30 at 6.01.07 AM.png

Share this post


Link to post
23 minutes ago, Yourname said:

Except I can't figure out how to get that return and put it in there.. using just the variable from Zapier doesn't work either.

 

You mean to get that number marked "id" from the webpage that opens? That's hard to do.

 

You're probably going about it the wrong way. Webpages are for humans, and APIs are for machines. So, if you want to use the Zapier data in your script, you should probably be using the API to run your Zap.

 

If there is no API, you'll need to open the URL in code and extract the ID from the HTML response.

Share this post


Link to post

Actually, sorry ... should have clarified @deanishe, but that's not a webpage. That's actually the return of zap. Pretty much the first screenshot posted by @paulminors above where the notification showed {"status: success", etc. 

 

That means the zap was sending the success message, along with ID back into the notification. It's just a matter of capturing it and turning it into a URL so the notification becomes an href. Hope this clarifies.. would love to see if we can do that, because this is 100% API.

Share this post


Link to post
7 hours ago, Yourname said:

but that's not a webpage.

 

What's the screenshot of, then?

 

7 hours ago, Yourname said:

would love to see if we can do that, because this is 100% API.

 

So, you do have a JSON response, then. I can't tell you exactly how to do it because I don't have Zapier or a test URL, but basically you need to open the URL in code and parse the response. In Python that would be something like:

from __future__ import print_function

import json
import os
from urllib import urlopen
import sys

# Get URL from workflow/environment variable
URL = os.getenv('ZAP_URL')


def log(s, *args, **kwargs):
    """Log to STDERR."""
    if args:
        s = s % args
    elif kwargs:
        s = s % kwargs
    print(s, file=sys.stderr)


try:
    r = urlopen(URL)
    code = r.getcode()
    log('[%d] %s', code, URL)
    if code > 200:
        raise Exception('request failed')

    # Parse payload and print wanted data, which
    # passes it to the next workflow action
    data = json.load(r)
    print(data['id'], end='')

except Exception as err:
    log(err)
    sys.exit(1)

 

Share this post


Link to post

Thanks @deanishe! Python makes sense for parsing - didn't think of that at all. 

 

So when I realized there needs to be a parser, I realized I have Pushbullet on my Google Chrome, and on my phone. I ended up sending the newly created Asana task ID to Pushbullet instead, and now I get a clickable notification.

 

Now I can create a task, and click into it if I need to assign the task to a project, add context, etc.

 

Screen Shot 2019-10-01 at 4.57.53 AM.png

Screen Shot 2019-10-01 at 4.58.09 AM.png

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...