npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

imessage-rest-service

v1.0.4

Published

A basic rest service sending imessages

Downloads

8

Readme

imessage-rest-service

A REST service that will transform incomming data and send it as imessages. This could for example be used together with Home Assistant REST notify integration.

The service only supports plain text imessages.

This service only runs on Mac OS X and needs native messages application installed (and logged into an iCloud account) The numbers that you want to send to needs to be stored under a contact in your address book. The messages will be sent as logged in user in messages application. If using for home automation notifying, I suggest you create a seoarate "system" iCloud account to separate messages from real persons.

Installation:

  1. Deploy this code to a server (with Mac OS X as OS) running Node.js
  2. Run npm install
  3. Generate certificates (see bellow)
  4. Copy and rename .env.sample to .env
  5. Add your ACCESS_TOKEN and ALLOWED_IPS to your environment vars to add some basic security
  6. Fire up with npm start

Generate SSL Certificates

openssl req -nodes -days 3650 -new -x509 -keyout server.key -out server.cert

The server.key and server.cert needs to be in the same directory as app.js.

Post JSON sample:

{
  "message": "Hello there",
  "number": "+22223445566",
  "title": "Hej"
}

JSON attributes explaination:

message: Message to send, format: plain text (mandatory)
number: Phone number that blongs to one of your contacts, format +22223445566 (mandatory)
title: Title to prefix message with, format: plain text (optional)

If ACCESS_TOKEN is set in .env add http header x-access-token with the your choosen ACCESS_TOKEN as value in all requests to the service.

The complete message that will be sent is in format <title> - <message>. If you want to concat title and message with something else between, uncomment and change TITLE_MESSAGE_CONCATENATION in .env.

Home Assistant Configuration Example

If want to use this rest service from Home Assistant, this is what should be added

notify:

# Imessage using REST
- name: imessage
    platform: rest
    resource: !secret imessage_resource
    method: POST_JSON
    verify_ssl: false
    headers: 
      x-access-token: !secret imessage_access_token
    message_param_name: "message"
    title_param_name: "title"
    target_param_name: "number"

# Persons
- name: imessage_john_doe
  platform: group
  services:
    - service: imessage
      data:
        target: !secret imessage_number_john_doe

Some explanations:

Following needs to be defined in your secrets.yaml

  • imessage_resource
  • imessage_access_token
  • imessage_number_john_doe

Like this for example:

# https://<IP_OF_HOME_ASSISTANT_SERVER>:<PORT>/webhook
message_resource: https://192.168.1.333:8888/webhook
# Access token defined in .env
imessage_access_token: 66a4c348-36ff-43b6-aeb8-e9cc122bbe36
# Person phone number
imessage_number_john_doe: "+22223445566"

The fragment under # Persons could be repeated as many times as you want. Just make sure have a unique name and target defined for each person/number.

If not using access token remove the following lines

    headers: 
      x-access-token: !secret imessage_access_token

And now you could invoke it from an automation as any other notify service