diff --git a/.gitignore b/.gitignore index a375f85..9859bc4 100644 --- a/.gitignore +++ b/.gitignore @@ -19,19 +19,8 @@ project/plugins/project/ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/dictionaries -.idea/**/shelf - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml +# Idea stuff +.idea/ # Gradle .idea/**/gradle.xml @@ -67,3 +56,81 @@ fabric.properties # Editor-based Rest Client .idea/httpRequests +### SBT template +# Simple Build Tool +# http://www.scala-sbt.org/release/docs/Getting-Started/Directories.html#configuring-version-control + +dist/* +target/ +lib_managed/ +src_managed/ +project/boot/ +project/plugins/project/ +.history +.cache +.lib/ +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests +### Scala template +*.class +*.log + diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index 92e9122..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 15a15b2..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/hydra.xml b/.idea/hydra.xml deleted file mode 100644 index 66eeb9a..0000000 --- a/.idea/hydra.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/modules/telegram-bot.iml b/.idea/modules/telegram-bot.iml deleted file mode 100644 index 6794500..0000000 --- a/.idea/modules/telegram-bot.iml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules/telegram-bot1.iml b/.idea/modules/telegram-bot1.iml deleted file mode 100644 index 5a235b4..0000000 --- a/.idea/modules/telegram-bot1.iml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/build.sbt b/build.sbt index f7aec26..8422276 100644 --- a/build.sbt +++ b/build.sbt @@ -25,3 +25,4 @@ lazy val `telegram-bot` = (project in file("telegram-bot")) circeAkkaHttp ) ) + .enablePlugins(DockerPlugin) diff --git a/keys/telegram-bot.key b/keys/telegram-bot.key new file mode 100644 index 0000000..6d505fa --- /dev/null +++ b/keys/telegram-bot.key @@ -0,0 +1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UiiUKtkt0XcUAqXaKKWF+R18e3nfWdT0swGcIAEg7bopvoRv9qE4Xwo +1oayWdZbhwKBgC5KlqNo4Q/WEL2b8I+y6HWnICpulk5bffZhAxmh7kynJO1FkmIg +IWIhbk9eHWlDA6HScYU4Phpv55Ko4QuqD309kyf/QmDhGONHSUjZ5MPgdy3wT5L/ +aiql1WT8YxnWZ0iMoofpyQDqEwwInmgQRedogIalfIvMrAlmXjiC8iAjAoGABBFo +Et/n+xlNlqAD9AU2qnjT7FRKPnMz5s/1f/ge+Ee1TwRLfbYPluaIyD8Zergknyrv +/Sap/eDAL6zT8KjHw/kHHwKdOfULmIiEfbXUVs2bj5vHzZVmxPoJhv1UW0RpVByg +wZvJ34EjQUaNegdrqj9CrEl8yQROu2pNmzH2p0cCgYBdJfGrPQ2MS4QEVOYKTULE +8fxfC6NmJG9f9HeKLPnlIMu8svhwCiEHWP+7vZG0gszh3m9IWVOh5YNwFu7Fp9m6 +3Ht1aEGrZM0ypD5jHLIaSOxOJRMVvT+O1yH8GBsNLxXstsfkIFSE4vMXbzeUo2Rm +5pAqJlj0tVH19/TlcuWbFQ== +-----END PRIVATE KEY----- diff --git a/keys/telegram-bot.p12 b/keys/telegram-bot.p12 new file mode 100644 index 0000000..8147227 Binary files /dev/null and b/keys/telegram-bot.p12 differ diff --git a/keys/telegram-bot.pem b/keys/telegram-bot.pem new file mode 100644 index 0000000..0fe289b --- /dev/null +++ b/keys/telegram-bot.pem @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDcTCCAlmgAwIBAgIJAKLMfxW4KRHuMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNV +BAYTAkNaMQ8wDQYDVQQHDAZQcmFndWUxGjAYBgNVBAoMEVBhdmVsIEthY2hhbG91 +c2tpMRMwEQYDVQQDDAp4ZXBwYWthLmV1MB4XDTE4MDUxMTE4MjEzOVoXDTI4MDUw +ODE4MjEzOVowTzELMAkGA1UEBhMCQ1oxDzANBgNVBAcMBlByYWd1ZTEaMBgGA1UE +CgwRUGF2ZWwgS2FjaGFsb3Vza2kxEzARBgNVBAMMCnhlcHBha2EuZXUwggEiMA0G +CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDWwewslKtWJ7yeYrxDuoh5PS7y5/C/ +0NT6tsAAsh3ZVCqdeNvYj56n8jVob/jJ9EYMqKj7dXLAMopDhtuwdDN/KhW9QVkK +zATE1wNxuV3aBVUTJuHHadUYQa7pVevvssAIa1XQ6NvU0pkwdDApylOj1TkA9MFl +ZWHWlF0dgrVyGjFxDoWdjm2aLCdRpZCr0giTOfZ5E+OJNALTHcuJO+PRKdEreO1Y +VAlT2Sk26f8/iG63C2/t7xWTyJKOjFPxwq3+dkNfJ1AXZ4I7aFDgP7BKogvooYuC +BItqog+IRUOoK9Yj24KCUxD+gaI5+tv0j1ov5d0ZAqqaiSql96s2/jyZAgMBAAGj +UDBOMB0GA1UdDgQWBBRkOXFj0c0jNdM1nJMRGr0EvfeMuTAfBgNVHSMEGDAWgBRk +OXFj0c0jNdM1nJMRGr0EvfeMuTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUA +A4IBAQBtXUOfnKdp1GY5gATTrPdr2s7FyiJvVfx/yeNNNR8ZnZcLjBMulEvXsfNi +AL1cEctnSDyT5z2el75nTdAgTFcBZQLsVk9/4ZwBRnfunFqfU5e5X9X9z//yt4Gy +Zq9BrMddQE+qwnOclcTDCc0GnyqKbaPiyYFcaXKhdrsflvoJI9tyLwPgjfXADLDF +JtjC0gGdbgefDweBUMTF0cpZED9q/J2fKXHurub+3QySvUOvphVFP4dBz2WhdoTe +v3lkEVp3I/IUv9qegO0B0o6X+Nnml4/b7HV1PArNceWOA6f57fSL2m6eN6xs4ULJ +kfUMloAr25yvmN/tPwm+8Op5ovot +-----END CERTIFICATE----- diff --git a/project/plugins.sbt b/project/plugins.sbt index 652a3b9..cc632f7 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1 +1,2 @@ addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6") +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.21") \ No newline at end of file diff --git a/telegram-bot/src/main/resources/application.conf b/telegram-bot/src/main/resources/application.conf new file mode 100644 index 0000000..426474b --- /dev/null +++ b/telegram-bot/src/main/resources/application.conf @@ -0,0 +1,18 @@ +akka { + loglevel = "DEBUG" + + extensions = [akka.persistence.Persistence] + + persistence { + journal { + plugin = "akka.persistence.journal.leveldb" + auto-start-journals = ["akka.persistence.journal.leveldb"] + leveldb.dir = "journal-check-delivery" + } + + snapshot-store { + plugin = "akka.persistence.snapshot-store.local" + auto-start-snapshot-stores = ["akka.persistence.snapshot-store.local"] + } + } +} diff --git a/telegram-bot/src/main/resources/logback.xml b/telegram-bot/src/main/resources/logback.xml new file mode 100644 index 0000000..ab73bdc --- /dev/null +++ b/telegram-bot/src/main/resources/logback.xml @@ -0,0 +1,11 @@ + + + + %date [%level] %logger: %message%n%xException + + + + + + + diff --git a/telegram-bot/src/main/resources/telegram-bot.p12 b/telegram-bot/src/main/resources/telegram-bot.p12 new file mode 100644 index 0000000..8147227 Binary files /dev/null and b/telegram-bot/src/main/resources/telegram-bot.p12 differ diff --git a/telegram-bot/src/main/resources/telegram-bot.pem b/telegram-bot/src/main/resources/telegram-bot.pem new file mode 100644 index 0000000..0fe289b --- /dev/null +++ b/telegram-bot/src/main/resources/telegram-bot.pem @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDcTCCAlmgAwIBAgIJAKLMfxW4KRHuMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNV +BAYTAkNaMQ8wDQYDVQQHDAZQcmFndWUxGjAYBgNVBAoMEVBhdmVsIEthY2hhbG91 +c2tpMRMwEQYDVQQDDAp4ZXBwYWthLmV1MB4XDTE4MDUxMTE4MjEzOVoXDTI4MDUw +ODE4MjEzOVowTzELMAkGA1UEBhMCQ1oxDzANBgNVBAcMBlByYWd1ZTEaMBgGA1UE +CgwRUGF2ZWwgS2FjaGFsb3Vza2kxEzARBgNVBAMMCnhlcHBha2EuZXUwggEiMA0G +CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDWwewslKtWJ7yeYrxDuoh5PS7y5/C/ +0NT6tsAAsh3ZVCqdeNvYj56n8jVob/jJ9EYMqKj7dXLAMopDhtuwdDN/KhW9QVkK +zATE1wNxuV3aBVUTJuHHadUYQa7pVevvssAIa1XQ6NvU0pkwdDApylOj1TkA9MFl +ZWHWlF0dgrVyGjFxDoWdjm2aLCdRpZCr0giTOfZ5E+OJNALTHcuJO+PRKdEreO1Y +VAlT2Sk26f8/iG63C2/t7xWTyJKOjFPxwq3+dkNfJ1AXZ4I7aFDgP7BKogvooYuC +BItqog+IRUOoK9Yj24KCUxD+gaI5+tv0j1ov5d0ZAqqaiSql96s2/jyZAgMBAAGj +UDBOMB0GA1UdDgQWBBRkOXFj0c0jNdM1nJMRGr0EvfeMuTAfBgNVHSMEGDAWgBRk +OXFj0c0jNdM1nJMRGr0EvfeMuTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUA +A4IBAQBtXUOfnKdp1GY5gATTrPdr2s7FyiJvVfx/yeNNNR8ZnZcLjBMulEvXsfNi +AL1cEctnSDyT5z2el75nTdAgTFcBZQLsVk9/4ZwBRnfunFqfU5e5X9X9z//yt4Gy +Zq9BrMddQE+qwnOclcTDCc0GnyqKbaPiyYFcaXKhdrsflvoJI9tyLwPgjfXADLDF +JtjC0gGdbgefDweBUMTF0cpZED9q/J2fKXHurub+3QySvUOvphVFP4dBz2WhdoTe +v3lkEVp3I/IUv9qegO0B0o6X+Nnml4/b7HV1PArNceWOA6f57fSL2m6eN6xs4ULJ +kfUMloAr25yvmN/tPwm+8Op5ovot +-----END CERTIFICATE----- diff --git a/telegram-bot/src/main/scala/eu/xeppaka/bot/Main.scala b/telegram-bot/src/main/scala/eu/xeppaka/bot/Main.scala index 52a0e98..142f535 100644 --- a/telegram-bot/src/main/scala/eu/xeppaka/bot/Main.scala +++ b/telegram-bot/src/main/scala/eu/xeppaka/bot/Main.scala @@ -15,9 +15,15 @@ import scala.io.StdIn object Main { def main(args: Array[String]): Unit = { - //val botId = "570855144:AAEv7b817cuq2JJI9f2kG5B9G3zW1x-btz4" // useless bot - val botId = "693134480:AAE8JRXA6j1mkOKTaxapP6A-E4LPHRuiIf8" // delivery bot - val botBehavior = Behaviors.supervise(TelegramBot.behavior(botId, "0.0.0.0", 88)).onFailure(SupervisorStrategy.restart) + val isProduction = System.getProperty("isProduction", "false").toBoolean + + val (botId, localPort, hookPort) = if (isProduction) { + ("693134480:AAE8JRXA6j1mkOKTaxapP6A-E4LPHRuiIf8", 88, 88) // delivery bot + } else { + ("570855144:AAEv7b817cuq2JJI9f2kG5B9G3zW1x-btz4", 8443, 8443) // useless bot + } + + val botBehavior = Behaviors.supervise(TelegramBot.behavior(botId, "0.0.0.0", localPort, hookPort)).onFailure(SupervisorStrategy.restart) val telegramBot = ActorSystem(botBehavior, "telegram-bot") implicit val actorSystem: actor.ActorSystem = telegramBot.toUntyped implicit val executionContext: ExecutionContextExecutor = telegramBot.dispatchers.lookup(DispatcherSelector.default()) diff --git a/telegram-bot/src/main/scala/eu/xeppaka/bot/TelegramBot.scala b/telegram-bot/src/main/scala/eu/xeppaka/bot/TelegramBot.scala index 99a0c2b..94a76b3 100644 --- a/telegram-bot/src/main/scala/eu/xeppaka/bot/TelegramBot.scala +++ b/telegram-bot/src/main/scala/eu/xeppaka/bot/TelegramBot.scala @@ -34,7 +34,7 @@ object TelegramBot { case object GetBotInfo case object GetWebhookInfo - def behavior(botId: String, interface: String, port: Int): Behavior[Command] = Behaviors.setup[Command] { ctx => + def behavior(botId: String, interface: String, localPort: Int, hookPort: Int): Behavior[Command] = Behaviors.setup[Command] { ctx => ctx.log.info("action=start_bot") implicit val untypedSystem: ActorSystem = ctx.system.toUntyped @@ -44,7 +44,7 @@ object TelegramBot { val botUri = BotUri(botId) val http: HttpExt = Http() val hookId = UUID.randomUUID().toString - val webhookUri = Uri(s"https://xeppaka.eu:88/$hookId") + val webhookUri = Uri(s"https://xeppaka.eu:$hookPort/$hookId") val httpsContext = createHttpsConnectionContext val stashBuffer = StashBuffer[Command](10) val dialogManager = ctx.spawnAnonymous(Behaviors.supervise(DialogManager.behavior(botUri)).onFailure(SupervisorStrategy.restart)) @@ -54,10 +54,10 @@ object TelegramBot { case class BindingSuccess(binding: Http.ServerBinding) extends Command case class BindingFailure(exception: Throwable) extends Command - ctx.log.info("action=bind_server interface={} port={}", interface, port) + ctx.log.info("action=bind_server interface={} port={}", interface, localPort) http - .bindAndHandle(routes, interface, port, httpsContext) + .bindAndHandle(routes, interface, localPort, httpsContext) .onComplete { case Success(binding) => ctx.self ! BindingSuccess(binding) case Failure(exception) => ctx.self ! BindingFailure(exception) @@ -81,7 +81,7 @@ object TelegramBot { case object UnbindingSuccess extends Command case class UnbindingFailure(exception: Throwable) extends Command - ctx.log.info("action=unbind_server interface={} port={}", interface, port) + ctx.log.info("action=unbind_server interface={} port={}", interface, localPort) binding .unbind()