Skip to content

Commit

Permalink
fixed small bug, which caused an database referential integrity const…
Browse files Browse the repository at this point in the history
…raint violation

reformatted code
  • Loading branch information
benkuly committed Dec 9, 2020
1 parent fea21bc commit 3b791f8
Show file tree
Hide file tree
Showing 54 changed files with 1,236 additions and 1,172 deletions.
49 changes: 41 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
![Docker Image CI](https://github.com/benkuly/matrix-sms-bridge/workflows/Docker%20Image%20CI/badge.svg)

# matrix-sms-bridge

This is a matrix bridge, which allows you to bridge matrix rooms to SMS with one telephone number only. It is build on top of [matrix-spring-boot-sdk](https://github.com/benkuly/matrix-spring-boot-sdk) and written in kotlin.
This is a matrix bridge, which allows you to bridge matrix rooms to SMS with one telephone number only. It is build on
top of [matrix-spring-boot-sdk](https://github.com/benkuly/matrix-spring-boot-sdk) and written in kotlin.

You need help? Ask your questions in [#matrix-sms-bridge:imbitbu.de](https://matrix.to/#/#matrix-sms-bridge:imbitbu.de)

Features:

* use with one outgoing telephone number only
* send SMS
* receive SMS
Expand All @@ -20,29 +23,46 @@ Features:
* modem (with [Gammu](https://github.com/gammu/gammu)) -> not actively maintained anymore

## User Guide

### Automated room creation
Create a room with you and `@smsBot:yourHomeServer.org` only. Now you can write `sms send --help` which gives you a help, how to use this command.

Example: `sms send -t 01749292923 "Hello World"` creates a new room with the telephone number and writes "Hello World" for you. If there already is a room with this telephone number, and you are participating, then "Hello World" will be sent to that room.
Create a room with you and `@smsBot:yourHomeServer.org` only. Now you can write `sms send --help` which gives you a
help, how to use this command.

Example: `sms send -t 01749292923 "Hello World"` creates a new room with the telephone number and writes "Hello World"
for you. If there already is a room with this telephone number, and you are participating, then "Hello World" will be
sent to that room.

### Invite telephone number to matrix room

The virtual matrix users, which represents SMS numbers, have the following pattern:

```text
@sms_49123456789:yourHomeServer.org
```

The number `49123456789` represents the international german telephone number `+49123456789`.

You can invite these users to every room, independently of the room members. So you can also invite more than one SMS number to rooms with more than one real matrix users.
You can invite these users to every room, independently of the room members. So you can also invite more than one SMS
number to rooms with more than one real matrix users.

### Write to telephone numbers
After a room invite the virtual matrix users automatically join the room and every message to this room will be sent as SMS to the telephone number. The SMS contains a token (e.g. "#3"), which can be used in the answer of the SMS to route it back to the matrix room.

After a room invite the virtual matrix users automatically join the room and every message to this room will be sent as
SMS to the telephone number. The SMS contains a token (e.g. "#3"), which can be used in the answer of the SMS to route
it back to the matrix room.

### What if the SMS user has no token?
The bridge can be configured to route all SMS without a valid token to a default matrix room. Note that you must invite `@smsbot:yourHomeServer` to this room.

The bridge can be configured to route all SMS without a valid token to a default matrix room. Note that you must
invite `@smsbot:yourHomeServer` to this room.

## Admin Guide

### Configure Application Service

The Application Service gets configured with a yaml-file:

```yaml
matrix:
bridge:
Expand Down Expand Up @@ -87,13 +107,16 @@ matrix:
```
### Configure HomeServer
Add this to your synapse `homeserver.yaml`:

```yaml
app_service_config_files:
- /path/to/sms-bridge-appservice.yaml
```

`sms-bridge-appservice.yaml` looks like:

```yaml
id: "SMS Bridge"
url: "http://url-to-sms-bridge:8080"
Expand All @@ -111,10 +134,15 @@ namespaces:
```

### Configure Provider
If you want your SMS gateway provider to be supported, look into the package [`provider`](./src/main/kotlin/net/folivo/matrix/bridge/sms/provider) to see how you can add your own provider to this bridge.

If you want your SMS gateway provider to be supported, look into the
package [`provider`](./src/main/kotlin/net/folivo/matrix/bridge/sms/provider) to see how you can add your own provider
to this bridge.

#### android-sms-gateway-server

You need to add some properties to the Application Service yaml-file:

```yaml
matrix:
bridge:
Expand All @@ -137,7 +165,9 @@ matrix:
```

#### Gammu

First you need to add some properties to the Application Service yaml-file:

```yaml
matrix:
bridge:
Expand All @@ -153,6 +183,7 @@ matrix:
```

Your `gammu-smsdrc` should look like this:

```text
[gammu]
Device = /dev/ttyModem
Expand All @@ -178,9 +209,11 @@ CheckBattery = 0
```

### Using Docker container

There are two types of docker-containers. One, that is bundled with Gammu and one without:

* Default: `docker pull folivonet/matrix-sms-bridge:latest`
* Containers bundled with gammu use tags with the suffix `-gammu`: `docker pull folivonet/matrix-sms-bridge:latest-gammu`
* Containers bundled with gammu use tags with the
suffix `-gammu`: `docker pull folivonet/matrix-sms-bridge:latest-gammu`

To see, how a docker setup of the bridge could look like, have a look at the [examples](./examples).
28 changes: 14 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ repositories {
}

group = "net.folivo"
version = "0.5.4"
version = "0.5.5"
java.sourceCompatibility = JavaVersion.VERSION_11

tasks.withType<org.springframework.boot.gradle.tasks.bundling.BootJar>() {
manifest {
attributes(
"Implementation-Title" to "matrix-sms-bridge",
"Implementation-Version" to project.version
"Implementation-Title" to "matrix-sms-bridge",
"Implementation-Version" to project.version
)
}
}
Expand Down Expand Up @@ -96,17 +96,17 @@ tasks.getByName<BootBuildImage>("bootBuildImage") {
tasks.register<Exec>("docker-gammu") {
group = "build"
commandLine(
"docker",
"build",
"--build-arg",
"JAR_FILE=./build/libs/*.jar",
"-t",
"folivonet/matrix-sms-bridge:latest-gammu",
"-t",
"folivonet/matrix-sms-bridge:${project.version}-gammu",
"-f",
"./src/main/docker/gammu/Dockerfile",
"."
"docker",
"build",
"--build-arg",
"JAR_FILE=./build/libs/*.jar",
"-t",
"folivonet/matrix-sms-bridge:latest-gammu",
"-t",
"folivonet/matrix-sms-bridge:${project.version}-gammu",
"-f",
"./src/main/docker/gammu/Dockerfile",
"."
)
dependsOn("bootJar")
}
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ object Versions {
const val kotlinRetry = "1.0.6" // https://github.com/michaelbull/kotlin-retry
const val kotest = "4.3.1" // https://github.com/kotest/kotest/releases
const val springBoot = "2.4.0" // https://spring.io/projects/spring-boot
const val springDependencyManagement = "1.0.10.RELEASE" // https://github.com/spring-gradle-plugins/dependency-management-plugin/releases
const val springDependencyManagement =
"1.0.10.RELEASE" // https://github.com/spring-gradle-plugins/dependency-management-plugin/releases
const val springMockk = "2.0.3" // https://github.com/Ninja-Squad/springmockk/releases
const val matrixSDK = "0.4.3" // https://github.com/benkuly/matrix-spring-boot-sdk/releases
const val clikt = "3.0.1" // https://github.com/ajalt/clikt/releases
Expand Down
4 changes: 2 additions & 2 deletions examples/android/synapse/homeserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ listeners:
x_forwarded: true

resources:
- names: [client, federation]
- names: [ client, federation ]
compress: false

# example additional_resources:
Expand Down Expand Up @@ -505,7 +505,7 @@ acme:
# Again, you may want to change this if you are forwarding connections
# through Apache/Nginx/etc.
#
bind_addresses: ['::', '0.0.0.0']
bind_addresses: [ '::', '0.0.0.0' ]

# How many days remaining on a certificate before it is renewed.
#
Expand Down
4 changes: 2 additions & 2 deletions examples/gammu/synapse/homeserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ listeners:
x_forwarded: true

resources:
- names: [client, federation]
- names: [ client, federation ]
compress: false

# example additional_resources:
Expand Down Expand Up @@ -505,7 +505,7 @@ acme:
# Again, you may want to change this if you are forwarding connections
# through Apache/Nginx/etc.
#
bind_addresses: ['::', '0.0.0.0']
bind_addresses: [ '::', '0.0.0.0' ]

# How many days remaining on a certificate before it is renewed.
#
Expand Down
74 changes: 37 additions & 37 deletions src/main/kotlin/net/folivo/matrix/bridge/sms/SmsBridgeProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ import org.springframework.boot.context.properties.ConstructorBinding
@ConfigurationProperties("matrix.bridge.sms")
@ConstructorBinding
data class SmsBridgeProperties(
val templates: SmsBridgeTemplateProperties = SmsBridgeTemplateProperties(),
val defaultRoomId: RoomId?,
val allowMappingWithoutToken: Boolean = true,
val singleModeEnabled: Boolean = false,
val defaultRegion: String,
val defaultTimeZone: String = "UTC"
val templates: SmsBridgeTemplateProperties = SmsBridgeTemplateProperties(),
val defaultRoomId: RoomId?,
val allowMappingWithoutToken: Boolean = true,
val singleModeEnabled: Boolean = false,
val defaultRegion: String,
val defaultTimeZone: String = "UTC"
) {
data class SmsBridgeTemplateProperties(
val outgoingMessage: String = "{sender} wrote:\n\n{body}",
val outgoingMessageFromBot: String = "{body}",//FIXME bad
val outgoingMessageToken: String = "\n\nTo answer to this message add this token to your message: {token}",
val answerInvalidTokenWithDefaultRoom: String? = null,
val answerInvalidTokenWithoutDefaultRoom: String? = "Your message did not contain any valid token. Nobody can and will read your message.",
val sendSmsError: String = "Could not send SMS: {error}",
val sendSmsIncompatibleMessage: String = "Only text messages can be send to this SMS user.",
val defaultRoomIncomingMessage: String = "{sender} wrote:\n\n{body}",
val defaultRoomIncomingMessageWithSingleMode: String = "A message from {sender} was send to room {roomAlias}. Someone should join the room. Otherwise nobody will read the message.\n\nType `sms invite {roomAlias}` in a bot room to get invited to the room.",
val botHelp: String = "To use this bot, type 'sms'",
val botTooManyMembers: String = "Only rooms with two members are allowed to write with this bot.",
val botSmsError: String = "There was an error while using sms command. Reason: {error}",
val botSmsSendInvalidTelephoneNumber: String = "The telephone number is invalid.",
val botSmsSendNewRoomMessage: String = "{sender} wrote:\n\n{body}",//FIXME bad
val botSmsSendNoticeDelayedMessage: String = "A message will be sent for you at {sendAfter}.",
val botSmsSendCreatedRoomAndSendMessage: String = "You were invited to a new created room and (if given) the message to the telephone number(s) {receiverNumbers} was (or will be) sent for you.",
val botSmsSendCreatedRoomAndSendNoMessage: String = "You were invited to a new created room.",
val botSmsSendSendMessage: String = "The message was (or will be) sent for you into an existing room with the telephone number(s) {receiverNumbers}.",
val botSmsSendTooManyRooms: String = "No message was (or will be) sent, because there was more then one room with this telephone number(s) {receiverNumbers}. You can force room creation with the -c option.",
val botSmsSendNoMessage: String = "There was no message content to send.",
val botSmsSendDisabledRoomCreation: String = "No message was sent to telephone number(s) {receiverNumbers}, because either the bot wasn't invited to the room with the telephone number or creation was disabled by your command.",
val botSmsSendSingleModeOnlyOneTelephoneNumberAllowed: String = "Single mode is allowed with one telephone number only.",
val botSmsSendSingleModeDisabled: String = "Single mode was disabled by your admin.",
val botSmsSendError: String = "There was an error while sending message to the telephone number(s) {receiverNumbers}. Reason: {error}",
val botSmsInviteSuccess: String = "{sender} was invited to {roomAlias}.",
val botSmsInviteError: String = "There was an error while invite {sender} to {roomAlias}. Reason: {error}",
val botSmsAbortSuccess: String = "The deferred sending of messages in this room were aborted.",
val botSmsAbortError: String = "There was an error running this command. Reason: {error}",
val providerSendError: String = "Could not send sms to {receiver} with your provider. We will try to resend it and will notify you as soon as it was successful. Reason: {error}",
val providerResendSuccess: String = "The resend was successful for all messages.",
val providerReceiveError: String = "Could not receive messages through your configured provider. If this message does not appear again in the next few minutes, then retrying the receiving was successful. Reason: {error}"
val outgoingMessage: String = "{sender} wrote:\n\n{body}",
val outgoingMessageFromBot: String = "{body}",//FIXME bad
val outgoingMessageToken: String = "\n\nTo answer to this message add this token to your message: {token}",
val answerInvalidTokenWithDefaultRoom: String? = null,
val answerInvalidTokenWithoutDefaultRoom: String? = "Your message did not contain any valid token. Nobody can and will read your message.",
val sendSmsError: String = "Could not send SMS: {error}",
val sendSmsIncompatibleMessage: String = "Only text messages can be send to this SMS user.",
val defaultRoomIncomingMessage: String = "{sender} wrote:\n\n{body}",
val defaultRoomIncomingMessageWithSingleMode: String = "A message from {sender} was send to room {roomAlias}. Someone should join the room. Otherwise nobody will read the message.\n\nType `sms invite {roomAlias}` in a bot room to get invited to the room.",
val botHelp: String = "To use this bot, type 'sms'",
val botTooManyMembers: String = "Only rooms with two members are allowed to write with this bot.",
val botSmsError: String = "There was an error while using sms command. Reason: {error}",
val botSmsSendInvalidTelephoneNumber: String = "The telephone number is invalid.",
val botSmsSendNewRoomMessage: String = "{sender} wrote:\n\n{body}",//FIXME bad
val botSmsSendNoticeDelayedMessage: String = "A message will be sent for you at {sendAfter}.",
val botSmsSendCreatedRoomAndSendMessage: String = "You were invited to a new created room and (if given) the message to the telephone number(s) {receiverNumbers} was (or will be) sent for you.",
val botSmsSendCreatedRoomAndSendNoMessage: String = "You were invited to a new created room.",
val botSmsSendSendMessage: String = "The message was (or will be) sent for you into an existing room with the telephone number(s) {receiverNumbers}.",
val botSmsSendTooManyRooms: String = "No message was (or will be) sent, because there was more then one room with this telephone number(s) {receiverNumbers}. You can force room creation with the -c option.",
val botSmsSendNoMessage: String = "There was no message content to send.",
val botSmsSendDisabledRoomCreation: String = "No message was sent to telephone number(s) {receiverNumbers}, because either the bot wasn't invited to the room with the telephone number or creation was disabled by your command.",
val botSmsSendSingleModeOnlyOneTelephoneNumberAllowed: String = "Single mode is allowed with one telephone number only.",
val botSmsSendSingleModeDisabled: String = "Single mode was disabled by your admin.",
val botSmsSendError: String = "There was an error while sending message to the telephone number(s) {receiverNumbers}. Reason: {error}",
val botSmsInviteSuccess: String = "{sender} was invited to {roomAlias}.",
val botSmsInviteError: String = "There was an error while invite {sender} to {roomAlias}. Reason: {error}",
val botSmsAbortSuccess: String = "The deferred sending of messages in this room were aborted.",
val botSmsAbortError: String = "There was an error running this command. Reason: {error}",
val providerSendError: String = "Could not send sms to {receiver} with your provider. We will try to resend it and will notify you as soon as it was successful. Reason: {error}",
val providerResendSuccess: String = "The resend was successful for all messages.",
val providerReceiveError: String = "Could not receive messages through your configured provider. If this message does not appear again in the next few minutes, then retrying the receiving was successful. Reason: {error}"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ import org.springframework.stereotype.Service

@Service
class SmsMatrixAppserviceRoomService(
roomService: MatrixRoomService,
helper: BotServiceHelper,
private val botProperties: MatrixBotProperties,
private val bridgeProperties: SmsBridgeProperties
roomService: MatrixRoomService,
helper: BotServiceHelper,
private val botProperties: MatrixBotProperties,
private val bridgeProperties: SmsBridgeProperties
) : DefaultAppserviceRoomService(roomService, helper) {

override suspend fun getCreateRoomParameter(roomAlias: RoomAliasId): CreateRoomParameter {
val invitedUser = UserId(roomAlias.localpart, botProperties.serverName)
return CreateRoomParameter(
visibility = PRIVATE,
powerLevelContentOverride = PowerLevelsEventContent(
invite = 0,
kick = 0,
events = mapOf("m.room.name" to 0, "m.room.topic" to 0),
users = mapOf(invitedUser to 100, botProperties.botUserId to 100)
),
invite = setOf(invitedUser)
visibility = PRIVATE,
powerLevelContentOverride = PowerLevelsEventContent(
invite = 0,
kick = 0,
events = mapOf("m.room.name" to 0, "m.room.topic" to 0),
users = mapOf(invitedUser to 100, botProperties.botUserId to 100)
),
invite = setOf(invitedUser)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import org.springframework.stereotype.Service

@Service
class SmsMatrixAppserviceUserService(
userService: MatrixUserService,
helper: BotServiceHelper,
private val botProperties: MatrixBotProperties
userService: MatrixUserService,
helper: BotServiceHelper,
private val botProperties: MatrixBotProperties
) : DefaultAppserviceUserService(userService, helper, botProperties) {

override suspend fun getRegisterUserParameter(userId: UserId): RegisterUserParameter {
Expand Down
Loading

0 comments on commit 3b791f8

Please sign in to comment.