| Name | lusid JSON |
| Version |
1.0.10
JSON |
| download |
| home_page | None |
| Summary | Self-hosted iMessage client (Twilio with blue bubbles) |
| upload_time | 2024-09-04 16:59:48 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.8 |
| license | None |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Lusid
Self-hosted Python interface for iMessage (similar to Twilio) that supports both green and blue bubbles.
Think this is cool? Check out what we're building at [lsd.so](https://lsd.so)
**Important:** Before use, please ensure you are compliant with telecommunications laws in your area and in some cases your recipient's area, including quiet hours, express consent, and other spam prevention laws. Lusid includes support, by default, for users to opt out by texting 'STOP', which is required in many countries including the US.
## Requirements
* Mac running macOS 10.11 or later
* Python
* iPhone with SIM (optional, adds SMS/green bubble support)
## Installing
Use pip or whichever python package manager you're working with
```bash
$ pip install lusid
```
You'll need to allow your Terminal application (or whichever terminal emulator you're running) to have full disk access in order to view the `chat.db` file containing your iMessages as well as "Accessibility" permissions via the Security & Privacy settings on your Mac.
Additionally, you'll need to disable System Integrity Protection on your Mac by running this terminal command in recovery mode:
```bash
$ csrutil disable
```
**Please note:** System Integrity Protection prevents malware from accessing and altering system-level files, and disabling leaves your computer vulnerable to malicious code. We reccomend going through the below article and ensuring you understand the risks before disabling.
For additional information on how to disable System Integrity Protection, the risks associated, and how to re-enable it, refer to this [Apple Developer Article](https://developer.apple.com/documentation/security/disabling-and-enabling-system-integrity-protection).
## Quickstart
### Sending Messages
If you're just interested in sending a message, import the `send_message` function and voila
```python
from lusid import send_message
to = "123-456-7890"
body = "Yeehaw"
send_message(to, body)
```
### Reading Messages
If you're just interested in getting iMessage data
```python
from lusid import read_messages
print(read_messages())
```
If you're interested in not only received but all messages and only ones that were sent in the past 24 hours
```python
from datetime import datetime, timedelta
from lusid import read_messages
print(read_messages(
since_time=datetime.now() + timedelta(days=-1),
inbound_only=False,
))
```
### SMS Support
If you're interested in supporting SMS (green bubbles), follow these steps:
* Ensure your iPhone has an active SIM card and is updated to the latest iOS software.
* In Settings > Apple ID, sign into the same Apple ID used on your Mac running Lusid.
* In Settings > Apps > Messages > Text Message Forwarding, enable the Mac running Lusid.
SMS/MMS messages can now be sent by running Lusid normally, provided both your Mac and iPhone are powered on and connected to the internet. To ensure best performance, keep both devices connected to the same network.
## Example Usage
### Basic
If you're interested in something replying to received messages
1. Create a "client" to repeatedly read your inbox (the rest of this quickstart assumes you're writing to a file named `app.py` but feel free to replace that later on with whatever you named your to)
```python
# app.py
from lusid import create_simple_message_client
def start_client():
create_simple_message_client(
message_handler=lambda to, body: None,
)
if __name__ == "__main__":
start_client()
```
2. Define a function for handling messages:
```python
# Snippet
def handle_message(from_number, body):
print(f"Handling the message [{body}] from [{from_number}]")
return "Some funny autoreply here" # Or None to not reply at all
```
3. Next we're going to include the function we defined earlier
```diff
# app.py
from lusid import create_simple_message_client
+def handle_message(from_number, body):
+ print(f"Handling the message [{body}] from [{from_number}]")
+ return "Some funny autoreply here" # Or None to not reply at all
def start_client():
create_simple_message_client(
message_handler=lambda to, body: None,
)
if __name__ == "__main__":
start_client()
```
Then actually use it as our message handler
```diff
# app.py
from lusid import create_simple_message_client
def handle_message(from_number, body):
print(f"Handling the message [{body}] from [{from_number}]")
return "Some funny autoreply here" # Or None to not reply at all
def start_client():
create_simple_message_client(
- message_handler=lambda to, body: None,
+ message_handler=handle_message
)
if __name__ == "__main__":
start_client()
```
If you'd like to just copy/paste the resulting code
```python
# app.py
from lusid import create_simple_message_client
def handle_message(from_number, body):
print(f"Handling the message [{body}] from [{from_number}]")
return "Some funny autoreply here" # Or None to not reply at all
def start_client():
create_simple_message_client(
message_handler=handle_message
)
if __name__ == "__main__":
start_client()
```
4. Now your script is set up to automatically reply to every received message with "Some funny autoreply here"
```bash
$ python app.py
Handling the message [Hello word!] from [+11234567890]
```
### Complex
Suppose you wanted to be able to share cat facts with a specific friend while also having message interaction, here's how you can accomplish that. We'll be adding to the **Basic example** above
For this particular example we'll be using the python package `requests` to make a simple API request
```bash
$ pip install requests
```
In short, like how React components have lifecycle methods, the message client features a `handle_post_read` method that can be specified at instantiation.
```diff
# app.py
+import random
+from requests import get
from lusid import create_simple_message_client
def handle_message(from_number, body):
print(f"Handling the message [{body}] from [{from_number}]")
return "Some funny autoreply here" # Or None to not reply at all
+def handle_post_read(cls):
+ facts = get("https://cat-fact.herokuapp.com/facts").json()
+ fact = random.choice(facts)["text"]
+
+ print(f"Telling kevin that {fact}")
+
+ kevin = "123-456-7890"
+ cls.send_message(kevin, fact)
def start_client():
create_simple_message_client(
message_handler=handle_message,
+ handle_post_read=handle_post_read
)
if __name__ == "__main__":
start_client()
```
Or, if you'd like to just copy and paste
```python
# app.py
import random
from requests import get
from lusid import create_simple_message_client
def handle_message(from_number, body):
print(f"Handling the message [{body}] from [{from_number}]")
return "Some funny autoreply here" # Or None to not reply at all
def handle_post_read(cls):
facts = get("https://cat-fact.herokuapp.com/facts").json()
fact = random.choice(facts)["text"]
print(f"Telling kevin that {fact}")
kevin = "123-456-7890"
cls.send_message(kevin, fact)
def start_client():
create_simple_message_client(
message_handler=handle_message,
handle_post_read=handle_post_read
)
if __name__ == "__main__":
start_client()
```
**And here's what it looks like when run**
```bash
$ python app.py
Telling kevin that Cats are the most popular pet in the United States: There are 88 million pet cats and 74 million dogs.
Telling kevin that Most cats are lactose intolerant, and milk can cause painful stomach cramps and diarrhea. It's best to forego the milk and just give your cat the standard: clean, cool drinking water.
Telling kevin that Owning a cat can reduce the risk of stroke and heart attack by a third.
```
Raw data
{
"_id": null,
"home_page": null,
"name": "lusid",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Yev Barkalov <yev@lsd.so>",
"download_url": "https://files.pythonhosted.org/packages/f6/3d/4649c7d17908c6c41e2ad58a7e44d08ec0a90c2ddc9732ee9567712ef01b/lusid-1.0.10.tar.gz",
"platform": null,
"description": "# Lusid\n\nSelf-hosted Python interface for iMessage (similar to Twilio) that supports both green and blue bubbles. \n\nThink this is cool? Check out what we're building at [lsd.so](https://lsd.so)\n\n**Important:** Before use, please ensure you are compliant with telecommunications laws in your area and in some cases your recipient's area, including quiet hours, express consent, and other spam prevention laws. Lusid includes support, by default, for users to opt out by texting 'STOP', which is required in many countries including the US.\n\n## Requirements\n\n* Mac running macOS 10.11 or later\n* Python\n* iPhone with SIM (optional, adds SMS/green bubble support)\n\n## Installing\n\nUse pip or whichever python package manager you're working with\n\n```bash\n$ pip install lusid\n```\n\nYou'll need to allow your Terminal application (or whichever terminal emulator you're running) to have full disk access in order to view the `chat.db` file containing your iMessages as well as \"Accessibility\" permissions via the Security & Privacy settings on your Mac.\n\nAdditionally, you'll need to disable System Integrity Protection on your Mac by running this terminal command in recovery mode:\n\n```bash\n$ csrutil disable\n```\n\n**Please note:** System Integrity Protection prevents malware from accessing and altering system-level files, and disabling leaves your computer vulnerable to malicious code. We reccomend going through the below article and ensuring you understand the risks before disabling.\n\nFor additional information on how to disable System Integrity Protection, the risks associated, and how to re-enable it, refer to this [Apple Developer Article](https://developer.apple.com/documentation/security/disabling-and-enabling-system-integrity-protection).\n\n## Quickstart\n\n### Sending Messages\n\nIf you're just interested in sending a message, import the `send_message` function and voila\n\n```python\nfrom lusid import send_message\n\nto = \"123-456-7890\"\nbody = \"Yeehaw\"\n\nsend_message(to, body)\n```\n\n### Reading Messages\n\nIf you're just interested in getting iMessage data\n\n```python\nfrom lusid import read_messages\n\nprint(read_messages())\n```\n\nIf you're interested in not only received but all messages and only ones that were sent in the past 24 hours\n\n```python\nfrom datetime import datetime, timedelta\n\nfrom lusid import read_messages\n\nprint(read_messages(\n since_time=datetime.now() + timedelta(days=-1),\n inbound_only=False,\n))\n```\n\n### SMS Support\n\nIf you're interested in supporting SMS (green bubbles), follow these steps:\n\n* Ensure your iPhone has an active SIM card and is updated to the latest iOS software.\n* In Settings > Apple ID, sign into the same Apple ID used on your Mac running Lusid.\n* In Settings > Apps > Messages > Text Message Forwarding, enable the Mac running Lusid.\n\nSMS/MMS messages can now be sent by running Lusid normally, provided both your Mac and iPhone are powered on and connected to the internet. To ensure best performance, keep both devices connected to the same network.\n\n## Example Usage\n\n### Basic\n\nIf you're interested in something replying to received messages\n\n1. Create a \"client\" to repeatedly read your inbox (the rest of this quickstart assumes you're writing to a file named `app.py` but feel free to replace that later on with whatever you named your to)\n\n```python\n# app.py\n\nfrom lusid import create_simple_message_client\n\ndef start_client():\n create_simple_message_client(\n message_handler=lambda to, body: None,\n )\n\nif __name__ == \"__main__\":\n start_client()\n```\n\n2. Define a function for handling messages:\n\n```python\n# Snippet\n\ndef handle_message(from_number, body):\n print(f\"Handling the message [{body}] from [{from_number}]\")\n return \"Some funny autoreply here\" # Or None to not reply at all\n```\n\n3. Next we're going to include the function we defined earlier\n\n```diff\n# app.py\n\nfrom lusid import create_simple_message_client\n\n+def handle_message(from_number, body):\n+ print(f\"Handling the message [{body}] from [{from_number}]\")\n+ return \"Some funny autoreply here\" # Or None to not reply at all\n\ndef start_client():\n create_simple_message_client(\n message_handler=lambda to, body: None,\n )\n\nif __name__ == \"__main__\":\n start_client()\n```\n\nThen actually use it as our message handler\n\n```diff\n# app.py\n\nfrom lusid import create_simple_message_client\n\ndef handle_message(from_number, body):\n print(f\"Handling the message [{body}] from [{from_number}]\")\n return \"Some funny autoreply here\" # Or None to not reply at all\n\ndef start_client():\n create_simple_message_client(\n- message_handler=lambda to, body: None,\n+ message_handler=handle_message\n )\n\nif __name__ == \"__main__\":\n start_client()\n```\n\nIf you'd like to just copy/paste the resulting code\n\n```python\n# app.py\n\nfrom lusid import create_simple_message_client\n\ndef handle_message(from_number, body):\n print(f\"Handling the message [{body}] from [{from_number}]\")\n return \"Some funny autoreply here\" # Or None to not reply at all\n\ndef start_client():\n create_simple_message_client(\n message_handler=handle_message\n )\n\nif __name__ == \"__main__\":\n start_client()\n```\n\n4. Now your script is set up to automatically reply to every received message with \"Some funny autoreply here\"\n\n```bash\n$ python app.py\nHandling the message [Hello word!] from [+11234567890]\n```\n\n### Complex\n\nSuppose you wanted to be able to share cat facts with a specific friend while also having message interaction, here's how you can accomplish that. We'll be adding to the **Basic example** above\n\nFor this particular example we'll be using the python package `requests` to make a simple API request\n\n```bash\n$ pip install requests\n```\n\nIn short, like how React components have lifecycle methods, the message client features a `handle_post_read` method that can be specified at instantiation. \n\n```diff\n# app.py\n\n+import random\n+from requests import get\nfrom lusid import create_simple_message_client\n\ndef handle_message(from_number, body):\n print(f\"Handling the message [{body}] from [{from_number}]\")\n return \"Some funny autoreply here\" # Or None to not reply at all\n\n+def handle_post_read(cls):\n+ facts = get(\"https://cat-fact.herokuapp.com/facts\").json()\n+ fact = random.choice(facts)[\"text\"]\n+\n+ print(f\"Telling kevin that {fact}\")\n+\n+ kevin = \"123-456-7890\"\n+ cls.send_message(kevin, fact)\n\ndef start_client():\n create_simple_message_client(\n message_handler=handle_message,\n+ handle_post_read=handle_post_read\n )\n\nif __name__ == \"__main__\":\n start_client()\n```\n\nOr, if you'd like to just copy and paste\n\n```python\n# app.py\n\nimport random\nfrom requests import get\nfrom lusid import create_simple_message_client\n\ndef handle_message(from_number, body):\n print(f\"Handling the message [{body}] from [{from_number}]\")\n return \"Some funny autoreply here\" # Or None to not reply at all\n\ndef handle_post_read(cls):\n facts = get(\"https://cat-fact.herokuapp.com/facts\").json()\n fact = random.choice(facts)[\"text\"]\n\n print(f\"Telling kevin that {fact}\")\n\n kevin = \"123-456-7890\"\n cls.send_message(kevin, fact)\n\ndef start_client():\n create_simple_message_client(\n message_handler=handle_message,\n handle_post_read=handle_post_read\n )\n\nif __name__ == \"__main__\":\n start_client()\n```\n\n**And here's what it looks like when run**\n\n```bash\n$ python app.py\nTelling kevin that Cats are the most popular pet in the United States: There are 88 million pet cats and 74 million dogs.\nTelling kevin that Most cats are lactose intolerant, and milk can cause painful stomach cramps and diarrhea. It's best to forego the milk and just give your cat the standard: clean, cool drinking water.\nTelling kevin that Owning a cat can reduce the risk of stroke and heart attack by a third.\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Self-hosted iMessage client (Twilio with blue bubbles)",
"version": "1.0.10",
"project_urls": {
"Homepage": "https://github.com/yevbar/lusid",
"Issues": "https://github.com/yevbar/lusid/issues"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4a89f8f4fc4b22ec4c2895920119a997996d981033833028806b953e30ab1aee",
"md5": "f6a7ab63b55a247336619d58b49146f3",
"sha256": "8b8dab18e75497bb21c856b9ebb42bb79627d9e54cabeffe561ff3f9854981f0"
},
"downloads": -1,
"filename": "lusid-1.0.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f6a7ab63b55a247336619d58b49146f3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 18955,
"upload_time": "2024-09-04T16:59:46",
"upload_time_iso_8601": "2024-09-04T16:59:46.160704Z",
"url": "https://files.pythonhosted.org/packages/4a/89/f8f4fc4b22ec4c2895920119a997996d981033833028806b953e30ab1aee/lusid-1.0.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f63d4649c7d17908c6c41e2ad58a7e44d08ec0a90c2ddc9732ee9567712ef01b",
"md5": "140b31c5a8f49a7378cfb342e17281f9",
"sha256": "79707f9b573a8fe626ffbec80ce1ad81ce77d1a4b59ff93ea37fda57e1188844"
},
"downloads": -1,
"filename": "lusid-1.0.10.tar.gz",
"has_sig": false,
"md5_digest": "140b31c5a8f49a7378cfb342e17281f9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 16794,
"upload_time": "2024-09-04T16:59:48",
"upload_time_iso_8601": "2024-09-04T16:59:48.664461Z",
"url": "https://files.pythonhosted.org/packages/f6/3d/4649c7d17908c6c41e2ad58a7e44d08ec0a90c2ddc9732ee9567712ef01b/lusid-1.0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-04 16:59:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "yevbar",
"github_project": "lusid",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "lusid"
}