Skip to content

Commit

Permalink
fixed #2
Browse files Browse the repository at this point in the history
bumped version
  • Loading branch information
benkuly committed Nov 26, 2020
1 parent 23baf41 commit ec75e4c
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repositories {
}

group = "net.folivo"
version = "0.5.2"
version = "0.5.3"
java.sourceCompatibility = JavaVersion.VERSION_11

tasks.withType<org.springframework.boot.gradle.tasks.bundling.BootJar>() {
Expand Down
2 changes: 1 addition & 1 deletion examples/android/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.3'
services:
matrix-sms-bridge:
image: folivonet/matrix-sms-bridge:latest
image: folivonet/matrix-sms-bridge:0.5.3
volumes:
- type: bind
source: ./config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ReceiveSmsService(
val roomIdFromAlias = roomService.getRoomAlias(roomAliasId)?.roomId
?: matrixClient.roomsApi.getRoomAlias(roomAliasId).roomId

messageService.sendRoomMessage(//FIXME test
messageService.sendRoomMessage(
MatrixMessage(roomIdFromAlias, cleanedBody, isNotice = false, asUserId = userId),
setOf(userId)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.folivo.matrix.bridge.sms.provider.android

import com.google.i18n.phonenumbers.NumberParseException
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.reactive.awaitFirstOrNull
import net.folivo.matrix.bridge.sms.SmsBridgeProperties
Expand Down Expand Up @@ -84,10 +85,22 @@ class AndroidSmsProvider(
response.messages
.sortedBy { it.id }
.fold(lastProcessed, { process, message ->
receiveSmsService.receiveSms(
message.body,
phoneNumberService.parseToInternationalNumber(message.sender)
)
try {
receiveSmsService.receiveSms(
message.body,
phoneNumberService.parseToInternationalNumber(message.sender)
)
} catch (error: NumberParseException) {
if (smsBridgeProperties.defaultRoomId != null)
matrixClient.roomsApi.sendRoomEvent(
smsBridgeProperties.defaultRoomId,
NoticeMessageEventContent(
smsBridgeProperties.templates.defaultRoomIncomingMessage
.replace("{sender}", message.sender)
.replace("{body}", message.body)
)
)
}
processedRepository.save(
process?.copy(lastProcessedId = message.id)
?: AndroidSmsProcessed(1, message.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ class AndroidSmsProviderLauncher(
return {
LOG.error("could not retrieve messages from android device or process them: ${reason.message}")
LOG.debug("detailed error", reason)
if (smsBridgeProperties.defaultRoomId != null)
matrixClient.roomsApi.sendRoomEvent(
smsBridgeProperties.defaultRoomId,
NoticeMessageEventContent(
smsBridgeProperties.templates.providerReceiveError
.replace("{error}", reason.message ?: "unknown")
)
)
try {
if (smsBridgeProperties.defaultRoomId != null)
matrixClient.roomsApi.sendRoomEvent(
smsBridgeProperties.defaultRoomId,
NoticeMessageEventContent(
smsBridgeProperties.templates.providerReceiveError
.replace("{error}", reason.message ?: "unknown")
)
)
} catch (error: Throwable) {
LOG.error("could not warn user in default room: ${error.message}")
}
ContinueRetrying
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,57 @@ private fun testBody(
db.select<AndroidSmsProcessed>().first().awaitFirstOrNull()
?.lastProcessedId.shouldBe(3)
}
describe("handle unparsable telephone numbers") {
beforeTest {
mockServerClient
.`when`(
HttpRequest.request()
.withMethod(HttpMethod.GET.name)
.withPath("/messages/in")
.withQueryStringParameter("after", "3"),
Times.exactly(1)
).respond(
HttpResponse.response()
.withBody(
"""
{
"nextBatch":"4",
"messages":[
{
"number":"123",
"body":"wtf",
"id":4
}
]
}
""".trimIndent(), MediaType.APPLICATION_JSON
)
)
}
it("should send to default room, when present") {
val defaultRoomId = RoomId("default", "server")
every { smsBridgeProperties.defaultRoomId }.returns(defaultRoomId)
every { smsBridgeProperties.templates.defaultRoomIncomingMessage }.returns("{sender} wrote {body}")
cut.getAndProcessNewMessages()
cut.getAndProcessNewMessages()
cut.getAndProcessNewMessages()
coVerify {
matrixClientMock.roomsApi.sendRoomEvent(defaultRoomId, match<NoticeMessageEventContent> {
println(it.body)
it.body == "123 wrote wtf"
}, any(), any(), any())
}
}
it("should ignore when not default room") {
every { smsBridgeProperties.defaultRoomId }.returns(null)
cut.getAndProcessNewMessages()
cut.getAndProcessNewMessages()
cut.getAndProcessNewMessages()
coVerify(exactly = 0) {
matrixClientMock.roomsApi.sendRoomEvent(any(), any(), any(), any(), any())
}
}
}
it("should handle exceptions while processing message") {
coEvery { receiveSmsServiceMock.receiveSms(any(), "+4917332222222") }
.throws(RuntimeException())
Expand Down

0 comments on commit ec75e4c

Please sign in to comment.