Create the base class for the Bot.

This commit is contained in:
Danila Fedorin 2018-01-12 17:22:05 -08:00
parent d0a044f3c7
commit 57ee991895
2 changed files with 27 additions and 0 deletions

17
src/telepathy/bot.cr Normal file
View File

@ -0,0 +1,17 @@
require "http"
module Telepathy
class Bot
def initialize(@api_token : String)
@request_base = "https://api.telegram.org/bot#{@api_token}"
@this_user = uninitialized User?
@this_user = get_me
end
def get_me
response = HTTP::Client.get(@request_base + "/getMe",
headers: HTTP::Headers{"User-agent" => "Telepathy"})
return Response(User).from_json(response.body).result
end
end
end

View File

@ -0,0 +1,10 @@
require "json"
module Telepathy
class Response(T)
JSON.mapping(
ok: Bool,
result: T
)
end
end