-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70ca704
commit 8d6e3fa
Showing
7 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
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
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
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
29 changes: 29 additions & 0 deletions
29
akka-loader/src/main/scala/telegram/LoaderTelegramClient.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package telegram | ||
|
||
import akka.actor.ActorSystem | ||
import com.typesafe.config.Config | ||
import com.typesafe.scalalogging.Logger | ||
import hattid.telegram.TelegramClient | ||
import hattid.telegram.TelegramClient.TelegramCreds | ||
import org.slf4j.LoggerFactory | ||
|
||
import javax.inject.{Inject, Singleton} | ||
|
||
@Singleton | ||
class LoaderTelegramClient @Inject()(config: Config, | ||
implicit val actorSystem: ActorSystem) { | ||
private val logger = Logger(LoggerFactory.getLogger(this.getClass)) | ||
def sendException(message: String, e: Throwable): Unit = { | ||
val enabled = config.hasPath("telegram.chatId") && config.hasPath("telegram.botToken") | ||
if (enabled) { | ||
implicit val creds: TelegramCreds = TelegramCreds(config.getString("telegram.chatId"), config.getString("telegram.botToken")) | ||
val stacktrace = e.getStackTrace.mkString("\n") | ||
val text = s"$message: ${e.getMessage} \n\n $stacktrace" | ||
try { | ||
TelegramClient.sendMessage(text.take(4095)) | ||
} catch { | ||
case e: Exception => logger.warn("Telegram reporting is not working", e) | ||
} | ||
} | ||
} | ||
} |