More telegram entities.
This commit is contained in:
@@ -18,19 +18,11 @@ import spray.json._
|
||||
import scala.util.{Failure, Success}
|
||||
|
||||
trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
|
||||
implicit object getMeFormat extends RootJsonFormat[GetMe] {
|
||||
override def write(obj: GetMe): JsValue = ???
|
||||
|
||||
override def read(json: JsValue): GetMe =
|
||||
json.asJsObject.getFields("id", "is_bot", "first_name", "username") match {
|
||||
case Seq(JsNumber(id), JsBoolean(isBot), JsString(firstName), JsString(userName)) => GetMe(id.toInt, isBot, firstName, userName)
|
||||
case _ => throw new DeserializationException("GetMe deserialize error")
|
||||
}
|
||||
}
|
||||
implicit val responseFormat = jsonFormat2(Response[GetMe])
|
||||
implicit val getMeFormat: RootJsonFormat[GetMe] = jsonFormat4(GetMe)
|
||||
implicit val responseFormat: RootJsonFormat[Response[GetMe]] = jsonFormat4(Response[GetMe])
|
||||
}
|
||||
|
||||
class TelegramBot extends JsonSupport {
|
||||
class TelegramBotServer extends JsonSupport {
|
||||
|
||||
def run(): Unit = {
|
||||
implicit val actorSystem: ActorSystem = ActorSystem("telegram-bot")
|
||||
@@ -67,10 +59,14 @@ class TelegramBot extends JsonSupport {
|
||||
def getBotInfo()(implicit actorSystem: ActorSystem, materializer: ActorMaterializer, executionContext: ExecutionContextExecutor): Future[Response[GetMe]] = {
|
||||
Http().singleRequest(HttpRequest(uri = "https://api.telegram.org/bot570855144:AAEv7b817cuq2JJI9f2kG5B9G3zW1x-btz4/getMe")).flatMap(Unmarshal(_).to[Response[GetMe]])
|
||||
}
|
||||
}
|
||||
|
||||
object TelegramBot {
|
||||
def main(args: Array[String]): Unit = {
|
||||
new TelegramBot().run()
|
||||
def setWebhook(): Unit = {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
object TelegramBotServer {
|
||||
def main(args: Array[String]): Unit = {
|
||||
new TelegramBotServer().run()
|
||||
}
|
||||
}
|
||||
@@ -3,41 +3,101 @@ package eu.xeppaka.bot1
|
||||
object TelegramEntities {
|
||||
|
||||
case class Response[T](ok: Boolean,
|
||||
// description: Option[String],
|
||||
// errorCode: Option[Int],
|
||||
description: Option[String],
|
||||
error_code: Option[Int],
|
||||
result: T)
|
||||
|
||||
case class GetMe(id: Int, isBot: Boolean, firstName: String, userName: String)
|
||||
case class GetMe(id: Int, is_bot: Boolean, first_name: String, username: String)
|
||||
|
||||
case class Update(updateId: Int,
|
||||
case class InlineQuery(id: String,
|
||||
from: User,
|
||||
location: Location,
|
||||
query: String,
|
||||
offset: String)
|
||||
|
||||
case class Location(longitude: Float,
|
||||
latitude: Float)
|
||||
|
||||
case class Update(update_id: Int,
|
||||
message: Option[Message],
|
||||
editedMessage: Option[Message],
|
||||
channelPost: Option[Message],
|
||||
editedChannelPost: Option[Message])
|
||||
edited_message: Option[Message],
|
||||
channel_post: Option[Message],
|
||||
edited_channel_post: Option[Message],
|
||||
inline_query: Option[InlineQuery],
|
||||
chosen_inline_result: Option[ChosenInlineResult],
|
||||
callback_query: Option[CallbackQuery],
|
||||
shipping_query: Option[ShippingQuery],
|
||||
pre_checkout_query: Option[PreCheckoutQuery])
|
||||
|
||||
case class ChosenInlineResult(result_id: String,
|
||||
from: User,
|
||||
location: Option[Location],
|
||||
inline_message_id: Option[String],
|
||||
query: String)
|
||||
|
||||
case class CallbackQuery(id: String,
|
||||
from: User,
|
||||
message: Option[Message],
|
||||
inline_message_id: Option[String],
|
||||
chat_instance: String,
|
||||
data: Option[String],
|
||||
game_short_name: Option[String])
|
||||
|
||||
case class ShippingQuery(id: String,
|
||||
from: User,
|
||||
invoice_payload: String,
|
||||
shipping_address: ShippingAddress)
|
||||
|
||||
case class ShippingAddress(country_code: String,
|
||||
state: String,
|
||||
city: String,
|
||||
street_line1: String,
|
||||
street_line2: String,
|
||||
post_code: String)
|
||||
|
||||
case class PreCheckoutQuery(id: String,
|
||||
from: User,
|
||||
currency: String,
|
||||
total_amount: Int,
|
||||
invoice_payload: String,
|
||||
shipping_option_id: Option[String],
|
||||
order_info: Option[OrderInfo])
|
||||
|
||||
case class OrderInfo(name: Option[String],
|
||||
phone_number: Option[String],
|
||||
email: Option[String],
|
||||
shipping_address: Option[ShippingAddress])
|
||||
|
||||
case class User(id: Int,
|
||||
isBot: Boolean,
|
||||
firstName: String,
|
||||
lastName: Option[String],
|
||||
userName: Option[String],
|
||||
languageCode: Option[String])
|
||||
is_bot: Boolean,
|
||||
first_name: String,
|
||||
last_name: Option[String],
|
||||
username: Option[String],
|
||||
language_code: Option[String])
|
||||
|
||||
case class Message()
|
||||
|
||||
case class ChatPhoto(smallFileId: String, bigFileId: String)
|
||||
case class ChatPhoto(small_file_id: String, big_file_id: String)
|
||||
|
||||
case class Chat(id: Int,
|
||||
chatType: String,
|
||||
`type`: String,
|
||||
title: Option[String],
|
||||
userName: Option[String],
|
||||
firstName: Option[String],
|
||||
lastName: Option[String],
|
||||
allMembersAreAdministrators: Option[Boolean],
|
||||
username: Option[String],
|
||||
first_name: Option[String],
|
||||
last_name: Option[String],
|
||||
all_members_are_administrators: Option[Boolean],
|
||||
photo: Option[ChatPhoto],
|
||||
description: Option[String],
|
||||
inviteLink: Option[String],
|
||||
pinnedMessage: Option[Message],
|
||||
stickerSetName: Option[String],
|
||||
canSetStickerSet: Option[Boolean]
|
||||
invite_link: Option[String],
|
||||
pinned_message: Option[Message],
|
||||
sticker_set_name: Option[String],
|
||||
can_set_sticker_set: Option[Boolean]
|
||||
)
|
||||
|
||||
case class InputFile()
|
||||
|
||||
case class Webhook(url: String,
|
||||
certificate: Option[InputFile],
|
||||
max_connections: Option[Int],
|
||||
allowed_updates: Option[Seq[String]])
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ object VkApiTests {
|
||||
// .userAuthorizationCodeFlow(APP_ID, APP_SECRET, "https://oauth.vk.com/blank.html", USER_SECRET_CODE)
|
||||
// .execute()
|
||||
|
||||
val userActor = new UserActor(6242549, "2ab6508fbc2ff7d2a23fd07cf6b6cb79354abc6c1276447bf2bfb6bfe4bca5cc8d5ecc83dbead6efa04d4")
|
||||
val userActor = new UserActor(6242549, "e7acb4be42aa11ab692b567ae272f16ec3c49d20f51851bb507126ce9ffc0f4aea013d34c0a26e285202d")
|
||||
|
||||
val resp = vkApiClient.messages().get(userActor).execute()
|
||||
println(resp)
|
||||
|
||||
Reference in New Issue
Block a user