telegram_bot_builder 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b382e2b36a318617749e3b40cb80ee4f8731c724
4
+ data.tar.gz: 5276cdaba2165bdda0d6e1376edc3d1d1986754f
5
+ SHA512:
6
+ metadata.gz: 9f236f59e6ea14f80528edbbff95c991fbb748d808e6b27968296d6b03e4eb960b05e1bc0256d41a04344a982d19ac7b312d9d82b975eec2f0bfb9d2afd48108
7
+ data.tar.gz: ccdc355c0dff16eb5ad5c69256db8a3c10ce573286f4156e1fb92fb4e0f2bdcdba05faa4d3dce61c77890cf9bbff2c7d24bd8901765465364f9de7e028780a93
@@ -0,0 +1,5 @@
1
+ require 'telegram_bot_builder/bot_api'
2
+
3
+ module TelegramBotBuilder
4
+
5
+ end
@@ -0,0 +1,112 @@
1
+ require 'telegram_bot_builder/bot_user'
2
+ require 'telegram_bot_builder/bot_message'
3
+ require 'telegram_bot_builder/bot_updates'
4
+ require 'telegram_bot_builder/bot_update'
5
+ require 'telegram_bot_builder/bot_webhook'
6
+
7
+ class BotAPI
8
+ def self.parse(method, result)
9
+ data = JSON.parse(result)
10
+
11
+ case method
12
+ when 'getMe'
13
+ object = BotUser.new
14
+ object.id = data['result']['id']
15
+ object.first_name = data['result']['first_name']
16
+ object.username = data['result']['username']
17
+
18
+ return object
19
+ when 'sendMessage'
20
+ from = BotUser.new
21
+ from.id = data['result']['from']['id']
22
+ from.first_name = data['result']['from']['first_name']
23
+ from.last_name = data['result']['from']['last_name']
24
+
25
+ chat = BotUser.new
26
+ chat.id = data['result']['chat']['id']
27
+ chat.first_name = data['result']['chat']['first_name']
28
+ chat.last_name = data['result']['chat']['last_name']
29
+ chat.type = data['result']['chat']['type']
30
+
31
+ message = BotMessage.new
32
+ message.message_id = data['result']['message_id']
33
+ message.from = from
34
+ message.chat = chat
35
+ message.date = data['result']['date']
36
+ message.text = data['result']['text']
37
+
38
+ return message
39
+ when 'getUpdates'
40
+ result = []
41
+
42
+ data['result'].each do |item|
43
+ from = BotUser.new
44
+ from.id = item['message']['from']['id']
45
+ from.first_name = item['message']['from']['first_name']
46
+ from.last_name = item['message']['from']['last_name']
47
+
48
+ chat = BotUser.new
49
+ chat.id = item['message']['chat']['id']
50
+ chat.first_name = item['message']['chat']['first_name']
51
+ chat.last_name = item['message']['chat']['last_name']
52
+ chat.type = item['message']['chat']['type']
53
+
54
+ message = BotMessage.new
55
+ message.message_id = item['message']['message_id']
56
+ message.from = from
57
+ message.chat = chat
58
+ message.date = item['message']['date']
59
+ message.text = item['message']['text']
60
+
61
+ object = BotUpdate.new
62
+ object.update_id = item['update_id']
63
+ object.message = message
64
+
65
+ result << object
66
+ end
67
+
68
+ return result
69
+
70
+ when 'getWebhookInfo'
71
+ result = {
72
+ url: data['result']['url'],
73
+ has_custom_certificate: data['result']['has_custom_certificate'],
74
+ pending_update_count: data['result']['pending_update_count'],
75
+ last_error_date: data['result']['last_error_date'],
76
+ last_error_message: data['result']['last_error_message'],
77
+ }
78
+
79
+ return result
80
+ end
81
+ end
82
+
83
+ class Auth
84
+ def initialize
85
+ #return auth
86
+ end
87
+
88
+ def auth
89
+ method = 'getMe'
90
+
91
+ uri = URI.parse(URLBUIDER.build(method))
92
+ http = Net::HTTP.new(uri.host, uri.port)
93
+ http.use_ssl = true
94
+ result = http.get(uri.request_uri)
95
+
96
+ if result.code == "200"
97
+ object = BotAPI.parse(method, result.body)
98
+
99
+ return object
100
+ end
101
+ end
102
+ end
103
+
104
+ class URLBUIDER
105
+ APIKEY = '269321203:AAFFkICX0TmGL5KXn86Fkb6KPd6qMTieTJY'
106
+ BASEURL = 'https://api.telegram.org';
107
+
108
+ def self.build(method)
109
+ "#{BASEURL}/bot#{APIKEY}/#{method}"
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,83 @@
1
+ class BotMessage
2
+ attr_accessor :message_id
3
+ attr_accessor :from # is user object
4
+ attr_accessor :date
5
+ attr_accessor :chat # is user object
6
+ attr_accessor :forward_from
7
+ attr_accessor :forward_date
8
+ attr_accessor :reply_to_message
9
+ attr_accessor :text
10
+ attr_accessor :entities
11
+ attr_accessor :audio
12
+ attr_accessor :document
13
+ attr_accessor :photo
14
+ attr_accessor :sticker
15
+ attr_accessor :video
16
+ attr_accessor :voice
17
+ attr_accessor :caption
18
+ attr_accessor :contact
19
+ attr_accessor :location
20
+ attr_accessor :venue
21
+ attr_accessor :new_chat_member
22
+ attr_accessor :left_chat_member
23
+ attr_accessor :new_chat_little
24
+ attr_accessor :new_chat_photo
25
+ attr_accessor :delete_chat_photo
26
+ attr_accessor :group_chat_created
27
+ attr_accessor :supergroup_chat_created
28
+ attr_accessor :channel_chat_created
29
+ attr_accessor :migrate_to_chat_id
30
+ attr_accessor :migrate_from_chat_id
31
+ attr_accessor :pinned_message
32
+
33
+ # for message
34
+ attr_accessor :text
35
+ attr_accessor :parse_mode # :markdown, :html
36
+ attr_accessor :disable_web_page_preview # true/false
37
+ attr_accessor :disable_notification # true/false
38
+ attr_accessor :reply_to_message_id # if the message is a reply, ID of the original message
39
+ attr_accessor :reply_markup # keyboard interface for reply - :inline/:reply/:reply_hide/:force_reply
40
+
41
+ def send
42
+ method = 'sendMessage'
43
+ params = {
44
+ chat_id: chat.id,
45
+ text: text,
46
+ }
47
+
48
+ if parse_mode == :markdown
49
+ params[:parse_mode] = 'Markdown'
50
+ elsif parse_mode == :html
51
+ params[:parse_mode] = 'HTML'
52
+ end
53
+
54
+ if disable_web_page_preview != nil
55
+ params[:disable_web_page_preview] = disable_web_page_preview
56
+ end
57
+
58
+ if disable_notification != nil
59
+ params[:disable_notification] = disable_notification
60
+ end
61
+
62
+ if reply_markup == :inline
63
+ params[:reply_markup] = 'InlineKeyboardMarkup'
64
+ elsif reply_markup == :reply
65
+ params[:reply_markup] = 'ReplyKeyboardMarkup'
66
+ elsif reply_markup == :reply_hide
67
+ params[:reply_markup] = 'ReplyKeyboardHide'
68
+ elsif reply_markup == :force_reply
69
+ params[:reply_markup] = 'ForceReply'
70
+ end
71
+
72
+ uri = URI.parse(BotAPI::URLBUIDER.build(method))
73
+ http = Net::HTTP.new(uri.host, uri.port)
74
+ http.use_ssl = true
75
+ request = Net::HTTP::Post.new(uri.request_uri)
76
+ request.set_form_data(params)
77
+ result = http.request(request)
78
+
79
+ if result.code == "200"
80
+ return BotAPI.parse(method, result.body)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,6 @@
1
+ class BotUpdate
2
+ attr_accessor :update_id
3
+ attr_accessor :message
4
+ attr_accessor :date
5
+ attr_accessor :text
6
+ end
@@ -0,0 +1,34 @@
1
+ class BotUpdates
2
+ attr_accessor :offset
3
+ attr_accessor :limit
4
+ attr_accessor :timeout
5
+
6
+ def get
7
+ method = 'getUpdates'
8
+
9
+ params = {}
10
+
11
+ if offset != nil
12
+ params[:offset] = offset
13
+ end
14
+
15
+ if limit != nil
16
+ params[:limit] = limit
17
+ end
18
+
19
+ if timeout != nil
20
+ params[:timeout] = timeout
21
+ end
22
+
23
+ uri = URI.parse(BotAPI::URLBUIDER.build(method))
24
+ http = Net::HTTP.new(uri.host, uri.port)
25
+ http.use_ssl = true
26
+ request = Net::HTTP::Post.new(uri.request_uri)
27
+ request.set_form_data(params)
28
+ result = http.request(request)
29
+
30
+ if result.code == "200"
31
+ return BotAPI.parse(method, result.body)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ class BotUser
2
+ attr_accessor :id
3
+ attr_accessor :first_name
4
+ attr_accessor :last_name
5
+ attr_accessor :username
6
+ attr_accessor :type
7
+
8
+ def sendMessage(message)
9
+ message.chat = self
10
+
11
+ message.send
12
+ end
13
+ end
@@ -0,0 +1,46 @@
1
+ class BotWebhook
2
+ def setWebhook(url, certificate)
3
+ method = 'setWebhook'
4
+
5
+ params = {}
6
+
7
+ if url != nil && certificate != nil
8
+ params = {
9
+ url: url,
10
+ certificate: certificate
11
+ }
12
+ end
13
+
14
+ uri = URI.parse(BotAPI::URLBUIDER.build(method))
15
+ http = Net::HTTP.new(uri.host, uri.port)
16
+ http.use_ssl = true
17
+ request = Net::HTTP::Post.new(uri.request_uri)
18
+ request.set_form_data(params)
19
+ result = http.request(request)
20
+
21
+ p result
22
+
23
+ if result.code == '200'
24
+ return BotAPI.parse(method, result.body)
25
+ end
26
+ end
27
+
28
+ def deleteWebhook
29
+ setWebhook(nil, nil)
30
+ end
31
+
32
+ def getWebhook
33
+ method = 'getWebhookInfo'
34
+
35
+ uri = URI.parse(BotAPI::URLBUIDER.build(method))
36
+ http = Net::HTTP.new(uri.host, uri.port)
37
+ http.use_ssl = true
38
+ request = Net::HTTP::Post.new(uri.request_uri)
39
+
40
+ result = http.request(request)
41
+ p result
42
+ if result.code == '200'
43
+ return BotAPI.parse(method, result.body)
44
+ end
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: telegram_bot_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Artur Khidirnabiev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: telegram bot sdk
14
+ email: artur.khidirnabiev@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/telegram_bot_builder.rb
20
+ - lib/telegram_bot_builder/bot_api.rb
21
+ - lib/telegram_bot_builder/bot_message.rb
22
+ - lib/telegram_bot_builder/bot_update.rb
23
+ - lib/telegram_bot_builder/bot_updates.rb
24
+ - lib/telegram_bot_builder/bot_user.rb
25
+ - lib/telegram_bot_builder/bot_webhook.rb
26
+ homepage: http://rubygems.org/gems/telegram_bot_builder
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.6.3
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Telegram Bot Builder
50
+ test_files: []
51
+ has_rdoc: