Categories
General Tech IoT Linux

Making a phone notification tool using Discord Webhooks

Reading Jlelse’s blog here (https://jlelse.blog/dev/telegram-go/) I realised there is another alternative to using an automation tool like IFTTT or Microsoft Power Automate, is to use a messaging app like Discord or Telegram. Previous post on the same topic:
https://jaytuckey.name/2020/04/21/making-a-simple-phone-notification-tool-using-ifttt-available-on-a-free-account/

Creating the Discord Notification Webhook

To make a personal notifier using discord you will need to make your own empty server for just you:

  • Make a server
  • Go to the #general channel settings
  • Go to Webhooks section and create a webhook:
  • Copy the URL, and use this in your script

A Shell Script to send a notification

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 '{"content": .}')" 'https://discordapp.com/api/webhooks/mynum/mykey'

A Python3 example using requests library

#!/usr/bin/python3

import json
import requests
import sys

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

message = ' '.join(sys.argv[1:])
url = 'https://discordapp.com/api/webhooks/mynum/mykey'
data = json.dumps({"content": message})
requests.post(url, headers={'Content-Type': 'application/json'}, data=data)

Other examples can be taken from my previous post on IFTTT, just change the JSON data to use content instead of value: https://jaytuckey.name/2020/04/21/making-a-simple-phone-notification-tool-using-ifttt-available-on-a-free-account/

Leave a Reply

Your email address will not be published.