Create the base class for the Bot.
This commit is contained in:
parent
d0a044f3c7
commit
57ee991895
17
src/telepathy/bot.cr
Normal file
17
src/telepathy/bot.cr
Normal 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
|
10
src/telepathy/model/response.cr
Normal file
10
src/telepathy/model/response.cr
Normal file
|
@ -0,0 +1,10 @@
|
|||
require "json"
|
||||
|
||||
module Telepathy
|
||||
class Response(T)
|
||||
JSON.mapping(
|
||||
ok: Bool,
|
||||
result: T
|
||||
)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user