telegrambot
"Batteries Included" Telegram Bot API wrapper for Scala
Features
- Fully asynchronous
- spray.io powered.
- Declarative DSL for simple bot features
- Strongly-typed
Supported Methods
- getMe
- sendMessage
- getUpdates
- forwardMessage
- sendPhoto
- sendAudio
- sendVoice (coming soon)
- sendDocument
- sendSticker
- sendVideo (coming soon)
- sendLocation
- sendChatAction
- getUserProfilePhotos
- getUpdates
- Custom keyboard markups
- Webhook with a SSL reverse proxy
TODO
- Built-in Webhook support
- Better error handling
- Documentation
Configuration
Check reference.conf for configuration.
Installation
There is no release yet; project still lack too much improvement. Wait for updates.
Usage
Simple commands + simple answers
object GreeterBot extends TelegramBot with Polling with Declarative {
on("/start") { implicit message: Message =>
reply("Welcome")
}
}
Using received message
object GreeterBot extends TelegramBot with Polling with Declarative {
on("/start") { implicit message: Message =>
message.from match {
case Some(user) => reply("Welcome, " + user.firstName)
case _ =>
}
}
}
Sending photos
object GreeterBot extends TelegramBot with Polling with Declarative {
on("/start") { implicit message: Message =>
sendPhoto("~/image.jpg")
}
}
When You Need More Power
object GreeterBot extends TelegramBot with Polling with Declarative {
when { message =>
message.photo match {
case Some(photo) => true
case None => false
}
} perform { implicit message =>
reply("Nice Smile!")
}
}
"Cuckoo Clock?" Why Not?
object GreeterBot extends TelegramBot with Polling with Declarative {
every(1 hours) {
sendTo("Ping!", 31415926535)
}
}
Sending Messages Not Always Successful
object TestBot extends TelegramBot with Polling with Declarative {
sendTo("test", 1093654812) map {
case Right(message) =>
println(message);
case Left(error) if error.code == 403 =>
println("No, we are not allowed to send messages to this chat");
case Left(error) if error.code == 400 =>
println("No, chat doesn't exists");
}
}
Keep user informed!
on("Welcome") { implicit message =>
typing; reply("typed.")
}
}