telegram-bot-ruby 2.8.0 → 2.9.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 +4 -4
- data/.agents/skills/commit/SKILL.md +18 -0
- data/.agents/skills/update-api/SKILL.md +70 -0
- data/.claude/skills +1 -0
- data/.rubocop.yml +0 -14
- data/CHANGELOG.md +22 -0
- data/README.md +17 -3
- data/lib/telegram/bot/api/endpoints.rb +9 -0
- data/lib/telegram/bot/api.rb +1 -1
- data/lib/telegram/bot/types/area_position.rb +16 -0
- data/lib/telegram/bot/types/chat_administrator_rights.rb +1 -0
- data/lib/telegram/bot/types/chat_full_info.rb +2 -0
- data/lib/telegram/bot/types/chat_member_administrator.rb +1 -0
- data/lib/telegram/bot/types/chat_share_theme.rb +15 -0
- data/lib/telegram/bot/types/chat_share_theme_backdrop.rb +13 -0
- data/lib/telegram/bot/types/chat_share_theme_backdrops.rb +11 -0
- data/lib/telegram/bot/types/chat_share_theme_emoji.rb +13 -0
- data/lib/telegram/bot/types/chat_share_theme_unique_gift.rb +12 -0
- data/lib/telegram/bot/types/community_chat_joined.rb +11 -0
- data/lib/telegram/bot/types/disabled_button.rb +10 -0
- data/lib/telegram/bot/types/emoji_type.rb +15 -0
- data/lib/telegram/bot/types/emoji_type_custom_emoji.rb +12 -0
- data/lib/telegram/bot/types/emoji_type_emoji.rb +12 -0
- data/lib/telegram/bot/types/ephemeral_message_parameters.rb +13 -0
- data/lib/telegram/bot/types/external_reply_info.rb +1 -0
- data/lib/telegram/bot/types/game.rb +1 -1
- data/lib/telegram/bot/types/inline_keyboard_button.rb +1 -0
- data/lib/telegram/bot/types/inline_keyboard_markup.rb +1 -0
- data/lib/telegram/bot/types/input_checklist.rb +1 -1
- data/lib/telegram/bot/types/input_checklist_task.rb +1 -1
- data/lib/telegram/bot/types/input_message_content.rb +3 -1
- data/lib/telegram/bot/types/input_rich_block.rb +3 -0
- data/lib/telegram/bot/types/input_rich_block_buttons.rb +13 -0
- data/lib/telegram/bot/types/input_rich_block_document.rb +13 -0
- data/lib/telegram/bot/types/input_rich_block_expandable_block_quotation.rb +13 -0
- data/lib/telegram/bot/types/input_rich_block_map.rb +3 -3
- data/lib/telegram/bot/types/input_rich_block_table.rb +1 -0
- data/lib/telegram/bot/types/input_rich_message_media.rb +2 -1
- data/lib/telegram/bot/types/input_shared_widget_message_content.rb +16 -0
- data/lib/telegram/bot/types/input_widget_message_content.rb +21 -0
- data/lib/telegram/bot/types/message.rb +4 -0
- data/lib/telegram/bot/types/message_generation_stopped.rb +13 -0
- data/lib/telegram/bot/types/paid_messages_waived.rb +10 -0
- data/lib/telegram/bot/types/poll.rb +1 -1
- data/lib/telegram/bot/types/reply_keyboard_markup.rb +1 -0
- data/lib/telegram/bot/types/reply_parameters.rb +1 -0
- data/lib/telegram/bot/types/rich_block.rb +3 -0
- data/lib/telegram/bot/types/rich_block_buttons.rb +13 -0
- data/lib/telegram/bot/types/rich_block_document.rb +13 -0
- data/lib/telegram/bot/types/rich_block_expandable_block_quotation.rb +13 -0
- data/lib/telegram/bot/types/rich_block_table.rb +1 -0
- data/lib/telegram/bot/types/rich_message_button.rb +21 -0
- data/lib/telegram/bot/types/rich_text.rb +4 -0
- data/lib/telegram/bot/types/rich_text_button.rb +12 -0
- data/lib/telegram/bot/types/rich_text_ton_address.rb +13 -0
- data/lib/telegram/bot/types/shared_widget_query.rb +15 -0
- data/lib/telegram/bot/types/story_area.rb +1 -1
- data/lib/telegram/bot/types/text_quote.rb +1 -0
- data/lib/telegram/bot/types/ton_nft.rb +17 -0
- data/lib/telegram/bot/types/ton_nft_attribute.rb +12 -0
- data/lib/telegram/bot/types/ton_wallet_card.rb +14 -0
- data/lib/telegram/bot/types/ton_wallet_card_sticker.rb +12 -0
- data/lib/telegram/bot/types/ton_wallet_transfer.rb +14 -0
- data/lib/telegram/bot/types/unique_gift_info.rb +3 -0
- data/lib/telegram/bot/types/update.rb +3 -0
- data/lib/telegram/bot/types/widget.rb +16 -0
- data/lib/telegram/bot/types/widget_query.rb +20 -0
- data/lib/telegram/bot/types/widget_query_type.rb +16 -0
- data/lib/telegram/bot/types/widget_query_type_data.rb +12 -0
- data/lib/telegram/bot/types/widget_query_type_sent_transaction.rb +13 -0
- data/lib/telegram/bot/types/widget_query_type_sign_data.rb +13 -0
- data/lib/telegram/bot/types/widget_query_wallet.rb +14 -0
- data/lib/telegram/bot/version.rb +1 -1
- data/rakelib/README.md +116 -0
- data/rakelib/builders/type_builder.rb +11 -5
- data/rakelib/docs.rake +15 -0
- data/rakelib/parse.rake +8 -25
- data/rakelib/parsers/api_method.rb +26 -0
- data/rakelib/parsers/description.rb +62 -0
- data/rakelib/parsers/docs_page.rb +62 -0
- data/rakelib/parsers/entry.rb +45 -0
- data/rakelib/parsers/entry_grammar.rb +48 -0
- data/rakelib/parsers/error.rb +5 -0
- data/rakelib/parsers/field.rb +30 -0
- data/rakelib/parsers/object_type.rb +29 -0
- data/rakelib/parsers/page_object.rb +41 -0
- data/rakelib/parsers/readers.rb +16 -0
- data/rakelib/parsers/return_type.rb +36 -0
- data/rakelib/parsers/serializer.rb +93 -0
- data/rakelib/parsers/table.rb +14 -0
- data/rakelib/parsers/type_ref.rb +42 -0
- data/rakelib/parsers/union_type.rb +42 -0
- metadata +60 -5
- data/.claude/skills/update-api/SKILL.md +0 -70
- data/rakelib/parsers/methods_parser.rb +0 -115
- data/rakelib/parsers/types_parser.rb +0 -273
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'nokogiri'
|
|
4
|
-
require 'net/http'
|
|
5
|
-
|
|
6
|
-
module Parsers
|
|
7
|
-
class TypesParser
|
|
8
|
-
API_URL = 'https://core.telegram.org/bots/api'
|
|
9
|
-
|
|
10
|
-
PRIMITIVE_TYPES = {
|
|
11
|
-
'String' => 'string',
|
|
12
|
-
'Integer' => 'integer',
|
|
13
|
-
'Boolean' => 'boolean',
|
|
14
|
-
'Float' => 'number',
|
|
15
|
-
'True' => 'boolean'
|
|
16
|
-
}.freeze
|
|
17
|
-
|
|
18
|
-
def parse
|
|
19
|
-
doc = fetch_document
|
|
20
|
-
result = {}
|
|
21
|
-
|
|
22
|
-
type_headers(doc).each do |header|
|
|
23
|
-
type_name = extract_type_name(header)
|
|
24
|
-
next unless type_name
|
|
25
|
-
|
|
26
|
-
type_data = parse_type(header, type_name)
|
|
27
|
-
result[type_name] = type_data if type_data
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
result
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
private
|
|
34
|
-
|
|
35
|
-
def fetch_document
|
|
36
|
-
uri = URI.parse(API_URL)
|
|
37
|
-
response = Net::HTTP.get(uri)
|
|
38
|
-
Nokogiri::HTML(response)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def type_headers(doc)
|
|
42
|
-
doc.css('h4')
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def extract_type_name(header)
|
|
46
|
-
name = header.text.strip
|
|
47
|
-
# Types start with uppercase letter (CapitalCase)
|
|
48
|
-
# Methods start with lowercase (camelCase) - skip those
|
|
49
|
-
return nil unless name.match?(/\A[A-Z][a-zA-Z0-9]*\z/)
|
|
50
|
-
|
|
51
|
-
name
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def parse_type(header, _type_name)
|
|
55
|
-
# Check if this is a union type (list of types without a table)
|
|
56
|
-
next_sibling = find_next_significant_sibling(header)
|
|
57
|
-
|
|
58
|
-
if union_type?(next_sibling)
|
|
59
|
-
parse_union_type(next_sibling)
|
|
60
|
-
else
|
|
61
|
-
parse_table_type(header)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def find_next_significant_sibling(header)
|
|
66
|
-
sibling = header.next_element
|
|
67
|
-
# Skip description paragraphs
|
|
68
|
-
sibling = sibling.next_element while sibling && sibling.name == 'p'
|
|
69
|
-
sibling
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def union_type?(element)
|
|
73
|
-
element&.name == 'ul'
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def parse_union_type(ul_element)
|
|
77
|
-
types = ul_element.css('li a').map { |a| a.text.strip }
|
|
78
|
-
{ 'type' => types }
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def parse_table_type(header)
|
|
82
|
-
table = find_attribute_table(header)
|
|
83
|
-
return {} unless table
|
|
84
|
-
|
|
85
|
-
attributes = {}
|
|
86
|
-
table.css('tbody tr').each do |row|
|
|
87
|
-
cells = row.css('td')
|
|
88
|
-
next unless cells.length >= 3
|
|
89
|
-
|
|
90
|
-
field_name = cells[0].text.strip
|
|
91
|
-
type_info = cells[1]
|
|
92
|
-
description_cell = cells[2]
|
|
93
|
-
|
|
94
|
-
attributes[field_name] = parse_attribute(type_info, description_cell)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
attributes
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def find_attribute_table(header)
|
|
101
|
-
sibling = header.next_element
|
|
102
|
-
while sibling
|
|
103
|
-
return sibling if sibling.name == 'table'
|
|
104
|
-
# Stop if we hit another h4 (next type/method)
|
|
105
|
-
break if sibling.name == 'h4'
|
|
106
|
-
|
|
107
|
-
sibling = sibling.next_element
|
|
108
|
-
end
|
|
109
|
-
nil
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def parse_attribute(type_cell, description_cell)
|
|
113
|
-
attribute = {}
|
|
114
|
-
raw_type = type_cell.text.strip
|
|
115
|
-
description = description_cell.text.strip
|
|
116
|
-
description_html = description_cell.inner_html
|
|
117
|
-
|
|
118
|
-
# Parse type
|
|
119
|
-
type_value = parse_type_value(type_cell)
|
|
120
|
-
if type_value.is_a?(Hash)
|
|
121
|
-
attribute.merge!(type_value)
|
|
122
|
-
else
|
|
123
|
-
attribute['type'] = type_value
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
# Parse required (absence of "Optional" at start of description)
|
|
127
|
-
attribute['required'] = true unless description.start_with?('Optional')
|
|
128
|
-
|
|
129
|
-
# Parse required_value (always "X" or must be <em>X</em>)
|
|
130
|
-
required_value = extract_required_value(description, description_html)
|
|
131
|
-
if required_value
|
|
132
|
-
attribute['required_value'] = required_value
|
|
133
|
-
attribute['default'] = required_value
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
# Parse size constraints (N-M characters or must be between)
|
|
137
|
-
min_size, max_size = extract_size_constraints(description)
|
|
138
|
-
attribute['min_size'] = min_size if min_size
|
|
139
|
-
attribute['max_size'] = max_size if max_size
|
|
140
|
-
|
|
141
|
-
# Parse default value (Defaults to X)
|
|
142
|
-
# If HTML type is 'True' (not 'Boolean'), it means the field only exists when true
|
|
143
|
-
if raw_type == 'True' && !attribute.key?('default')
|
|
144
|
-
attribute['default'] = true
|
|
145
|
-
elsif !attribute.key?('default')
|
|
146
|
-
default = extract_default_value(description, description_html, attribute['type'])
|
|
147
|
-
attribute['default'] = default unless default.nil?
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
# Clean up: remove required if false
|
|
151
|
-
attribute.delete('required') unless attribute['required']
|
|
152
|
-
|
|
153
|
-
attribute
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def parse_type_value(type_cell)
|
|
157
|
-
text = type_cell.text.strip
|
|
158
|
-
links = type_cell.css('a')
|
|
159
|
-
|
|
160
|
-
# Check for "Array of X"
|
|
161
|
-
if text.start_with?('Array of')
|
|
162
|
-
items_type = parse_array_items(type_cell, text)
|
|
163
|
-
return { 'type' => 'array', 'items' => items_type }
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
# Check for union type "X or Y"
|
|
167
|
-
if text.include?(' or ')
|
|
168
|
-
types = parse_union_types(type_cell, text)
|
|
169
|
-
return types.length == 1 ? normalize_type(types.first) : types.map { |t| normalize_type(t) }
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
# Single type
|
|
173
|
-
if links.any?
|
|
174
|
-
normalize_type(links.first.text.strip)
|
|
175
|
-
else
|
|
176
|
-
normalize_type(text)
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
def parse_array_items(type_cell, text)
|
|
181
|
-
# Handle "Array of Array of X"
|
|
182
|
-
if text.include?('Array of Array of')
|
|
183
|
-
inner_type = type_cell.css('a').last&.text&.strip || text.split('Array of Array of').last.strip
|
|
184
|
-
return { 'type' => 'array', 'items' => normalize_type(inner_type) }
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
# Regular "Array of X"
|
|
188
|
-
link = type_cell.css('a').first
|
|
189
|
-
if link
|
|
190
|
-
normalize_type(link.text.strip)
|
|
191
|
-
else
|
|
192
|
-
# Primitive array like "Array of String"
|
|
193
|
-
items_text = text.sub('Array of ', '').strip
|
|
194
|
-
normalize_type(items_text)
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
def parse_union_types(type_cell, text)
|
|
199
|
-
links = type_cell.css('a')
|
|
200
|
-
if links.any?
|
|
201
|
-
links.map { |l| l.text.strip }
|
|
202
|
-
else
|
|
203
|
-
text.split(' or ').map(&:strip)
|
|
204
|
-
end
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
def normalize_type(type)
|
|
208
|
-
PRIMITIVE_TYPES[type] || type
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def extract_required_value(description, description_html)
|
|
212
|
-
# Pattern: always "X" or always "X" (smart quotes)
|
|
213
|
-
match = description.match(/always ["\u201c]([^"\u201d]+)["\u201d]/i)
|
|
214
|
-
return match[1].delete('\\') if match
|
|
215
|
-
|
|
216
|
-
# Pattern: must be <em>X</em> (check inner HTML)
|
|
217
|
-
match = description_html.match(%r{must be <em>([^<]+)</em>}i)
|
|
218
|
-
return match[1] if match
|
|
219
|
-
|
|
220
|
-
nil
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
def extract_size_constraints(description)
|
|
224
|
-
min_size = nil
|
|
225
|
-
max_size = nil
|
|
226
|
-
|
|
227
|
-
# Pattern: N-M characters (covers 0-N and 1-N cases)
|
|
228
|
-
if (match = description.match(/(\d+)-(\d+) characters/))
|
|
229
|
-
min_val = match[1].to_i
|
|
230
|
-
max_size = match[2].to_i
|
|
231
|
-
min_size = min_val if min_val.positive?
|
|
232
|
-
# Pattern: must be between N and M
|
|
233
|
-
elsif (match = description.match(/must be between (\d+) and (\d+)/))
|
|
234
|
-
min_size = match[1].to_i
|
|
235
|
-
max_size = match[2].to_i
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
[min_size, max_size]
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
def extract_default_value(description, description_html, type)
|
|
242
|
-
# Pattern: Defaults to "X" (with smart quotes U+201C/U+201D)
|
|
243
|
-
if (match = description.match(/Defaults to \u201c([^\u201d]+)\u201d/i))
|
|
244
|
-
return cast_default_value(match[1], type)
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
# Pattern: Defaults to <em>X</em> (check inner HTML for em-wrapped values)
|
|
248
|
-
if (match = description_html.match(%r{Defaults to <em>([^<]+)</em>}i))
|
|
249
|
-
return cast_default_value(match[1], type)
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
# Pattern: Defaults to <number> (plain numeric values)
|
|
253
|
-
if (match = description.match(/Defaults to (\d+)/i))
|
|
254
|
-
return cast_default_value(match[1], type)
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
nil
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
def cast_default_value(value, type)
|
|
261
|
-
case type
|
|
262
|
-
when 'integer'
|
|
263
|
-
value.to_i
|
|
264
|
-
when 'boolean'
|
|
265
|
-
value.downcase == 'true'
|
|
266
|
-
when 'number'
|
|
267
|
-
value.to_f
|
|
268
|
-
else
|
|
269
|
-
value
|
|
270
|
-
end
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
end
|