caronc / apprise

Apprise - Push Notifications that work with just about every platform!
https://hub.docker.com/r/caronc/apprise
BSD 2-Clause "Simplified" License
11.71k stars 410 forks source link

Added (Simple) Threema Gateway Support #993

Closed caronc closed 10 months ago

caronc commented 11 months ago

Description:

Related issue (if applicable): #986

Added Threema (Gateway) support.

This only supports the Simple Methods right now due to the size of the private key (it would make for one heck of a long Apprise URL :wink:. This doesn't rule e2e encryption down the road, but at this time this will be a good start.

You need to first set up an account with Threema which will grant you access to your Threema 8 character User ID (which starts with an asterix (*). e.g *THREEMA

Account Setup

Syntax

Valid syntax is as follows:

You can freely mix/match the variables as well:

Parameter Breakdown

Variable Required Description
gateway_id Yes Your Gateway ID (8 characters that usually start with a +. You may use ?from= (or gwid) as an alias to this variable. These usually start with an asterisk (*) such as *MYGWYID
secret Yes Your Threema API Secret associated with your account. You may use ?secret= as an alias to this variable.
target No Specfiy Threema UserID, Email Address, or Phone No. If no target is specified then your User ID is used instead. There is no limit to the number of targets you specify. You may use ?to= as an alias to this variable.

New Service Completion Status

Checklist

Testing

Anyone can help test this source code as follows:

# Create a virtual environment to work in as follows:
python3 -m venv apprise

# Change into our new directory
cd apprise

# Activate our virtual environment
source bin/activate

# Install the branch
pip install git+https://github.com/caronc/apprise.git@986-threema-gateway-support

# Test out the changes with the following command:
apprise -t "Test Title" -b "Test Message" \
  "threema://gateway_id@secret/"
codecov-commenter commented 11 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (7e87807) 99.51% compared to head (3025c28) 99.51%. Report is 1 commits behind head on master.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #993 +/- ## ======================================== Coverage 99.51% 99.51% ======================================== Files 124 125 +1 Lines 16635 16760 +125 Branches 3408 3434 +26 ======================================== + Hits 16554 16679 +125 Misses 70 70 Partials 11 11 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Flash1232 commented 11 months ago

Please let me know anytime if you need any assistance with integrating Gateway. :)

caronc commented 11 months ago

I wrote all of the code yesterday and forgot to git add it... -oops :eyes: ...

Just pushed it now for your review.

One thing i'd like to document is how to you can obtain your secret (for the simple mode); i don't see a means of generating it through the website/admin area.

Flash1232 commented 11 months ago

One thing i'd like to document is how to you can obtain your secret (for the simple mode); i don't see a means of generating it through the website/admin area.

We just reached out to you via E-Mail but the process can be broken down to a few steps:

Just pushed it now for your review.

We will gladly look into it as soon as we can spare some time, thank you in advance for your work!

caronc commented 11 months ago

@Flash1232 Thank you for this amazing review!! 🙏🙏🙏⭐

I am a bit slow addressing things these days; weekends and some evenings are all I got. But I will 100% address all of this soon!

Edit: @threema-eduard & @rugk I meant to also give you each credit here, but i'll leave it to both of you now as you were both incredibly helpful! thank you so much! :pray:

caronc commented 10 months ago

So i did the following:

Question: If a Gateway ID isn't a Threema ID, are Threema ID's still restricted to 8 characters as defined here?

caronc commented 10 months ago

@rugk

Also considering this may be implemented is threema:// the correct "protocol" to go with? (As it is likely hard or only with breaking changes, changeable?) Would e2e mode then be called threema-e2e://? Or shall we call it threema-basic:// already?

What will happen is that the url will become threema://credentails?mode=basic or mode=e2e. Depending on the content specified in the credentials area, we can automate/detect what you're attempting to do with the option of fixing the mode= anyway just to enforce (should detection choose something that wasn't intended)

threema-eduard commented 10 months ago

Dear @caronc

Thank you for updating your PR.

I retried with the latest changes and everything seems to be working now!

Question: If a Gateway ID isn't a Threema ID, are Threema ID's still restricted to 8 characters as defined here?

You potentially inferred this from https://github.com/caronc/apprise/pull/993#discussion_r1383440019, right? Sorry for not being clearer on this: Gateway IDs are Threema IDs in that they must be, otherwise no Threema client would be able to communicate with them. There is a special distinction: Gateway IDs are - strictly speaking - a subset of Threema IDs, but we will only assign the '*' at the first position to Gateway IDs (regular "user" Threema identities are alphanumeric without special chars). Any kind of Threema ID always consists of 8 characters (including Gateway IDs).

So i did the following:

  • user renamed to gateway_id
  • at least 1 target must be specified (Gateway ID != Threema ID)
  • dropped + in E.164 phone no
  • from added into payload
  • Threema Gateway references everywhere (vs just Threema)
  • Test cases improved allowing me to notice the to wasn't even being even processed correctly; now it is

Thank you so much!

And also thanks to @rugk for spotting some of the things I did not catch!