mautrix / imessage

A Matrix-iMessage puppeting bridge
https://go.mau.fi/mautrix-imessage/
GNU Affero General Public License v3.0
348 stars 37 forks source link

Add a way to start new chats #126

Closed rothn closed 7 months ago

rothn commented 10 months ago

It would be wonderful to have an option to start new iMessage chats like I can with the WhatsApp bridge

trek-boldly-go commented 8 months ago

@rothn I have added this functionality because of the bluebubbles enhancements, but the bot command pm will probably work for the other modes of this bridge as well (although I haven't tested). Why don't you give one of the more recent artifacts a try and see if it works for you?

rothn commented 8 months ago

This does not appear to work for people who have not already messaged me: image

rothn commented 8 months ago

Logs:

2024-02-02T19:29:05-08:00 DBG Request completed as_user_id=@imessagebot:[nicholasroth.net](http://nicholasroth.net/) duration=172.507848 method=PUT req_body={"body":"Failed to start PM: failed to resolve identifier: user not found","msgtype":"m.notice"} req_id=63 response_length=59 response_mime=application/json status_code=200 url=https://matrix.nicholasroth.net/_matrix/client/v3/rooms/%<REDACTED>:nicholasroth.net/send/m.room.message/mautrix-go_1706930945419743000_20?user_id=%40imessagebot%3Anicholasroth.net

2024-02-02T19:29:24-08:00 DBG Starting handling of transaction content={"pdu":1} req_id=0 transaction_id=228963 ws_command=

2024-02-02T19:29:24-08:00 DBG Finished dispatching events from transaction req_id=0 transaction_id=228963 ws_command=

2024-02-02T19:29:24-08:00 DBG Sent response to transaction req_id=0 transaction_id=228963 ws_command=

2024-02-02T19:29:24-08:00 DBG Sent message checkpoint message_checkpoint={"event_id":"$OUajJITWLPxkGyA-ZhNmGNts3Td1kAuDT78Z9U094u4","event_type":"m.room.message","message_type":"m.text","reported_by":"BRIDGE","retry_num":0,"room_id":"!<REDACTED>:[nicholasroth.net](http://nicholasroth.net/)","status":"SUCCESS","step":"BRIDGE","timestamp":1706930964737}

2024-02-02T19:29:24-08:00 DBG Sent message checkpoint message_checkpoint={"event_id":"$OUajJITWLPxkGyA-ZhNmGNts3Td1kAuDT78Z9U094u4","event_type":"m.room.message","message_type":"m.text","reported_by":"BRIDGE","retry_num":0,"room_id":"!<REDACTED>:[nicholasroth.net](http://nicholasroth.net/)","status":"SUCCESS","step":"COMMAND","timestamp":1706930964737}

2024-02-02T19:29:24-08:00 DBG Received command event_id=$OUajJITWLPxkGyA-ZhNmGNts3Td1kAuDT78Z9U094u4 mx_command=pm room_id=!<REDACTED>:[nicholasroth.net](http://nicholasroth.net/) user_id=@nicholasroth:[nicholasroth.net](http://nicholasroth.net/)

2024-02-02T19:29:24-08:00 DBG Request completed as_user_id=@imessagebot:[nicholasroth.net](http://nicholasroth.net/) duration=155.886025 method=PUT req_body={"m.relates_to":{"event_id":"$OUajJITWLPxkGyA-ZhNmGNts3Td1kAuDT78Z9U094u4","rel_type":"m.reference"},"network":"","status":"SUCCESS"} req_id=64 response_length=59 response_mime=application/json status_code=200 url=https://matrix.nicholasroth.net/_matrix/client/v3/rooms/%<REDACTED>:nicholasroth.net/send/com.beeper.message_send_status/mautrix-go_1706930964742045000_21?user_id=%40imessagebot%3Anicholasroth.net

2024-02-02T19:29:24-08:00 DBG Starting handling of transaction content={"pdu":1} req_id=0 transaction_id=228966 ws_command=

2024-02-02T19:29:24-08:00 DBG Finished dispatching events from transaction req_id=0 transaction_id=228966 ws_command=

2024-02-02T19:29:24-08:00 DBG Sent response to transaction req_id=0 transaction_id=228966 ws_command=

2024-02-02T19:29:24-08:00 DBG Request completed as_user_id=@imessagebot:[nicholasroth.net](http://nicholasroth.net/) duration=217.915182 method=PUT req_body={"body":"Failed to start PM: failed to resolve identifier: user not found","msgtype":"m.notice"} req_id=65 response_length=59 response_mime=application/json status_code=200 url=https://matrix.nicholasroth.net/_matrix/client/v3/rooms/%<REDACTED>:nicholasroth.net/send/m.room.message/mautrix-go_1706930964752515000_22?user_id=%40imessagebot%3Anicholasroth.net

2024-02-02T19:29:24-08:00 DBG Starting handling of transaction content={"pdu":1} req_id=0 transaction_id=228967 ws_command=

2024-02-02T19:29:24-08:00 DBG Finished dispatching events from transaction req_id=0 transaction_id=228967 ws_command=

2024-02-02T19:29:24-08:00 DBG Sent response to transaction req_id=0 transaction_id=228967 ws_command=

2024-02-02T19:29:24-08:00 DBG Sent message checkpoint message_checkpoint={"event_id":"$cmYr8QS2WsNLZ75F7kbfaDC5n2DeIZm5r9RMu2V235I","event_type":"m.room.message","message_type":"m.notice","reported_by":"BRIDGE","retry_num":0,"room_id":"!<REDACTED>:[nicholasroth.net](http://nicholasroth.net/)","status":"SUCCESS","step":"BRIDGE","timestamp":1706930964977}
rothn commented 8 months ago

Thanks for looking into this @trek-boldly-go . I'm using this build: https://mau.dev/mautrix/imessage/-/jobs/43409

trek-boldly-go commented 8 months ago

I have a few other must do items for bluebubbles, but if I get that merged to the main branch at some point then I promise to look at the code to see if it can be done. You should probably redact the phone numbers you posted here though. Are you running apple-script or Barcelona?

rothn commented 8 months ago

AppleScript. Barcelona crashed and did not work (I believe there's a separate issue tracking that). Regarding phone numbers, I just checked again but could not find any. Thanks for taking a look when you can!

trek-boldly-go commented 7 months ago

Peeked at the code for this and I don't think there is a safe way to do this. Right now, the code looks up your input in the mac DB to see if there is already a chat that matches the number you provided. It would probably still work for numbers that you have already messaged with (even if they aren't in beeper yet) but messaging numbers that you have never messaged before might not work. For reference, here is what fails: https://github.com/mautrix/imessage/blob/25aaae37d11db8c77ef77693e84ae6ecc847e1f8/imessage/mac/messages.go#L469C1-L475C2

func (mac *macOSDatabase) ResolveIdentifier(identifier string) (guid string, err error) {
    err = mac.chatGUIDQuery.QueryRow("%;-;" + identifier).Scan(&guid)
    if errors.Is(err, sql.ErrNoRows) {
        return "", fmt.Errorf("user not found")
    }
    return
}

It could probably still be enhanced with the same logic I added to the BlueBubbles mode, to check for emails and clean up phone numbers with spaces, dashes, and parenthesis.

    var handle = address
    if !strings.Contains(address, "@") {
        handle = "+" + numericOnly(address)
    }

Allowing a number that has never been messaged before could be risky, and I don't know apple-script well enough to attempt it.

tulir commented 7 months ago

AppleScript doesn't allow creating chats

trek-boldly-go commented 7 months ago

Then there you have it. I'll go ahead and close this issue as it isn't possible with AppleScript and it is already supported with BlueBubbles.