Messages app plugin

Posted on
Wed Jan 27, 2016 2:39 pm
gazally offline
Posts: 27
Joined: Jan 18, 2016
Location: Bigfoot country

Messages app plugin

Here's my first plugin, which lets Indigo send and receive messages with the OS X Messages app. I wrote it because I wanted to make turning the water on and off at our vacation house super simple for my non-techie family members. And I wanted to learn Python and it seemed like a good little project.

The basic idea is that you set up a device to send and receive messages. Received messages can be retrieved from the device state, and there are plugin actions to mark a message as read and to send outgoing messages.

For both instructions and the download, see: https://github.com/gazally/indigo-messages

The plugin relies on an Applescript handler to collect messages and pass them onto Indigo so installation is a tad more complicated than usual, but I've put instructions in the github README for how to do it. It seems likely that Applescript handler support is not very high priority for the Messages development team at Apple because the El Capitan version, the only one I've tried it on, has a couple of bugs. I don't have a solution for either one of them, but they're not hard to work around either. See the end of the README for details.

Posted on
Wed Jan 27, 2016 3:59 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Messages app plugin

Nice, thanks for the contribution!

It occurs to me that if you're running Yosemite or better you probably can send TXT messages as well since continuity would just pass it over to your iPhone (if you have one that is). Hmmmm...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jan 27, 2016 4:11 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Messages app plugin

And, yes, it does seem like the trend at Apple over the past several years is to allow AppleScript to languish. This is no small part of the reasoning why we've moved away from it to Python as our scripting language.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jan 28, 2016 6:48 am
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: Messages app plugin

This is awesome!

I have been waiting so long for this.

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Thu Jan 28, 2016 7:28 am
jalves offline
Posts: 744
Joined: Jun 16, 2013

Re: Messages app plugin

This looks like it could be very useful. I'm going to have to try it out. Thanks for the development effort!

Running Indigo 2023.2 on a 24" iMac M1), OS X 14.4
Jeff

Posted on
Thu Mar 24, 2016 12:11 pm
kadluvu offline
Posts: 6
Joined: Mar 18, 2016
Location: Portland, OR

Re: Messages app plugin

