Pushbullet Integration

Posted by Wyth on Wed 02 Mar 2016 01:17 AM — 10 posts, 35,620 views.

#0
First off, if this all seems incredibly janky, I apologize. At this point my brain is kind of fried. I'd like to set up pushbullet notifications where if someone says my name on a specific channel, it will push that line to me.

I was originally trying to do it just in lua, but was having a hell of a time getting https (which is required by pushbullet) to work. After wasting a lot of time there, I decided to move on and just figure out how to have the trigger execute a shell script which I know will work. So I set it up to pass a parameter on.

Here is the trigger I'm using:

<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="^(.+) gossip \'.*(wyth|Wyth|WythDryden).*\'$"
regexp="y"
repeat="y"
send_to="12"
sequence="100"
>
<send>assert (utils.shellexecute ("C:/Users/Wyth/Desktop/pushbullet.sh", "%0", nil, nil, 0))</send>
</trigger>
</triggers>

and this is the shell script I'm using:

!/bin/bash

# The API Key
API_KEY="####################"

# Note Title
NOTE_TITLE="Emperia"

# Body of the Message
BODY="$1"

curl -k -u "$API_KEY": https://api.pushbullet.com/v2/pushes -d device_iden=#################### -d type=note -d title="$NOTE_TITLE" -d body="$BODY"

The trigger will successfully go off, but when I receive the pushbullet notification it only sends the first word on the line. I suspect that it's because the parameter is being sent without "" on the shellexecute, so it only sees that first word which is picked up at the $1 in the script. I tried using $a in the script but that didn't work. I also tried putting '' in various spots to no avail. Maybe it's a really easy thing I'm overlooking, or maybe it's not possible, but at this point I can't wrap my brain around it. Would anyone perhaps be able to shed some insight into which direction I should go in?
USA #1
I'm a Lua newbie so I'm just saying this to perhaps help your line of thinking into figuring this out until one of the superhero's show up.

I notice in the trigger you have two groupings.
(.+) and (wyth|Wyth|WythDryden)

The first one would account for the $1, however I know nothing about shell scripting so I could be wrong on that, but in lua %1 is the first wildcard and makes sense why you are only getting one word as that's the only wildcard being passed along to the shell.

Maybe make a trigger to capture everything and use an if statement to pass it on?
#2
Wuggly said:

I'm a Lua newbie so I'm just saying this to perhaps help your line of thinking into figuring this out until one of the superhero's show up.

I notice in the trigger you have two groupings.
(.+) and (wyth|Wyth|WythDryden)

The first one would account for the $1, however I know nothing about shell scripting so I could be wrong on that, but in lua %1 is the first wildcard and makes sense why you are only getting one word as that's the only wildcard being passed along to the shell.

Maybe make a trigger to capture everything and use an if statement to pass it on?


Well in the trigger itself I'm actually using %0 to use the entire line, and not just the phrase that triggers it. If I try changing the shell script to use $0 instead of $1 then the string sent in the pushbullet note is actually the file/filepath of the script itself.

Also, for the record, if I try sending an entire string with "" from the command line it works.

C:\Users\Wyth\Desktop>sh pushbullet.sh "This is a string."
USA #3
Have you tried putting it into a variable then pass the variable to the shell?

So it's like this..

<send>
matched_line = "%0"
assert (utils.shellexecute ("C:/Users/Wyth/Desktop/pushbullet.sh", matched_line, nil, nil, 0))
</send>


My line of thinking is since it's passing the whole line, that maybe it's passing along the wildcards too and perhaps putting it into a variable will put those matches into the string.
Amended on Wed 02 Mar 2016 04:21 AM by Wuggly
#4
Wuggly said:

Have you tried putting it into a variable then pass the variable to the shell?

So it's like this..

<send>
matched_line = "%0"
assert (utils.shellexecute ("C:/Users/Wyth/Desktop/pushbullet.sh", matched_line, nil, nil, 0))
</send>


I did try that, and unfortunately it doesn't make a difference.

I'm pretty certain that the %0 is catching the whole line:

<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="^(.+) gossip \'.*(wyth|Wyth|WythDryden).*\'$"
regexp="y"
repeat="y"
send_to="12"
sequence="100"
>
<send>assert (utils.shellexecute ("C:/Users/Wyth/Desktop/pushbullet.sh", "%0", nil, nil, 0))
print("%0")</send>
</trigger>
</triggers>


<4249/11517 36hp 2409/2409 100m 811/1586 2502tnl 7105hps>
go wyth saying a thing
You gossip 'wyth saying a thing'

<4252/11517 36hp 2409/2409 100m 823/1586 2502tnl 7105hps>


The "You gossip 'wyth saying a thing'" is printed from %0. But the body of the pushbullet message sends only the word 'You'. I'm pretty sure this would be an easy solve if I had the syntax of the shellexecute correct to send the entire string as a parameter within "", (which is working if I do that manually from a prompt) but I can't seem to figure it out right now. Also, the window does pop up when running and then disappears when it's done, despite putting the "0" at the end of the command. So this also leads me to believe my syntax might be the problem.

Also, thanks for taking the time to reply. I'd try to get back to you sooner, but the forum software will only let me respond like every 20 minutes. I thought I had an account here before from all the lurking I did, but apparently I didn't.
USA #5
Have you tried using %10 in the trigger instead of %0?

While reviewing the triggers page.
http://www.gammon.com.au/scripts/doc.php?general=triggers


I saw this..

Quote:
Wildcard 10 is the entire matching sequence, which is not necessarily the same as the matching line in the case of regular expressions.


Then of course the %0 is...

Quote:
Wildcard subscript 0 is the entire matching line.



EDIT: Actually I believe that would only make it worse since you are using a regex.

Plus since you said
Wyth said:

The "You gossip 'wyth saying a thing'" is printed from %0.


which means everything lua-wise is doing it's job. Seems more likely a shell scripting problem. Maybe you'll luck out with someone here who also knows shell or you could always ask at the stackexchange website.
Amended on Wed 02 Mar 2016 05:37 AM by Wuggly
Australia Forum Administrator #6
Quote:

I suspect that it's because the parameter is being sent without "" on the shellexecute, so it only sees that first word ...


You could embed quotes, eg.


assert (utils.shellexecute ("C:/Users/Wyth/Desktop/pushbullet.sh", "\"%0\"", nil, nil, 0))


Not sure if that will help.

Quote:

Have you tried using %10 in the trigger instead of %0?


The 10th wildcard would be %<10>
#7
Nick Gammon said:

Quote:

I suspect that it's because the parameter is being sent without "" on the shellexecute, so it only sees that first word ...


You could embed quotes, eg.


assert (utils.shellexecute ("C:/Users/Wyth/Desktop/pushbullet.sh", "\"%0\"", nil, nil, 0))


Not sure if that will help.

Quote:

Have you tried using %10 in the trigger instead of %0?


The 10th wildcard would be %<10>


Thank you! I knew it had to be some manner of that syntax, I kept messing around with it, but with single ' and double ". My brain was just fried, but that makes perfect sense. My only other question is that the window still pops up to run the script, even though I am passing 0 as the 5th argument. Any idea why?

Thanks again in advance!
USA #8
Reading http://www.gammon.com.au/scripts/doc.php?lua=utils.shellexecute

Have you tried using 2 instead of 0?

Quote:

2: Activates the window and displays it as a minimized window.
#9
Wuggly said:

Reading http://www.gammon.com.au/scripts/doc.php?lua=utils.shellexecute

Have you tried using 2 instead of 0?

Quote:

2: Activates the window and displays it as a minimized window.



It produces the same effect.