Created
June 10, 2020 04:04
-
-
Save seratch/c085ac418c53daad24473f38e0363a9a to your computer and use it in GitHub Desktop.
Slack app built with Scalatra
This file contains 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
val ScalatraVersion = "2.7.0" | |
organization := "hello" | |
name := "bolt-scalatra-app" | |
version := "0.1.0-SNAPSHOT" | |
scalaVersion := "2.13.1" | |
resolvers += Classpaths.typesafeReleases | |
libraryDependencies ++= Seq( | |
"org.scalatra" %% "scalatra" % ScalatraVersion, | |
"com.slack.api" % "bolt-servlet" % "1.0.8", | |
"org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test", | |
"ch.qos.logback" % "logback-classic" % "1.2.3" % "runtime", | |
"org.eclipse.jetty" % "jetty-webapp" % "9.4.28.v20200408" % "container", | |
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided" | |
) | |
containerPort in Jetty := 3000 | |
enablePlugins(SbtTwirl) | |
enablePlugins(ScalatraPlugin) |
This file contains 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
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.4.2") | |
addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % "1.0.4") |
This file contains 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
import com.slack.api.bolt.App | |
import com.slack.api.bolt.handler.builtin.SlashCommandHandler | |
import com.slack.api.bolt.servlet.SlackAppServlet | |
import javax.servlet.ServletContext | |
import javax.servlet.http.{HttpServletRequest, HttpServletResponse} | |
import org.scalatra._ | |
class RootController extends ScalatraServlet { | |
get("/") { | |
views.html.hello() | |
} | |
} | |
class SlackAppController(app: App) extends SlackAppServlet(app) with org.scalatra.Handler { | |
override def handle(request: HttpServletRequest, response: HttpServletResponse): Unit = { | |
doPost(request, response) | |
} | |
} | |
object Components { | |
lazy val slackApp: App = { | |
val app = new App() | |
val makeRequestHandler: SlashCommandHandler = (req, ctx) => { | |
ctx.ack(s"Thanks <@${req.getPayload.getUserId}>!") | |
} | |
app.command("/make-request", makeRequestHandler) | |
app | |
} | |
} | |
class ScalatraBootstrap extends LifeCycle { | |
override def init(context: ServletContext) { | |
context.mount(new RootController, "/*") | |
context.mount(new SlackAppController(Components.slackApp), "/slack/events") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment