Skip to content

Commit

Permalink
Updated to current Spring Boot/Cloud and API
Browse files Browse the repository at this point in the history
  • Loading branch information
patbaumgartner committed Jan 8, 2023
1 parent 8539e97 commit d00ba7c
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 68 deletions.
Empty file added .springjavaformatconfig
Empty file.
1 change: 1 addition & 0 deletions HELP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Getting Started

### Reference Documentation

For further reference, please consider the following sections:

* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
Expand Down
105 changes: 66 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

# Lovebox Telegram Sender

The app allows sending messages via Telegram Bot to a single Lovebox instance. Text messages and photos with captions are supported. Other message types (e.g. Stickers, Audio, etc.) will lead to a default message.
The app allows sending messages via Telegram Bot to a single Lovebox instance. Text messages and photos with captions
are supported. Other message types (e.g. Stickers, Audio, etc.) will lead to a default message.

## Application Setup

To set up the app a few ids and values need to be retrieved on the Lovebox API. The following curl commands help to find the needed data on an existing account. Make sure you have set up your account via the Android or iOS app already.
To set up the app a few ids and values need to be retrieved on the Lovebox API. The following curl commands help to find
the needed data on an existing account. Make sure you have set up your account via the Android or iOS app already.

### Login with Password

Expand Down Expand Up @@ -42,9 +44,9 @@ curl --location --request POST 'https://app-api.loveboxlove.com/v1/graphql' \
--header 'content-type: application/json' \
--header 'host: app-api.loveboxlove.com' \
--data-raw '{
"operationName": null,
"operationName": "me",
"variables": {},
"query": "{\n me {\n _id\n firstName\n email\n boxes {\n _id\n color\n signature\n lovePercentage\n nickname\n notifications {\n disableUntil\n messageRead\n heartReceived\n __typename\n }\n admin {\n _id\n firstName\n email\n __typename\n }\n privacyPolicy\n pairingCode\n isConnected\n isAdmin\n hardware\n hasColor\n hasColorBackup\n connectionDate\n __typename\n }\n relations {\n _id\n name\n relationType\n picture\n color\n streak\n boxId\n loveGoal\n streakDeadline\n reminders {\n day\n meridiem\n number\n weekday\n time\n __typename\n }\n specialDates {\n _id\n name\n date\n dateType\n __typename\n }\n addresses {\n firstname\n lastname\n streetAddress\n zipCode\n city\n country\n state\n __typename\n }\n __typename\n }\n roles\n device {\n _id\n appVersion\n os\n __typename\n }\n profile\n reminder\n premium\n beta\n fcmToken\n language\n loveCoins\n __typename\n }\n}\n"
"query": "query me {\n me {\n _id\n _id\n createdAt\n firstName\n email\n beta\n settings {\n streak\n loveGoal\n reminders {\n day\n meridiem\n number\n weekday\n time\n __typename\n }\n specialDates {\n _id\n name\n date\n dateType\n __typename\n }\n notifications {\n generalMessageRead\n generalHeartReceived\n marketingOffers\n marketingOffersPush\n marketingOffersEmail\n __typename\n }\n __typename\n }\n addresses {\n firstname\n lastname\n streetAddress\n zipCode\n city\n country\n state\n __typename\n }\n boxes {\n _id\n color\n companyId\n signature\n picture\n nickname\n notifications {\n disableUntil\n messageRead\n heartReceived\n __typename\n }\n admin {\n _id\n firstName\n email\n __typename\n }\n privacyPolicy\n pairingCode\n isConnected\n isAdmin\n hardware\n hasColor\n connectionDate\n macAddress\n __typename\n }\n roles\n device {\n _id\n appVersion\n os\n __typename\n }\n profile\n reminder\n subscription {\n subscribed\n platform\n __typename\n }\n fcmToken\n language\n loveCoins\n lastSentMessage\n __typename\n }\n}\n"
}'
```

Expand All @@ -53,19 +55,45 @@ curl --location --request POST 'https://app-api.loveboxlove.com/v1/graphql' \
"data": {
"me": {
"_id": "42c61f261f399d0016350b7f",
"createdAt": "2021-12-24T19:27:34.542Z",
"firstName": "FirstName",
"email": "[email protected]",
"beta": 0,
"settings": {
"streak": 1,
"loveGoal": "TwiceAWeek",
"reminders": [
// ...
],
"specialDates": [
// ...
],
"notifications": {
"generalMessageRead": true,
"generalHeartReceived": true,
"marketingOffers": true,
"marketingOffersPush": true,
"marketingOffersEmail": true,
"__typename": "NotificationUserSettings"
},
"__typename": "Settings"
},
"addresses": [],
"boxes": [
{
// lovebox.box-id
"_id": "417a114e58e15a0214cf3612",
"color": "#8A64FF",
"companyId": "",
// lovebox.signature
"signature": "Signature",
"lovePercentage": 100,
"picture": null,
"nickname": "Nickname",
"notifications": {
// ...
"disableUntil": null,
"messageRead": true,
"heartReceived": true,
"__typename": "NotificationSettings"
},
"admin": {
"_id": "61c61ecc71010a00161789f2",
Expand All @@ -79,46 +107,28 @@ curl --location --request POST 'https://app-api.loveboxlove.com/v1/graphql' \
"isAdmin": false,
"hardware": "C2",
"hasColor": true,
"hasColorBackup": null,
"connectionDate": "2021-12-24T19:27:35.123Z",
"macAddress": "0CDC7ECF4FC4",
"__typename": "BoxSettings"
}
],
"relations": [
{
// lovebox.relation-id
"_id": "33c67a2127d7be09142f4326",
"name": "Nickname",
"relationType": "other",
"picture": null,
"color": "#3399FF",
"streak": 5,
// lovebox.box-id
"boxId": "417a114e58e15a0214cf3612",
"loveGoal": "Daily",
"streakDeadline": "2021-12-29T22:59:59.999Z",
"reminders": [],
"addresses": [],
"__typename": "Relation"
}
],
"roles": [],
"device": {
// lovebox.device-id
"_id": "42fab8322d8cec91",
"appVersion": "5.4.9",
"appVersion": "5.14.9",
"os": "android",
"__typename": "Device"
},
"profile": {
// ...
},
"reminder": null,
"premium": 0,
"beta": 0,
"reminder": 0,
"subscription": null,
"fcmToken": "edMLqMyMrpoGig9ZHdFdvH:AdA91bGGwx3UEuYTdhYOWDIdwlm2b23B9Jjin3MCGbi7CmUSpCVHFlorfryygi5QUBQMUVUiGsDJIE3RliENFmsuWrOnf4cBba-mNT5032NoKlo9AdPU5YhuCOR0KIdAbCokR42Hru",
"language": "en",
"loveCoins": 10,
"lastSentMessage": "2023-01-01T17:55:34.890Z",
"__typename": "User"
}
}
Expand All @@ -127,13 +137,16 @@ curl --location --request POST 'https://app-api.loveboxlove.com/v1/graphql' \

### Setting up a Telegram Bot

To create a chatbot on Telegram, you need to contact the [@BotFather](https://telegram.me/BotFather), which is a bot used to create other bots.
To create a chatbot on Telegram, you need to contact the [@BotFather](https://telegram.me/BotFather), which is a bot
used to create other bots.

The command you need is `/newbot` which leads to the next steps to create your bot. Follow the instructions and get the bot `username`, and `token`.
The command you need is `/newbot` which leads to the next steps to create your bot. Follow the instructions and get the
bot `username`, and `token`.

### Adjusting SpringBoot's application.properties

Running the app from the source needs adjustments according to your settings. Adjusting the `application.properties` in the sources or passing them as Java options or CLI arguments to the app.
Running the app from the source needs adjustments according to your settings. Adjusting the `application.properties` in
the sources or passing them as Java options or CLI arguments to the app.

```properties
# Lovebox Login
Expand All @@ -143,15 +156,16 @@ lovebox.password=mySecret
# Lovebox Setting
lovebox.signature=Signature
lovebox.device-id=42fab8322d8cec91
lovebox.relation-id=33c67a2127d7be09142f4326
lovebox.box-id=417a114e58e15a0214cf3612
# Telegram Bot Settings
bot.username=Lovebox_bot
bot.token=4072971853:ABEojZ42uNA6YYn_c7DF8RH0UOorqXuveSQ
```

### Setting Environment Variables e.g. for Docker
The following snippet can be passed as `.env` and read by the `docker-compose.yml` or used to be passed directly to the `docker run` command.

The following snippet can be passed as `.env` and read by the `docker-compose.yml` or used to be passed directly to
the `docker run` command.

```bash
# Lovebox Login
Expand Down Expand Up @@ -194,20 +208,27 @@ mvn spring-boot:build-image \

