I was making a simple Toast notification with a text box and a button that would send a POST request with the TextBox data. Something like this.
When I press “Reply” I wanted to send a POST notification with the text box with it’s id textBox
. Now the code I did, the notification did work, however, when I typed something and pressed “Reply”, that data isnt sending.
here’s the code.
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
$app = '[redacted]'
$template = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<actions>
<input id="textBox" type="text" placeHolderContent="Type a reply" arguments="textBoxTest" />
<action activationType="foreground" content="Reply" arguments="reply" />
</actions>
</toast>
"@
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($template)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
$toast.add_Activated({
param($sender, $e)
$reply = $e.UserInput['textBox']
# Send POST request
$uri = "https://your-api-endpoint.com"
$body = @{
id = $reply
} | ConvertTo-Json
Invoke-RestMethod -Uri $uri -Method Post -Body $body -ContentType "application/json"
})
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("$app").Show($toast)
is there anything missing or something I can replace?