Class: TelegramAPI
- Inherits:
-
Object
- Object
- TelegramAPI
- Defined in:
- lib/telegramAPI.rb
Overview
This library provides an easy way to access to the Telegram Bot API
- Author
-
Benedetto Nespoli
- License
-
MIT
Constant Summary collapse
- @@core =
"https://api.telegram.org/bot"
Instance Method Summary collapse
- #answerInlineQuery(inline_query_id, results) ⇒ Object
- #forwardMessage(to, from, msg) ⇒ Object
- #getChat(chat_id) ⇒ Object
- #getChatAdministrators(chat_id) ⇒ Object
- #getChatMember(chat_id, user_id) ⇒ Object
- #getChatMembersCount(chat_id) ⇒ Object
- #getFile(file_id) ⇒ Object
- #getMe ⇒ Object
- #getUpdates(options = {"timeout"=>0, "limit"=>100}) ⇒ Object
- #getUserProfilePhotos(id, options = {}) ⇒ Object
-
#initialize(token) ⇒ TelegramAPI
constructor
A new instance of TelegramAPI.
- #kickChatMember(chat_id, user_id) ⇒ Object
- #leaveChat(chat_id) ⇒ Object
- #sendAudio(to, path, options = {}) ⇒ Object
-
#sendChatAction(to, act) ⇒ Object
act is one between: typing, upload_photo, record_video, record_audio, upload_audio, upload_document, find_location.
- #sendContact(to, phone_number, first_name, options = {}) ⇒ Object
- #sendDocument(to, path, options = {}) ⇒ Object
- #sendLocation(to, lat, long, options = {}) ⇒ Object
- #sendMessage(to, text, options = {}) ⇒ Object
- #sendPhoto(to, path, options = {}) ⇒ Object
- #sendSticker(to, id, options = {}) ⇒ Object
- #sendStickerFromFile(to, path, options = {}) ⇒ Object
- #sendVenue(to, lat, long, title, address, options = {}) ⇒ Object
- #sendVideo(to, path, options = {}) ⇒ Object
- #sendVoice(to, path, options = {}) ⇒ Object
- #setWebhook(url) ⇒ Object
- #unbanChatMember(chat_id, user_id) ⇒ Object
Constructor Details
#initialize(token) ⇒ TelegramAPI
Returns a new instance of TelegramAPI.
14 15 16 17 |
# File 'lib/telegramAPI.rb', line 14 def initialize token @token = token @last_update = 0 end |
Instance Method Details
#answerInlineQuery(inline_query_id, results) ⇒ Object
141 142 143 |
# File 'lib/telegramAPI.rb', line 141 def answerInlineQuery inline_query_id, results self.query("answerInlineQuery", {:inline_query_id=>inline_query_id, :results=>JSON.dump(results)}) end |
#forwardMessage(to, from, msg) ⇒ Object
56 57 58 |
# File 'lib/telegramAPI.rb', line 56 def forwardMessage to, from, msg self.query("forwardMessage", {:chat_id=>to, :from_chat_id=>from, :message_id=>msg}) end |
#getChat(chat_id) ⇒ Object
125 126 127 |
# File 'lib/telegramAPI.rb', line 125 def getChat chat_id self.query("getChat", {:chat_id=>chat_id}) end |
#getChatAdministrators(chat_id) ⇒ Object
129 130 131 |
# File 'lib/telegramAPI.rb', line 129 def getChatAdministrators chat_id self.query("getChatAdministrators", {:chat_id=>chat_id}) end |
#getChatMember(chat_id, user_id) ⇒ Object
137 138 139 |
# File 'lib/telegramAPI.rb', line 137 def getChatMember chat_id, user_id self.query("getChatMember", {:chat_id=>chat_id, :user_id=>user_id}) end |
#getChatMembersCount(chat_id) ⇒ Object
133 134 135 |
# File 'lib/telegramAPI.rb', line 133 def getChatMembersCount chat_id self.query("getChatMembersCount", {:chat_id=>chat_id}) end |
#getFile(file_id) ⇒ Object
109 110 111 |
# File 'lib/telegramAPI.rb', line 109 def getFile file_id self.query("getFile", {:file_id=>file_id}) end |
#getMe ⇒ Object
45 46 47 |
# File 'lib/telegramAPI.rb', line 45 def getMe self.query("getMe") end |
#getUpdates(options = {"timeout"=>0, "limit"=>100}) ⇒ Object
41 42 43 |
# File 'lib/telegramAPI.rb', line 41 def getUpdates ={"timeout"=>0, "limit"=>100} self.query("getUpdates", {"offset"=>@last_update.to_s}.merge(parse_hash())) end |
#getUserProfilePhotos(id, options = {}) ⇒ Object
105 106 107 |
# File 'lib/telegramAPI.rb', line 105 def getUserProfilePhotos id, ={} self.query("getUserProfilePhotos", {:user_id=>id}.merge(parse_hash())) end |
#kickChatMember(chat_id, user_id) ⇒ Object
113 114 115 |
# File 'lib/telegramAPI.rb', line 113 def kickChatMember chat_id, user_id self.query("kickChatMember", {:chat_id=>chat_id, :user_id=>user_id}) end |
#leaveChat(chat_id) ⇒ Object
117 118 119 |
# File 'lib/telegramAPI.rb', line 117 def leaveChat chat_id self.query("leaveChat", {:chat_id=>chat_id}) end |
#sendAudio(to, path, options = {}) ⇒ Object
64 65 66 |
# File 'lib/telegramAPI.rb', line 64 def sendAudio to, path, ={} self.post("/sendAudio", :audio, path, to, ) end |
#sendChatAction(to, act) ⇒ Object
act is one between: typing, upload_photo, record_video, record_audio, upload_audio, upload_document, find_location
101 102 103 |
# File 'lib/telegramAPI.rb', line 101 def sendChatAction to, act self.query("sendChatAction", {:chat_id=>to, :action=>act}) end |
#sendContact(to, phone_number, first_name, options = {}) ⇒ Object
96 97 98 |
# File 'lib/telegramAPI.rb', line 96 def sendContact to, phone_number, first_name, ={} self.query("sendContact", {:chat_id=>to, :phone_number=>phone_number, :first_name=>first_name}.merge(parse_hash())) end |
#sendDocument(to, path, options = {}) ⇒ Object
68 69 70 |
# File 'lib/telegramAPI.rb', line 68 def sendDocument to, path, ={} self.post("/sendDocument", :document, path, to, ) end |
#sendLocation(to, lat, long, options = {}) ⇒ Object
88 89 90 |
# File 'lib/telegramAPI.rb', line 88 def sendLocation to, lat, long, ={} self.query("sendLocation", {:chat_id=>to, :latitude=>lat, :longitude=>long}.merge(parse_hash())) end |
#sendMessage(to, text, options = {}) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/telegramAPI.rb', line 49 def sendMessage to, text, ={} if .has_key?"reply_markup" then ["reply_markup"]=["reply_markup"].to_json end self.query("sendMessage", {:chat_id=>to.to_s, :text=>text}.merge(parse_hash())) end |
#sendPhoto(to, path, options = {}) ⇒ Object
60 61 62 |
# File 'lib/telegramAPI.rb', line 60 def sendPhoto to, path, ={} self.post("/sendPhoto", :photo, path, to, ) end |
#sendSticker(to, id, options = {}) ⇒ Object
76 77 78 |
# File 'lib/telegramAPI.rb', line 76 def sendSticker to, id, ={} RestClient.post(@@core+@token+"/sendSticker", {:sticker=>id, :chat_id=>to.to_s}.merge(parse_hash())).body end |
#sendStickerFromFile(to, path, options = {}) ⇒ Object
72 73 74 |
# File 'lib/telegramAPI.rb', line 72 def sendStickerFromFile to, path, ={} self.post("/sendSticker", :sticker, path, to, ) end |
#sendVenue(to, lat, long, title, address, options = {}) ⇒ Object
92 93 94 |
# File 'lib/telegramAPI.rb', line 92 def sendVenue to, lat, long, title, address, ={} self.query("sendVenue", {:chat_id=>to, :latitude=>lat, :longitude=>long, :title=>title, :address=>address}.merge(parse_hash())) end |
#sendVideo(to, path, options = {}) ⇒ Object
80 81 82 |
# File 'lib/telegramAPI.rb', line 80 def sendVideo to, path, ={} self.post("/sendVideo", :video, path, to, ) end |
#sendVoice(to, path, options = {}) ⇒ Object
84 85 86 |
# File 'lib/telegramAPI.rb', line 84 def sendVoice to, path, ={} self.post("/sendVoice", :voice, path, to, ) end |
#setWebhook(url) ⇒ Object
37 38 39 |
# File 'lib/telegramAPI.rb', line 37 def setWebhook url self.query("setWebhook", {"url"=>URI::encode(url)}) end |
#unbanChatMember(chat_id, user_id) ⇒ Object
121 122 123 |
# File 'lib/telegramAPI.rb', line 121 def unbanChatMember chat_id, user_id self.query("unbanChatMember", {:chat_id=>chat_id, :user_id=>user_id}) end |