My objective will be pretty simple. I get a lot of text messages sent to me via sending an e-mail notification. It works great, but EVERY message has a unique number from ATT (Sending an e-mail to phone number@txt.att.net. I'm hoping this plugin will enable me to send notifications and have them all nested as from my AppleID.

~ Easy setup and now my messages are nested! Very nice.

Posted on
Fri Mar 25, 2016 11:06 am
Seeker offline
Posts: 440
Joined: Aug 05, 2013

Re: Messages app plugin

Thank you for this plugin. i just installed it and setup a test action and it seems to work great!

Posted on
Mon Mar 28, 2016 10:56 am
gazally offline
Posts: 27
Joined: Jan 18, 2016
Location: Bigfoot country

Re: Messages app plugin

I just put a ridiculously minor update up, to fix a bug that was leading to duplicate lines in my daily chatlog report. If anyone might find it helpful, here's the script I'm using to get a daily email containing all of Indigo's communications using the Messages plugin. It requires the SQL Logger plugin and I have it on a schedule running just before midnight:

Code: Select all
import sqlite3

def format_lines(rows):
    results = []
    rows = sorted(rows, key=lambda tup:tup[1])
    for r in rows:
        date, time, name, msg, resp, st1, st2 = r
        if st2 == "New":
            results.append("{0} {1}> {2}".format(time, name, msg))
        else:
            results.append("{0} Indigo> {1}".format(time, resp))
    return results

logpath = indigo.server.getInstallFolderPath() + "/Logs"
db = logpath + "/indigo_history.sqlite"
conn = sqlite3.connect(db)
c = conn.cursor()

chatlog = []
for dev in indigo.devices.iter("me.gazally.indigoplugin.Messages"):
    chatlog.extend(c.execute("SELECT date(ts, 'localtime'), time(ts, 'localtime'), name, message, response, responsestatus, status FROM device_history_" + str(dev.id) + " WHERE date(ts, 'localtime')=date('now', 'localtime') AND (status='New' OR responsestatus='Sending')"))

conn.close()
if chatlog:
    indigo.server.sendEmailTo("xxxx@xxxx.com", "Indigo daily chatlog", "\n".join(format_lines(chatlog)))


Posted on
Mon Mar 28, 2016 11:48 am
petematheson offline
Posts: 847
Joined: Sep 14, 2014
Location: Southampton, UK

Re: Messages app plugin

Nice work on this one! Following for future updates but all seems to be working well so far on El Capitan :D

Posted on
Fri Apr 15, 2016 3:24 pm
Seeker offline
Posts: 440
Joined: Aug 05, 2013

Re: Messages app plugin

Can you explain the 'mark as read' deal? The plugin works great, but the messages don't show up as new.

Posted on
Fri Apr 15, 2016 7:09 pm
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

Re: Messages app plugin

Very cool!

FYI Matt, Continuity would only work in the oddest use case for this plugin: when you're at home near your server.

Continuity won't work if you're out of the house, unless you left your phone at home!

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun Apr 17, 2016 12:22 pm
gazally offline
Posts: 27
Joined: Jan 18, 2016
Location: Bigfoot country

Re: Messages app plugin

My Indigo installation has its own iCloud account. Maybe Matt's has its own iPhone :P

Seeker, I'm not really sure what your question is. When a message arrives the device state should go to New and stay there until you use the Mark as Read action. If additional messages arrive after the first one, they will wait for you to use Mark as Read before overwriting the first one.

The reason for "Mark as Read" is to make the message device states stick around so that you can use them in actions attached to a trigger without the risk that a new message will arrive and cause the device states to be overwritten before the actions have had a chance to read them. Because if a plugin or device used in one of your actions is busy when a trigger fires, Indigo will queue that action up as work to be done later and possibly do all kinds of other stuff before that action actually happens. This is mostly a concern with my Chatbot plugin, which could potentially be running some time-consuming Python script in response to the last message when the new one arrives.

Posted on
Sun Apr 17, 2016 1:20 pm
petematheson offline
Posts: 847
Joined: Sep 14, 2014
Location: Southampton, UK

Re: Messages app plugin

I'm constantly getting the 'Wait' prompt after a few messages at random times. Once it does it, the rest of the messages just queue up behind until I manually log on and click through all the wait messages. Any ideas how to stop this?
It's not the front window thing as I always click a few windows in front of messages just to be sure.

Posted on
Sun Apr 17, 2016 5:03 pm
Seeker offline
Posts: 440
Joined: Aug 05, 2013

Re: Messages app plugin

gazally wrote:
Seeker, I'm not really sure what your question is. When a message arrives the device state should go to New and stay there until you use the Mark as Read action. If additional messages arrive after the first one, they will wait for you to use Mark as Read before overwriting the first one.

The reason for "Mark as Read" is to make the message device states stick around so that you can use them in actions attached to a trigger without the risk that a new message will arrive and cause the device states to be overwritten before the actions have had a chance to read them. Because if a plugin or device used in one of your actions is busy when a trigger fires, Indigo will queue that action up as work to be done later and possibly do all kinds of other stuff before that action actually happens. This is mostly a concern with my Chatbot plugin, which could potentially be running some time-consuming Python script in response to the last message when the new one arrives.


My issue is that the messages sent by the plugin ARRIVE as read. They are never not read.

Posted on
Mon Apr 18, 2016 8:46 am
gazally offline
Posts: 27
Joined: Jan 18, 2016
Location: Bigfoot country

Re: Messages app plugin

Seeker, are you sure you don't have a Mark as Read action hiding in a trigger somewhere? I notice I omitted a debugLog message in that action, which I'll remedy, but that's the only place in the code where message status gets sent to Read.

Pete, I haven't encountered a Wait prompt. Is it coming from Messages or Indigo?

Who is online

Users browsing this forum: No registered users and 6 guests