Skip to content

Commit

Permalink
pass taskRef to start/stop typing jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ff137 committed Nov 15, 2023
1 parent 2231e9e commit e60a441
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/xyz/didx/ConversationPollingHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import xyz.didx.openai.OpenAIAgent
import xyz.didx.passkit.PasskitAgent
import xyz.didx.ai.AiHandler
import xyz.didx.ai.model.ChatState
import cats.effect.Ref
import cats.effect.FiberIO

class ConversationPollingHandler(using logger: Logger[IO]):
val appConf = getConf(using logger)
Expand Down Expand Up @@ -159,14 +161,17 @@ class ConversationPollingHandler(using logger: Logger[IO]):
val currentState = userStates.getOrElse(userPhone, ChatState.Onboarding)

(for {
_ <- EitherT(signalBot.startTyping(userPhone))
taskRef <- // reference for start/stop typing indicator job
EitherT.right[Error](Ref.of[IO, Option[FiberIO[Unit]]](None))
_ <- EitherT.right[Error](signalBot.startTyping(userPhone, taskRef))
responseState <- EitherT(AiHandler.getAiResponse(
input = message.text,
conversationId = userPhone,
state = currentState,
telNo = Some(userPhone)
))
signalMessage = SignalSimpleMessage(userPhone, message.name, responseState._1)
_ <- EitherT.right[Error](signalBot.stopTyping(userPhone, taskRef))
sendResult <- EitherT(signalBot.send(
SignalSendMessage(
List[String](),
Expand All @@ -175,7 +180,6 @@ class ConversationPollingHandler(using logger: Logger[IO]):
List(message.phone)
)
))
_ <- EitherT(signalBot.stopTyping(userPhone))
} yield
// Update the state map with the new state for this user
userStates.update(userPhone, responseState._2)
Expand Down

0 comments on commit e60a441

Please sign in to comment.