Incoming WebHooks URL を取得する
https://<Your Team Name>.slack.com/apps/build
にアクセスし
Scala で post してみる
postするのに play-ws を利用する。
※ scalaVersionは2.11.7
それ以上のversionにするとjava.lang.NoClassDefFoundError: scala/Product$class
Compile Dependenciesをちゃんと見ろということですね。すいません。
build.scala
name := "slack-incoming"
version := "1.0"
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"com.typesafe.play" % "play-ws_2.11" % "2.5.9"
)
Main.scala
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import play.api.libs.ws._
import play.api.libs.ws.ahc.AhcWSClient
import scala.concurrent.Future
object Main {
import scala.concurrent.ExecutionContext.Implicits._
def main(args: Array[String]): Unit = {
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
val wsClient = AhcWSClient()
call(wsClient)
.andThen { case _ => wsClient.close() }
.andThen { case _ => system.terminate() }
}
def call(wsClient: WSClient) = {
val postJson = """{"text": "This is a line of text in a channel.\nAnd this is another line of text."}"""
val contentType = ("Content-Type" -> "application/json")
wsClient.url("<Web Hooks URL>")
.withHeaders(contentType)
.post(postJson)
}
}
Slackで確認
すごく・・・かんたんです・・・
その2があるかは未定