2 releases

0.2.2 Apr 26, 2021
0.2.1 Mar 13, 2021

#1220 in Web programming


Used in test-notifier

MIT license

23KB
137 lines

Nustify

crates.io Documentation

💬 Send iOS/Android notifications using IFTTT's Webhook 💬

nustify = "0.2"

IFTTT

From Wikipedia:

IFTTT is a free web-based service to create chains of simple conditional statements, called applets. An applet is triggered by changes that occur within other web services such as Gmail, Facebook, Telegram, Instagram, or Pinterest.

IFTTT proposes hundreds of triggers, but the one that Notigo uses is the Webhook trigger (also known as Maker Event).

By creating an IFTTT applet that sends a rich notification to your device when a Webhook is triggered, we can create a simple wrapper and use it in our Rust code.

IFTTT account and mobile app

In order to receive a notification from IFTTT, you have to create an IFTTT account and download the iOS app or the Android app.

Creating the IFTTT applet

Next, you need to create the corresponding applet in your IFTTT account. Applets that use Webhook as a trigger can't be share like other applets, so you need to create it manually:

  • Go to the applet creation page;
  • Search for webhook and select the Receive a web request trigger;
  • Specify the name of the event
  • Click on Create trigger;
  • For the that action, search for notification and select the Send a rich notification from the IFTTT app action;
  • Use the Add ingredient button to add value1 as a title and value2 as a message. value3 as a link or image URL.

The final configuration of the applet looks like this:

Screen Shot 2021-04-26 at 00 54 32 Screen Shot 2021-04-26 at 00 55 54

Getting the Webhook key

The last step before using the applet is to get your Webhook key. Head to the Webhook settings page then click on the Documentation button on the upper right corner.

Now that you have created the applet and got your Webhook key, you can use the library or the example command.

Using the library

Here is a simple example that send a notification with "Hello from Rust" as a title and "Rusty content" as a message:

use std::error::Error;
use nustify::notification::Builder;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn Error>> {
    let key = "MY_IFTTT_KEY";
    let notification = Builder::new("Rusty content".to_owned())
        .title("Hello from Rust".to_owned())
        .build();
    nustify::send(&notification, "nustify", &key).await?;
    Ok(())
}

Sending images

If you want to add an image to your notification, you have to pass its link rather than the image data itself. This library also provides a wrapper to the Imgur API allowing you to first upload the image to Imgur.

Golang version

I also released a Golang version of this library and a command.

Enjoy simple notifications!

Dependencies

~3–16MB
~233K SLoC