override def handleRequest()

in anghammarad/src/main/scala/com/gu/anghammarad/Lambda.scala [11:36]


  override def handleRequest(input: SNSEvent, context: Context): Unit = {

    val parseNotification = Serialization.parseNotification(input)

    val sentMessages = for {
      stage <- Config.getStage()
      config <- Config.loadConfig(stage)
      configuration <- Serialization.parseConfig(config)
      notification <- parseNotification
      sent <- AnghammaradService.run(notification, configuration)
    } yield sent

    // send notification if result is a failure
    sentMessages match {
      case Failure(err) =>
        context.getLogger.log(s"Failed to send message ${err.getMessage}. " +
          s"Notification details: ${parseNotification.getOrElse("Could not parse notification")}")
        throw err
      case Success(sent) =>
        sent.map {
          case (_, EmailAddress(email)) => s"Email: $email"
          case (_, HangoutsRoom(webhook)) => s"Hangouts webhook: $webhook"
        }
        context.getLogger.log(s"sent ${sent.mkString(",")}")
    }
  }