Last active
June 13, 2025 20:56
-
-
Save Krever/eee34f786bfbb9854ae12c17c88889a4 to your computer and use it in GitHub Desktop.
Prorotype api for chatops4s
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chatops4s | |
import cats.effect.IO | |
object UsageExample { | |
val inbound: InboundGateway = ??? | |
val outbound: OutboundGateway = ??? | |
for { | |
approveAction <- inbound.registerAction(ctx => IO(println(s"Approved by ${ctx.userId}"))) | |
rejectAction <- inbound.registerAction(ctx => IO(println(s"Rejected by ${ctx.userId}"))) | |
msg = Message( | |
text = "Deploy to production?", | |
interactions = Seq( | |
approveAction.render("Approve"), | |
rejectAction.render("Reject"), | |
), | |
) | |
response <- outbound.sendToChannel("channel123", msg) | |
_ <- outbound.sendToThread(response.messageId, Message("Thanks for your feedback")) | |
} yield () | |
} | |
// allows to put data into the platform, probably based on sttp | |
trait OutboundGateway { | |
def sendToChannel(channelId: String, message: Message): IO[MessageResponse] | |
def sendToThread(messageId: String, message: Message): IO[MessageResponse] | |
} | |
case class Message( | |
text: String, | |
interactions: Seq[Button] = Seq(), | |
) | |
case class MessageResponse( | |
messageId: String, | |
) | |
// allows to receive data from the platform | |
trait InboundGateway { | |
// todo: id will be required to keep processing between restarts | |
def registerAction(handler: InteractionContext => IO[Unit]): IO[ButtonInteraction] | |
} | |
// who clicked what where | |
case class InteractionContext( | |
userId: String, | |
channelId: String, | |
messageId: String, | |
) | |
// registered interaction | |
// handler was registered and produced this object that can be used to accept data | |
trait ButtonInteraction { | |
def render(label: String): Button | |
} | |
// Direct mapping of api - object we put in the request | |
case class Button(label: String, value: String) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment