From 57ee991895923ca73cd1be72c188a5293e296706 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 12 Jan 2018 17:22:05 -0800 Subject: [PATCH] Create the base class for the Bot. --- src/telepathy/bot.cr | 17 +++++++++++++++++ src/telepathy/model/response.cr | 10 ++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/telepathy/bot.cr create mode 100644 src/telepathy/model/response.cr 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