diff --git a/src/telepathy/bot.cr b/src/telepathy/bot.cr new file mode 100644 index 0000000..1c37e45 --- /dev/null +++ b/src/telepathy/bot.cr @@ -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 diff --git a/src/telepathy/model/response.cr b/src/telepathy/model/response.cr new file mode 100644 index 0000000..886c8f3 --- /dev/null +++ b/src/telepathy/model/response.cr @@ -0,0 +1,10 @@ +require "json" + +module Telepathy + class Response(T) + JSON.mapping( + ok: Bool, + result: T + ) + end +end