Compare commits

..

1 Commits

Author SHA1 Message Date
Pavel Kachalouski
3a3de48c8f Set initial dialog status as waiting for command
All checks were successful
continuous-integration/drone/push Build is passing
2019-05-19 21:19:36 +02:00
2 changed files with 12 additions and 8 deletions

View File

@@ -171,7 +171,7 @@ object CheckDeliveryDialog {
val message = SendMessage(chatId, "Please enter a parcel id to remove.", reply_markup = Some(markup))
sendMessage(message, waitParcelId(parcelId => removeParcelId(parcelId)), onFailure)
} else {
val message = SendMessage(chatId, "You don't have watched parcels. There is nothing to remove.")
val message = SendMessage(chatId, "You don't have watched parcels. There is nothing to remove.", reply_markup = commandsKeyboard)
sendMessage(message, onSuccess, onFailure)
}
case ListParcelsFailure(exception) =>
@@ -240,7 +240,7 @@ object CheckDeliveryDialog {
Behaviors.same
}
def sendMessage(message: SendMessage, onSuccess: => Behavior[Command], onFailure: => Behavior[Command], attempt: Int = 0): Behavior[Command] = Behaviors.setup[Command] { ctx =>
def sendMessage(message: SendMessage, onSuccess: => Behavior[Command], onFailure: => Behavior[Command], attempt: Int = 1): Behavior[Command] = Behaviors.setup[Command] { ctx =>
import io.circe.generic.auto._
import io.circe.syntax._
@@ -254,7 +254,7 @@ object CheckDeliveryDialog {
Source
.single(request)
.initialDelay(2.seconds * attempt)
.initialDelay(2.seconds * (attempt - 1))
.mapAsync(1) { request =>
http
.singleRequest(request)
@@ -280,7 +280,7 @@ object CheckDeliveryDialog {
case SendMessageFailure(exception) =>
ctx.log.error(exception, "action=send_message status=finished result=failure chat_id={} attempt={}", chatId, attempt)
if (attempt >= 5) {
if (attempt > 5) {
ctx.log.error(exception, "action=send_message result=failure message=attempts threshold exceeded")
stashBuffer.unstashAll(ctx, onFailure)
} else {

View File

@@ -104,7 +104,7 @@ object TelegramBot {
}
}
def settingWebhook(binding: Http.ServerBinding): Behavior[Command] = Behaviors.setup[Command] { ctx =>
def settingWebhook(binding: Http.ServerBinding, attempt: Int = 1): Behavior[Command] = Behaviors.setup[Command] { ctx =>
case object SetWebhookSuccess extends Command
case class SetWebhookFailure(exception: Throwable) extends Command
@@ -145,9 +145,13 @@ object TelegramBot {
ctx.log.info("action=set_webhook result=success")
stashBuffer.unstashAll(ctx, started(binding))
case SetWebhookFailure(exception) =>
ctx.log.error("action=set_webhook result=failure", exception)
ctx.log.error("action=start_bot result=failure")
unbindingServer(binding, None)
if (attempt > 20) {
ctx.log.error(exception, "action=set_webhook result=failure attempt={}", attempt)
ctx.log.error("action=start_bot result=failure")
unbindingServer(binding, None)
} else {
settingWebhook(binding, attempt = attempt + 1)
}
case otherCommand: Command =>
stashBuffer.stash(otherCommand)
Behaviors.same