diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..92e9122 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/src/main/scala/eu/xeppaka/bot1/TelegramBotServer.scala b/src/main/scala/eu/xeppaka/bot1/TelegramBotServer.scala index a28efa2..4a51dd2 100644 --- a/src/main/scala/eu/xeppaka/bot1/TelegramBotServer.scala +++ b/src/main/scala/eu/xeppaka/bot1/TelegramBotServer.scala @@ -40,9 +40,9 @@ class TelegramBotServer(botId: String, port: Int, httpsContext: Option[HttpsConn private val http: HttpExt = Http() private val hookId = UUID.randomUUID().toString - private val webhookUri = Uri(s"https://xeppaka.eu:$port/$hookId") + private val webhookUri = Uri(s"https://xeppaka.eu:88/$hookId") private val bindingFuture = http.bindAndHandle(botRoutes(hookId), - "pkcloud", + "lenovo", port, connectionContext = httpsContext.getOrElse(http.defaultClientHttpsContext)) @@ -65,7 +65,7 @@ class TelegramBotServer(botId: String, port: Int, httpsContext: Option[HttpsConn def botRoutes(hookId: String): Route = { path(hookId) { post { - entity(as[Update]) { update => + entity(as[Update]) { _ => handleWith(receivedUpdate) } } @@ -146,7 +146,7 @@ object TelegramBotServer { def main(args: Array[String]): Unit = { val httpsContext = createHttpsConnectionContext - val tbs = TelegramBotServer(88, Some(createHttpsConnectionContext)) + val tbs = TelegramBotServer(8443, Some(createHttpsConnectionContext)) StdIn.readLine() tbs.stop() diff --git a/src/main/scala/eu/xeppaka/bot1/actors/ChatActor.scala b/src/main/scala/eu/xeppaka/bot1/actors/ChatActor.scala index b7381d8..f034925 100644 --- a/src/main/scala/eu/xeppaka/bot1/actors/ChatActor.scala +++ b/src/main/scala/eu/xeppaka/bot1/actors/ChatActor.scala @@ -4,19 +4,14 @@ import akka.actor.typed.scaladsl.Behaviors import akka.actor.typed.{ActorRef, Behavior} object ChatActor { - sealed trait ChatCommand { def replyTo: ActorRef[Response] } case class Response(text: String) - case class Help(replyTo: ActorRef[Response]) extends ChatCommand - case class Start(replyTo: ActorRef[Response]) extends ChatCommand - case class MessageReceived(text: String, replyTo: ActorRef[Response]) extends ChatCommand - case class Stop(replyTo: ActorRef[Response]) extends ChatCommand private val started: Behavior[ChatCommand] = Behaviors.receive { (ctx, msg) => @@ -33,7 +28,7 @@ object ChatActor { case _ => Behaviors.unhandled } - } + } private val initial: Behavior[ChatCommand] = Behaviors.receive { (ctx, msg) => msg match { @@ -44,7 +39,7 @@ object ChatActor { c.replyTo ! Response("Only /start command is supported. Try it...") Behaviors.same } - } + } private def replyHelp(replyTo: ActorRef[Response]): Unit = { replyTo ! Response("No help is provided for such motherfuckers like you! But... ok, send /stop and we are free.") diff --git a/src/main/scala/eu/xeppaka/bot1/actors/UpdateActor2.scala b/src/main/scala/eu/xeppaka/bot1/actors/UpdateActor2.scala deleted file mode 100644 index 535262b..0000000 --- a/src/main/scala/eu/xeppaka/bot1/actors/UpdateActor2.scala +++ /dev/null @@ -1,42 +0,0 @@ -package eu.xeppaka.bot1.actors - -import akka.actor.{Actor, ActorLogging, Props} -import akka.http.scaladsl.HttpExt -import akka.http.scaladsl.model.{ContentTypes, HttpEntity, HttpMethods, HttpRequest} -import akka.util.ByteString -import eu.xeppaka.bot1.TelegramEntities.SendMessage -import eu.xeppaka.bot1.{BotUri, TelegramEntities} - -class UpdateActor2 extends Actor with ActorLogging { - import UpdateActor2.ReceivedUpdate - - override def receive: Receive = { - case ReceivedUpdate(update) => processUpdate(update) - } - - private def processUpdate(update: TelegramEntities.Update) = { - log.info(s"Received update: $update") - if (update.message.isDefined) { - processMessage(update.message.get) - } - } - - private def processMessage(message: TelegramEntities.Message) = { - import io.circe._, io.circe.generic.auto._, io.circe.syntax._ - -// log.info("Received message from: {}", message.from) -// val sendMessage = SendMessage(message.chat.id, s"Привет, ${message.from.get.first_name}") -// val printer = Printer.noSpaces.copy(dropNullValues = true) -// val json = printer.pretty(sendMessage.asJson) -// val request = HttpRequest(HttpMethods.POST, uri = botUri.sendMessage, entity = HttpEntity.Strict(ContentTypes.`application/json`, ByteString(json))) -// http.singleRequest(request) - } -} - -object UpdateActor2 { - - case class ReceivedUpdate(update: TelegramEntities.Update) - - def props(): Props = Props(new UpdateActor2()) - -}