Webhook with parameters?

chaoscreater

Active member
I've got a bit of a tricky problem. I have the following Powershell script, which queries the traffic in my area and returns some basic data:

$Name = "Upper Harb Hwy - Tristram Ave"

$url = 'https://infoconnect1.highwayinfo.govt.nz/ic/jbi/TrafficConditions2/REST/FeedService/?wsdl'
$headers = @{
'username' = 'xxxxx'
'password' = 'xxxxxx'
}

$response = Invoke-RestMethod -Uri $url -Headers $headers -Method GET -UseBasicParsing

$tnsCongestion = $response.getTrafficConditionsResponse.trafficConditions.motorways.locations | Where-Object {$_.name -like $Name} | Select-Object -ExpandProperty congestion

#Write-Output "The congestion for $Name is: $tnsCongestion"

$Data = "The congestion for $Name is: $tnsCongestion"
Write-Output $Data

$response looks something like this:

$xml = [xml]@'
<?xml version="1.0" encoding="UTF-8"?>
<tns:getTrafficConditionsResponse xmlns:tns="https://infoconnect.highwayinfo.govt.nz/schemas/traffic2">
<tns:trafficConditions>
<tns:lastUpdated>2023-04-21T17:29:58.630+12:00</tns:lastUpdated>
<tns:motorways>
<tns:name>Northern Motorway</tns:name>
<tns:locations>
<tns:congestion>Free Flow</tns:congestion>
<tns:direction>Southbound</tns:direction>
<tns:endLat>-36.7506902724442</tns:endLat>
<tns:endLon>174.726003398276</tns:endLon>
<tns:id>2</tns:id>
<tns:inOut>In</tns:inOut>
<tns:name>Oteha Valley Rd - Upper Harb Hwy</tns:name>
<tns:eek:rder>1</tns:eek:rder>
<tns:startLat>-36.7183869853163</tns:startLat>
<tns:startLon>174.712619564421</tns:startLon>
</tns:locations>
<tns:locations>
<tns:congestion>Free Flow</tns:congestion>
<tns:direction>Southbound</tns:direction>
<tns:endLat>-36.7717936352071</tns:endLat>
<tns:endLon>174.742831686402</tns:endLon>
<tns:id>4</tns:id>
<tns:inOut>In</tns:inOut>
<tns:name>Upper Harb Hwy - Tristram Ave</tns:name>
<tns:eek:rder>2</tns:eek:rder>
<tns:startLat>-36.7506902724442</tns:startLat>
<tns:startLon>174.726003398276</tns:startLon>
</tns:locations>
</tns:motorways>
</tns:trafficConditions>
</tns:getTrafficConditionsResponse>
'@


The above works fine running in Powershell on my PC, but I'm trying to run this on Android. I've tried to convert the above into a shell script, but the problem is that I cannot find any decent xml parser binary packages that can be installed on Android. Sure, grep and sed are already preinstalled on Android and I can access and execute them, but grep on Android is quite limited, it's missing the -P option and this means I can't really make use of it. Other solutions require xml parser packages like JQ, XMLLint or xmlstarlet to be installed, but I couldn't find any binary packages available to download for Android. I'm by no means a Linux user, so a lot of these things are way over my head.

Back to the Powershell script, I've got this set up in an Azure Automation Runbook, which has its own webhook that I can invoke. In the webhook, I can specify the request body and pass in data to the Powershell script, like this:

$webhookURI = "https://5eddf5f7-bf58-4fad-9fb9-xxx...xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$params = @{
Name ="Upper Harb Hwy - Tristram Ave";
}
$body = ConvertTo-Json -InputObject $params
$response = Invoke-WebRequest -Method Post -Uri $webhookURI -Body $body -UseBasicParsing
$response

1682082407957.png


The problem is, Azure Automation Runbook webhook is designed to not return any data. I was hoping that I could invoke the webhook from Android and then use the result from the HTTP response, but looks like this isn't possible.

So then my next idea is to make the Azure Automation Runbook process the result and then pass that into a MacroDroid webhook. The problem is that MacroDroid webhook doesn't seem to support parameters with request body.

All I want is to just make my Android check the traffic, then announce the output (as per screenshot above). It shouldn't be this difficult, but I'm having a hard time trying to make this work.
 

chaoscreater

Active member
Never mind, figured it out. Got it working using a combination of Azure Automation Runbook and MacroDroid webhook. My Azure Automation Runbook will run the script and will get the result as per my previous screenshot. I then take the result e.g. "Free Flow" and pass that as a parameter to the MacroDroid webhook. I then receive the webhook trigger in MacroDroid and I'll take the parameter data and use that in my Actions section.
 
Last edited:
Top