Class: ChatSDK::Telegram::ApiClient
- Inherits:
-
Object
- Object
- ChatSDK::Telegram::ApiClient
- Defined in:
- lib/chat_sdk/telegram/api_client.rb
Constant Summary collapse
- BASE_URL =
"https://api.telegram.org"
Instance Method Summary collapse
- #delete_message(chat_id:, message_id:) ⇒ Object
- #edit_message_text(chat_id:, message_id:, text:, reply_markup: nil) ⇒ Object
-
#initialize(bot_token) ⇒ ApiClient
constructor
A new instance of ApiClient.
- #send_chat_action(chat_id:, action:) ⇒ Object
- #send_document(chat_id:, document:, filename:, caption: nil, reply_to_message_id: nil) ⇒ Object
- #send_message(chat_id:, text:, reply_markup: nil, reply_to_message_id: nil) ⇒ Object
- #set_message_reaction(chat_id:, message_id:, reaction:) ⇒ Object
Constructor Details
#initialize(bot_token) ⇒ ApiClient
Returns a new instance of ApiClient.
8 9 10 |
# File 'lib/chat_sdk/telegram/api_client.rb', line 8 def initialize(bot_token) @bot_token = bot_token end |
Instance Method Details
#delete_message(chat_id:, message_id:) ⇒ Object
25 26 27 |
# File 'lib/chat_sdk/telegram/api_client.rb', line 25 def (chat_id:, message_id:) request(:post, "deleteMessage", {"chat_id" => chat_id, "message_id" => }) end |
#edit_message_text(chat_id:, message_id:, text:, reply_markup: nil) ⇒ Object
19 20 21 22 23 |
# File 'lib/chat_sdk/telegram/api_client.rb', line 19 def (chat_id:, message_id:, text:, reply_markup: nil) body = {"chat_id" => chat_id, "message_id" => , "text" => text, "parse_mode" => "Markdown"} body["reply_markup"] = reply_markup if reply_markup request(:post, "editMessageText", body) end |
#send_chat_action(chat_id:, action:) ⇒ Object
49 50 51 |
# File 'lib/chat_sdk/telegram/api_client.rb', line 49 def send_chat_action(chat_id:, action:) request(:post, "sendChatAction", {"chat_id" => chat_id, "action" => action}) end |
#send_document(chat_id:, document:, filename:, caption: nil, reply_to_message_id: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/chat_sdk/telegram/api_client.rb', line 29 def send_document(chat_id:, document:, filename:, caption: nil, reply_to_message_id: nil) payload = { "chat_id" => chat_id, "document" => Faraday::Multipart::FilePart.new(document, "application/octet-stream", filename) } payload["caption"] = caption if caption payload["reply_to_message_id"] = if response = upload_connection.post(api_path("sendDocument"), payload) handle_response(response) end |
#send_message(chat_id:, text:, reply_markup: nil, reply_to_message_id: nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/chat_sdk/telegram/api_client.rb', line 12 def (chat_id:, text:, reply_markup: nil, reply_to_message_id: nil) body = {"chat_id" => chat_id, "text" => text, "parse_mode" => "Markdown"} body["reply_markup"] = reply_markup if reply_markup body["reply_to_message_id"] = if request(:post, "sendMessage", body) end |
#set_message_reaction(chat_id:, message_id:, reaction:) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/chat_sdk/telegram/api_client.rb', line 41 def (chat_id:, message_id:, reaction:) request(:post, "setMessageReaction", { "chat_id" => chat_id, "message_id" => , "reaction" => reaction }) end |