Hacker News new | ask | show | jobs
by mwlp 2210 days ago
I've been working on a new version of [my iMessage bot](https://github.com/inculi/Sue) recently. Previously it was using Applescript handlers on Sierra, now sqlite calls to iMessage's chat.db (I have to give credit to another bot, [Jared](https://github.com/ZekeSnider/Jared) for help in this area).

I get latest messages with:

```

SELECT handle.id, handle.person_centric_id, message.cache_has_attachments, message.text, message.ROWID, message.cache_roomnames, message.is_from_me, message.date/1000000000 + strftime("%s", "2001-01-01") AS utc_date FROM message INNER JOIN handle ON message.handle_id = handle.ROWID WHERE message.ROWID > #{rowid};

```

and their attachments with:

```

SELECT attachment.ROWID AS a_id, message_attachment_join.message_id AS m_id, attachment.filename, attachment.mime_type, attachment.total_bytes FROM attachment INNER JOIN message_attachment_join ON attachment.ROWID == message_attachment_join.attachment_id WHERE message_attachment_join.message_id >= #{rowid};

```

where rowid is the max rowid from the previous search, and attachments with null mime_types get ignored (YouTube previews, etc). Sending through Applescript still.

1 comments

Nice job. I'll take a look at your project and see if I can contrib