### Fixing Known Issues with Missing Fonts

Since the app uses fonts, we need to make sure that fonts are part of the docker container. The containers produced above throw an exception when using them `java.lang.NullPointerException: Cannot load from short array because "sun.awt.FontConfiguration.head" is null`
Since the app uses fonts, we need to make sure that fonts are part of the docker container. The containers produced
above throw an exception when using
them `java.lang.NullPointerException: Cannot load from short array because "sun.awt.FontConfiguration.head" is null`

[Andreas Ahlensdorf](https://github.com/aahlenst) describes nicely the font problem in his blog
post [Prerequisites for Font [Support in AdoptOpenJDK](https://blog.adoptopenjdk.net/2021/01/prerequisites-for-font-support-in-adoptopenjdk/).
post [Prerequisites for
Font [Support in AdoptOpenJDK](https://blog.adoptopenjdk.net/2021/01/prerequisites-for-font-support-in-adoptopenjdk/).

After more research, it seems that the only solution to add fonts to the build pack base image is to create an OCI run image by extending the base one. See the `Dockerfile.`base-cnb` file and how a patch with the additional font packages might look like.
After more research, it seems that the only solution to add fonts to the build pack base image is to create an OCI run
image by extending the base one. See the `Dockerfile.`base-cnb` file and how a patch with the additional font packages
might look like.

Build the `runImage` locally with the following command.

```bash
docker build --no-cache -f Dockerfile.base-cnb -t patbaumgartner/run:base-cnb .
```

Since we run the pull policy in the `mvn spring-boot:build-image` command with IF_NOT_PRESENT, we need to make sure that the newest version of the builder is locally available. Finally, pass to the `spring-boot-maven-plugin` the `runImage` to build the docker container containing the fonts.
Since we run the pull policy in the `mvn spring-boot:build-image` command with IF_NOT_PRESENT, we need to make sure that
the newest version of the builder is locally available. Finally, pass to the `spring-boot-maven-plugin` the `runImage`
to build the docker container containing the fonts.

```bash
mvn spring-boot:build-image \
Expand All @@ -220,4 +241,10 @@ mvn spring-boot:build-image \

## Credits

Reverse engineering (unpinning certificates) was done with [APKLab](https://github.com/APKLab/APKLab) and the [Lovebox APK](https://www.apkmonk.com/app/love.lovebox.loveboxapp/) provided by [apkmonk](https://www.apkmonk.com). Postman was used to capture the REST calls from the mobile app. The article [Capturing Http Requests](https://learning.postman.com/docs/sending-requests/capturing-request-data/capturing-http-requests/) covers everything needed. After a Postman update, [new certs](https://learning.postman.com/docs/sending-requests/capturing-request-data/capturing-http-requests/#troubleshooting-certificate-issues)](https://learning.postman.com/docs/sending-requests/capturing-request-data/capturing-http-requests/#troubleshooting-certificate-issues) need to be installed.
Reverse engineering (unpinning certificates) was done with [APKLab](https://github.com/APKLab/APKLab) and
the [Lovebox APK](https://www.apkmonk.com/app/love.lovebox.loveboxapp/) provided by [apkmonk](https://www.apkmonk.com).
Postman was used to capture the REST calls from the mobile app. The
article [Capturing Http Requests](https://learning.postman.com/docs/sending-requests/capturing-request-data/capturing-http-requests/)
covers everything needed. After a Postman
update, [new certs](https://learning.postman.com/docs/sending-requests/capturing-request-data/capturing-http-requests/#troubleshooting-certificate-issues)](https://learning.postman.com/docs/sending-requests/capturing-request-data/capturing-http-requests/#troubleshooting-certificate-issues)
need to be installed.
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-RC2</version>
<relativePath /> <!-- lookup parent from repository -->
<version>3.0.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.patbaumgartner</groupId>
Expand All @@ -19,14 +19,14 @@

<properties>
<!-- Providing properties for CI build -->
<CI_REGISTRY />
<CI_REGISTRY_USER />
<CI_REGISTRY_PASSWORD />
<CI_REGISTRY/>
<CI_REGISTRY_USER/>
<CI_REGISTRY_PASSWORD/>
<!-- Project properties for dependency management -->
<emoji4j.version>6.0</emoji4j.version>
<imgscalr.version>4.2</imgscalr.version>
<java.version>17</java.version>
<spring-cloud.version>2022.0.0-RC3</spring-cloud.version>
<spring-cloud.version>2022.0.0</spring-cloud.version>
<telegrambots-spring-boot-starter.version>6.4.0</telegrambots-spring-boot-starter.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ public class LoveboxRestClientProperties {
private String boxId;
/* Signature of message sender */
private String signature;
/* Recipient relation id */
private String relationId;

}
Loading

0 comments on commit d00ba7c

Please sign in to comment.