Home

Awesome

iMessage API

This is a simple API to interact with iMessages using a Flask server. It allows you to send messages, retrieve messages, and fetch recent contacts.

Prerequisites

Installation

  1. Clone this repository:
git clone https://github.com/danikhan632/iMessage-API.git
  1. Change to the directory:
cd iMessage-api
  1. Install the required packages:
pip install -r requirements.txt
  1. Download contacts from iCloud, click select all then export vCard. Rename output and move to this directory

alt text

  1. Enable full disk access on either Terminal or iTerm, whichever one you plan to run the server on.

alt text

  1. Now that you have renamed the iCloud contacts file to contacts.vcf run this to turn the contacts to json
python3 icloud_parser.py

Now rename ".env.template" to ".env"and set a password, your name, and port number for this to run off. Replace $user in DB_FILEPATH with your user account name.

PASSWORD=password
YOUR_NAME=your-name
PORT_NUMBER=5000
DB_FILEPATH=/Users/$user/Library/Messages/chat.db

Now to run to run the api server, run the following command

python3 server.py

iMessage API Docs

Endpoints

Send a message

POST /send

Send a message to a recipient.

Parameters

Example

curl -X POST "http://localhost:5000/send" \
  -H "api_key: <your-api-key>" \
  -H "Content-Type: application/json" \
  -d '{"recipient": "John Doe", "message": "Hello!"}'

Get messages

GET /messages

Retrieve a list of messages.

Parameters

curl "http://localhost:5000/messages?num_messages=5&sent=true&formatted=true" \
     -H "api_key: <your-api-key>"

Get most recent contacts

GET /recent_contacts

Retrieve a list of your most recent contacts.

Parameters

curl "http://localhost:5000/recent_contacts?num_contacts=5"