Initial commit. Playing with VK api for the bot.

This commit is contained in:
Pavel Kachalouski
2018-05-08 22:49:55 +02:00
commit 8b705c8f77
10 changed files with 205 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package eu.xeppaka.bot1
import akka.actor.{Actor, Props}
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{HttpEntity, HttpRequest, HttpResponse, StatusCodes}
import akka.stream.{ActorMaterializer, ActorMaterializerSettings}
import eu.xeppaka.bot1.AccessTokenActor.GetToken
import scala.concurrent.duration._
class AccessTokenActor extends Actor {
import akka.pattern.pipe
import context.dispatcher
private val OAUTH_URL_TEMPLATE = "https://oauth.vk.com/authorize?client_id=%d&scope=friends&redirect_uri=https://oauth.vk.com/blank.html&display=page&v=5.74&response_type=token"
private implicit val materializer: ActorMaterializer = ActorMaterializer(ActorMaterializerSettings(context.system))
private val http = Http(context.system)
override def receive: Receive = {
case GetToken(clientId) =>
val uri = OAUTH_URL_TEMPLATE.format(clientId)
val request = HttpRequest(uri = uri)
http.singleRequest(request).pipeTo(self)
case HttpResponse(StatusCodes.OK, headers, entity, _) =>
println("OK")
entity.withoutSizeLimit().toStrict(1 second).pipeTo(self)
case resp @ HttpResponse(code, _, _, _) =>
println(s"Failed with HTTP code $code")
case HttpEntity.Strict(contentType, data) =>
println(data.utf8String)
}
}
object AccessTokenActor {
case class GetToken(clientId: Int)
def props: Props = Props[AccessTokenActor]
}

View File

@@ -0,0 +1,17 @@
package eu.xeppaka.bot1
import java.util.UUID
import akka.actor.Actor
class DialogActor extends Actor {
private val dialogId = UUID.randomUUID()
override def receive: Receive = {
case 1 =>
}
}
object DialogActor {
}

View File

@@ -0,0 +1,31 @@
package eu.xeppaka.bot1
import akka.actor.ActorSystem
import com.vk.api.sdk.client.VkApiClient
import com.vk.api.sdk.client.actors.UserActor
import com.vk.api.sdk.httpclient.HttpTransportClient
object VkApiTests {
private val APP_ID = 6472591
private val APP_SECRET = "iGClqTncCZpzEqD8m5Wt"
private val USER_SECRET_CODE = "4180052ce419f0470d"
private val vkTransportClient = HttpTransportClient.getInstance()
private val vkApiClient = new VkApiClient(vkTransportClient)
// private val actorSystem = ActorSystem("vk")
def main(args: Array[String]): Unit = {
// val accessTokenActor = actorSystem.actorOf(AccessTokenActor.props)
// accessTokenActor ! GetToken(APP_ID)
// val authResponse = vkApiClient.oauth()
// .userAuthorizationCodeFlow(APP_ID, APP_SECRET, "https://oauth.vk.com/blank.html", USER_SECRET_CODE)
// .execute()
val userActor = new UserActor(6242549, "2ab6508fbc2ff7d2a23fd07cf6b6cb79354abc6c1276447bf2bfb6bfe4bca5cc8d5ecc83dbead6efa04d4")
val resp = vkApiClient.messages().get(userActor).execute()
println(resp)
}
}

View File

@@ -0,0 +1,9 @@
package example
object Hello extends Greeting with App {
println(greeting)
}
trait Greeting {
lazy val greeting: String = "hello"
}

View File

@@ -0,0 +1,9 @@
package example
import org.scalatest._
class HelloSpec extends FlatSpec with Matchers {
"The Hello object" should "say hello" in {
Hello.greeting shouldEqual "hello"
}
}