A customized Telegram client and relay server that can receive HMS Push Notification on Huawei Devices. This client allows Huawei users to receive Telegram messages without keeping the client alive at the background, eliminating the possible message missing incidence due to the battery policy of EMUI/HarmonyOS.
- Obtain your own api_id for your application.
- Replace the corresponding information (APP_ID, APP_HASH, etc.) in TMessagesProj/src/main/java/org/telegram/hmsmsger/BuildVArs.java
- Replace the original package name org.telegram.hmsmsger with your customized one (This step is essential since the package name must be unique at next step)
- Register as a Huawei Developer, and create a new project then a new APP using your own package name in the AppConnect Console. Enable Push Kit and download the corresponding agconnect-service.json file to replace the dummy one under TMessagesProj/ directory. Make sure to add the given code inside the correct build.gradle files. For more detail of this step, please refer to the official tutorial of Huawei.
- Follow the official tutorial of Google Firebase to create APP and integrate Firebase into your APP. Remember to replace the dummy google-services.json under TMessagesProj/ directory with your own one and add the given code inside the correct build.gradle files.
- Use any approach you like to acquire the HMS PushToken of your Huawei Device. In this client I have implemented one possible approach in the ApplicationLoader.java file, named getToken(), FYR.
- Choose a proper build variant and then build the project and test it on your Huawei Device.
The relay server is written with Python, and some code are copied from hms-push-serverdemo-python. Its design rationale is receiving the incoming message via the MTProto API of Telegram then pushing the message to your Huawei Phone. Here I use Telethon to implement above operations.
In order to run the server, please follow these steps:
- Install Telethon and any required dependencies using your package management tools.
- Open telepy/tele.py replace [api_id, api_hash] (for Telegram) and [app_id, app_secret] (for HMS) with your own values. Make sure to run this program on a trusted server since the leakage of that information may incur the loss of your privacy and properties.
- Run the tele.py and log in with your Telegram account. Login is only required the first time you run the server program.
- Keep it running in the background via nohup/screen or any tools you like.
- Try if you can receive push notification on your Huawei Device! If not, you may check the output to see what happened.