8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/telegram_bot_builder/bot_api.rb', line 8
def self.parse(method, result)
data = JSON.parse(result)
case method
when 'getMe'
object = BotUser.new
object.id = data['result']['id']
object.first_name = data['result']['first_name']
object.username = data['result']['username']
return object
when 'sendMessage'
from = BotUser.new
from.id = data['result']['from']['id']
from.first_name = data['result']['from']['first_name']
from.last_name = data['result']['from']['last_name']
chat = BotUser.new
chat.id = data['result']['chat']['id']
chat.first_name = data['result']['chat']['first_name']
chat.last_name = data['result']['chat']['last_name']
chat.type = data['result']['chat']['type']
message = BotMessage.new
message.message_id = data['result']['message_id']
message.from = from
message.chat = chat
message.date = data['result']['date']
message.text = data['result']['text']
return message
when 'getUpdates'
result = []
data['result'].each do |item|
from = BotUser.new
from.id = item['message']['from']['id']
from.first_name = item['message']['from']['first_name']
from.last_name = item['message']['from']['last_name']
chat = BotUser.new
chat.id = item['message']['chat']['id']
chat.first_name = item['message']['chat']['first_name']
chat.last_name = item['message']['chat']['last_name']
chat.type = item['message']['chat']['type']
message = BotMessage.new
message.message_id = item['message']['message_id']
message.from = from
message.chat = chat
message.date = item['message']['date']
message.text = item['message']['text']
object = BotUpdate.new
object.update_id = item['update_id']
object.message = message
result << object
end
return result
when 'getWebhookInfo'
result = {
url: data['result']['url'],
has_custom_certificate: data['result']['has_custom_certificate'],
pending_update_count: data['result']['pending_update_count'],
last_error_date: data['result']['last_error_date'],
last_error_message: data['result']['last_error_message'],
}
return result
end
end
|