Initial commit. Playing with VK api for the bot.
This commit is contained in:
69
.gitignore
vendored
Normal file
69
.gitignore
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### SBT template
|
||||
# Simple Build Tool
|
||||
# http://www.scala-sbt.org/release/docs/Getting-Started/Directories.html#configuring-version-control
|
||||
|
||||
dist/*
|
||||
target/
|
||||
lib_managed/
|
||||
src_managed/
|
||||
project/boot/
|
||||
project/plugins/project/
|
||||
.history
|
||||
.cache
|
||||
.lib/
|
||||
### Scala template
|
||||
*.class
|
||||
*.log
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# CMake
|
||||
cmake-build-debug/
|
||||
cmake-build-release/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
18
build.sbt
Normal file
18
build.sbt
Normal file
@@ -0,0 +1,18 @@
|
||||
import Dependencies._
|
||||
|
||||
lazy val root = (project in file(".")).
|
||||
settings(
|
||||
inThisBuild(List(
|
||||
organization := "com.example",
|
||||
scalaVersion := "2.12.6",
|
||||
version := "0.1.0-SNAPSHOT"
|
||||
)),
|
||||
name := "telegram-bot1",
|
||||
libraryDependencies ++= Seq(
|
||||
scalaTest % Test,
|
||||
akka,
|
||||
akkaHttp,
|
||||
akkaStream,
|
||||
vkapi
|
||||
)
|
||||
)
|
||||
9
project/Dependencies.scala
Normal file
9
project/Dependencies.scala
Normal file
@@ -0,0 +1,9 @@
|
||||
import sbt._
|
||||
|
||||
object Dependencies {
|
||||
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5"
|
||||
lazy val akka = "com.typesafe.akka" %% "akka-actor" % "2.5.12"
|
||||
lazy val akkaHttp = "com.typesafe.akka" %% "akka-http" % "10.1.1"
|
||||
lazy val akkaStream = "com.typesafe.akka" %% "akka-stream" % "2.5.12"
|
||||
lazy val vkapi = "com.vk.api" % "sdk" % "0.5.12"
|
||||
}
|
||||
1
project/build.properties
Normal file
1
project/build.properties
Normal file
@@ -0,0 +1 @@
|
||||
sbt.version=1.1.4
|
||||
40
src/main/scala/eu/xeppaka/bot1/AccessTokenActor.scala
Normal file
40
src/main/scala/eu/xeppaka/bot1/AccessTokenActor.scala
Normal 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]
|
||||
}
|
||||
17
src/main/scala/eu/xeppaka/bot1/DialogActor.scala
Normal file
17
src/main/scala/eu/xeppaka/bot1/DialogActor.scala
Normal 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 {
|
||||
|
||||
}
|
||||
31
src/main/scala/eu/xeppaka/bot1/VkApiTests.scala
Normal file
31
src/main/scala/eu/xeppaka/bot1/VkApiTests.scala
Normal 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)
|
||||
}
|
||||
}
|
||||
9
src/main/scala/example/Hello.scala
Normal file
9
src/main/scala/example/Hello.scala
Normal file
@@ -0,0 +1,9 @@
|
||||
package example
|
||||
|
||||
object Hello extends Greeting with App {
|
||||
println(greeting)
|
||||
}
|
||||
|
||||
trait Greeting {
|
||||
lazy val greeting: String = "hello"
|
||||
}
|
||||
9
src/test/scala/example/HelloSpec.scala
Normal file
9
src/test/scala/example/HelloSpec.scala
Normal 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"
|
||||
}
|
||||
}
|
||||
2
urls.txt
Normal file
2
urls.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
https://oauth.vk.com/authorize?client_id=6472591&scope=friends&redirect_uri=https://oauth.vk.com/blank.html&display=mobile&v=5.74&response_type=token
|
||||
https://oauth.vk.com/authorize?client_id=6472591&scope=friends&redirect_uri=https://oauth.vk.com/blank.html&display=mobile&v=5.74&response_type=code
|
||||
Reference in New Issue
Block a user