PINE64
Python3 cli app to bridge SMS/MMS to matrix/riot.im - Printable Version

+- PINE64 (https://forum.pine64.org)
+-- Forum: PinePhone (https://forum.pine64.org/forumdisplay.php?fid=120)
+--- Forum: PinePhone Software (https://forum.pine64.org/forumdisplay.php?fid=121)
+--- Thread: Python3 cli app to bridge SMS/MMS to matrix/riot.im (/showthread.php?tid=9100)

Pages: 1 2


Python3 cli app to bridge SMS/MMS to matrix/riot.im - FutureBucket - 02-09-2020

quick edit: My script is almost done. SMS/MMS/Group chats are all bridged to matrix and I've been using it without issue for over a month now.
I just a couple things left to do and then I'll clean it up. Please give it a try!
https://gitlab.com/untidylamp/ofono-matrix-puppet


Original post:

I'm working on an app that will allow you to send/receive SMS and MMS messages from the web using Matrix/riot.im

here is the very first version with a really bad readme file. as of right now only SMSes work but I have the code for ofono to send/receive MMS. I just need to figure out how to send files to matrix and then put it in the script.




I'm not very good at programming but I'm learning. Hopefully someone else finds what I'm working on useful or maybe it will help them build a more reliable web texting app Smile




I'm also interested in running a VoIP server on my phone so that I can use a VoIP app on another device to send/receive calls from my cell number without forwarding calls to a VoIP provider. That way I'll just leave my little server PinePhone at home on all the time but be able to do everything a phone can from any other device with a data connection. I have no idea where to start with this so I'll just be forwarding calls to my VoIP provider for now.


RE: Python3 cli app to bridge SMS/MMS to matrix/riot.im - FutureBucket - 02-23-2020

I have the base done. Everything works but there are bugs and problems I'll need to clean up and fix. I also plan to add a couple more features like starting a chat from Matrix side. However, SMS/MMS/Group work in both directions.

https://gitlab.com/untidylamp/ofono-matrix-puppet



I still don't have my PinePhone so I cant test with that but I'd be happy to hear if this works for you/if you have any problems.


Cheers,


RE: Python3 cli app to bridge SMS/MMS to matrix/riot.im - MartijnBraam - 02-24-2020

I see you have some code to remove +1 from your number, this will break for anyone that's not in a country that has country code 1 like USA, for example it's +31 in NL. the proper way is using a phone number handleing library for this since the length of the prefix is variable.


RE: Python3 cli app to bridge SMS/MMS to matrix/riot.im - FutureBucket - 02-24-2020

(02-24-2020, 05:46 PM)MartijnBraam Wrote: I see you have some code to remove +1 from your number, this will break for anyone that's not in a country that has country code 1 like USA, for example it's +31 in NL. the proper way is using a phone number handleing library for this since the length of the prefix is variable.

Ah, good idea. I never even thought about looking for a phone number library. I was thinking about changing it to using the last 10 numbers but I like your idea better. Thank you!


Its just Telus here in Canada who is inconsistent. Incoming SMSes are 2505551234 but incoming MMSes are +12505551234. I just did a quick thing to remove +1 from MMSes only. Now that I have a pretty good base and I think my design is alright I'm going to go back though it and clean it up a bit

Edit:

https://pypi.org/project/phonenumbers/

This is awesome, its exactly what I need. I'll get this in there next!


RE: Python3 cli app to bridge SMS/MMS to matrix/riot.im - FutureBucket - 02-24-2020

(02-24-2020, 05:46 PM)MartijnBraam Wrote: I see you have some code to remove +1 from your number, this will break for anyone that's not in a country that has country code 1 like USA, for example it's +31 in NL. the proper way is using a phone number handleing library for this since the length of the prefix is variable.

Fixed. Thanks Again! I'm much happier with it now.


Still lots to do but I've fixed the number formatting.


RE: Python3 cli app to bridge SMS/MMS to matrix/riot.im - MartijnBraam - 02-25-2020

Yeah number formatting/handeling for phone numbers is deceptively easy. Even android breaks down if you have SIP accounts added which has an @ in the number.


RE: Python3 cli app to bridge SMS/MMS to matrix/riot.im - pacman99 - 12-07-2020

Your code is really useful, thank you for writing it. I ported it to work with purple-mm-sms allowing sms to be bridged on distros using phosh/ModemManager.
https://gitlab.com/pacman99/purple-matrix-puppet


RE: Python3 cli app to bridge SMS/MMS to matrix/riot.im - FutureBucket - 01-19-2021

(12-07-2020, 01:39 AM)pacman99 Wrote: Your code is really useful, thank you for writing it. I ported it to work with purple-mm-sms allowing sms to be bridged on distros using phosh/ModemManager.
https://gitlab.com/pacman99/purple-matrix-puppet

Hey, I saw that. I'm excited to see what you come up with!  If you need help or anything, let me know!

I actually took your idea of contacts and implemented it in mine Smile  

What you see on my gitlab account is all the programming I've done in my life (so be kind. haha). I'm sure there's lots of better ways to write some of the code I have there too but it works. I've been running my script on a nexus5/Ubuntu Touch for almost 2 years and had next to no problems. It's nice to leave it at home and get a data simcard out of country and still be able to text friends and family.


RE: Python3 cli app to bridge SMS/MMS to matrix/riot.im - pacman99 - 01-31-2021

(01-19-2021, 10:16 AM)FutureBucket Wrote: Hey, I saw that. I'm excited to see what you come up with!  If you need help or anything, let me know!

I actually took your idea of contacts and implemented it in mine Smile  

What you see on my gitlab account is all the programming I've done in my life (so be kind. haha). I'm sure there's lots of better ways to write some of the code I have there too but it works. I've been running my script on a nexus5/Ubuntu Touch for almost 2 years and had next to no problems. It's nice to leave it at home and get a data simcard out of country and still be able to text friends and family.

Ohh awesome! I'm glad some of my code was useful. Yeah my contacts code isn't amazing, but it works. And don't worry I'm not that great either, your code is pretty well written, probably better than some of my additions anyway.

I actually ran into this one issue with the script and I wonder if you have experienced it. I use systemd to manage it and whenever the phone resumes from suspend the matrix sync thread just hangs. Its really weird there are no log messages or anything but the sync thread just stops logging new syncs. So I can't send the bridge messages anymore. I think I've narrowed it down to the thread fails at any point when theres no wifi. But every network connection is under a try except block, so I'm not sure whats wrong.


RE: Python3 cli app to bridge SMS/MMS to matrix/riot.im - FutureBucket - 02-01-2021

(01-31-2021, 01:57 PM)pacman99 Wrote:
(01-19-2021, 10:16 AM)FutureBucket Wrote: Hey, I saw that. I'm excited to see what you come up with!  If you need help or anything, let me know!

I actually took your idea of contacts and implemented it in mine Smile  

What you see on my gitlab account is all the programming I've done in my life (so be kind. haha). I'm sure there's lots of better ways to write some of the code I have there too but it works. I've been running my script on a nexus5/Ubuntu Touch for almost 2 years and had next to no problems. It's nice to leave it at home and get a data simcard out of country and still be able to text friends and family.

Ohh awesome! I'm glad some of my code was useful. Yeah my contacts code isn't amazing, but it works. And don't worry I'm not that great either, your code is pretty well written, probably better than some of my additions anyway.

I actually ran into this one issue with the script and I wonder if you have experienced it. I use systemd to manage it and whenever the phone resumes from suspend the matrix sync thread just hangs. Its really weird there are no log messages or anything but the sync thread just stops logging new syncs. So I can't send the bridge messages anymore. I think I've narrowed it down to the thread fails at any point when theres no wifi. But every network connection is under a try except block, so I'm not sure whats wrong.

I'm sorry, I've never experienced the problem you're having. My use case is different. My script is running on a Nexus5 with Ubuntu Touch that I NEVER touch. It's plugged in 24/7 and stays at home. I use a second device (android) that has the elements app I use for texting. Also, I have a cron job that restarts UT every night around 3AM because UbuntuTouch, at least on the Nexus5, doesn't close their file connections to the MMSes. If you leave it on for weeks I'll have thousands of open file handles to deleted files.

On the other hand, I'm almost 100% sure that I don't handle the threads correctly. I don't think any errors or anything will show if one of the threads die, it just stop and not say anything, which sounds like what you're experiencing.  I would have a look at how I start the treads and maybe try and restart them if they fail? or figure out how to catch a failure?? I don't know how to do this.

I am working on something else that has threads too so maybe I'll read about it and see if I can figure it out.


Quick edit: actually, I think I know what your problem is. Did you apply this patch to matrix-python-sdk?

https://github.com/matrix-org/matrix-python-sdk/pull/303/commits/aa4071835a79b5a3dccfd366b01bd9d53ed0a62f

You can test this, make sure the script is running, disable wifi AND cell data. wait a couple minutes then enable data again. if the matrix sync doesn't work its because the sdk just wait forever for the original sync to complete. That patch will kill the failed connection after X seconds and start a new one.