Categories
General Tech Linux Powershell Systems Administration

Making a simple phone notification tool using IFTTT – Available on a Free Account

I previously made a guide on how to create a notifier using Microsoft Power Automate: https://jaytuckey.name/2020/04/21/making-a-simple-phone-notification-tool-using-microsoft-power-automate-previously-microsoft-flow/

However, the Request trigger used in that flow is only available on a premium account so many people won’t be able to use it without a work account. For those people, here’s how to make the same thing using IFTTT:

Creating the IFTTT Applet

  • Select it and choose “Receive a web request”
  • Choose an “Event Name”, eg. “example_notifier” and create the trigger
  • For the “That” part of the applet, search for “Notifications”
  • Select “Send a notification from the IFTTT app”
  • Choose a message, or just put in {{Value1}} for a very simple notification. I used {{Value1}} - from IFTTT
  • Finish the applet

Now you will need to get your notification URL. Go to https://ifttt.com/maker_webhooks and click the “Documentation” button to get your unique key. It will give you something like:
https://maker.ifttt.com/trigger/{event}/with/key/mykeyblahblah

Therefore, for my example_notifier it will be:
https://maker.ifttt.com/trigger/example_notifier/with/key/mykeyblahblah

Testing with Curl

You should now be able to send a test notification using curl (Replace the URL with your own). You will need the IFTTT app installed on your phone and logged in to receive the notification:

~> curl --header 'Content-Type: application/json' --data '{"value1": "test notification"}' 'https://maker.ifttt.com/trigger/example_notifier/with/key/mykeyblahblah'
Congratulations! You've fired the example_notifier event⏎
~>

A Shell Script to send a notification (no escaping)

Note that this script uses the tools curl so it will need to be installed. This script also doesn’t do any escaping of characters that might be passed so " characters will break it easily:

#!/bin/sh

curl --header 'Content-Type: application/json' --data "{\"value1\": \"$1\"}" 'https://maker.ifttt.com/trigger/example_notifier/with/key/mykeyblahblah'

Same script but using jq to escape input

Note that this script uses the tools curl and jq so they will need to be installed for it to work:

#!/bin/sh

curl --header 'Content-Type: application/json' --data "$(echo $1 | jq --raw-input '{"value1": .}')" 'https://maker.ifttt.com/trigger/example_notifier/with/key/mykeyblahblah'

A Python3 Script to send a notification

This script uses only the standard library in Python3:

#!/usr/bin/python3

import json
import urllib.request
import sys

if len(sys.argv) < 2:
    print('need to provide an argument')
    exit(1)

message = ' '.join(sys.argv[1:])
url = 'https://maker.ifttt.com/trigger/example_notifier/with/key/mykeyblahblah'
data = json.dumps({"value1": message}).encode()
req = urllib.request.Request(url)
req.add_header('Content-Type', 'application/json')

with urllib.request.urlopen(req, data) as opened_req:
    opened_req.read()  # read back all the data

A Python2 Script to send a notification

Sometimes you don’t have python3 available (eg. MacOS), so you may want to use python2 to send a notification:

#!/usr/bin/python

import json
import urllib2
import sys

if len(sys.argv) < 2:
    print('need to provide an argument')
    exit(1)

message = ' '.join(sys.argv[1:])
url = 'https://maker.ifttt.com/trigger/example_notifier/with/key/mykeyblahblah'
data = json.dumps({"value1": message}).encode()
req = urllib2.Request(url)
req.add_header('Content-Type', 'application/json')

opened_req =  urllib2.urlopen(req, data)
opened_req.read()  # read back all the data

A Powershell Script to send a notification

param([String][Parameter(Mandatory=$true)]$Message)

$Uri = 'https://maker.ifttt.com/trigger/example_notifier/with/key/mykeyblahblah'

$_ = Invoke-WebRequest -UseBasicParsing -Method Post -Headers @{'Content-Type'='application/json'} -Body (ConvertTo-Json @{'value1'=$Message}) -Uri $Uri

Leave a Reply

Your email address will not be published.