dialog_ruby 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/Gemfile +0 -0
  4. data/_dev/get_full_botapi.rb +59 -0
  5. data/_dev/inlinekb_pubsub.rb +69 -0
  6. data/_dev/main.rb +127 -0
  7. data/_dev/restriction.rb +32 -0
  8. data/_dev/ru.yml +79 -0
  9. data/_dev/sidekiq.rb +28 -0
  10. data/_dev/tdlib.rb +154 -0
  11. data/dialog.sh +51 -0
  12. data/dialog_ruby.gemspec +41 -0
  13. data/lib/architecture.md +22 -0
  14. data/lib/configuration.rb +117 -0
  15. data/lib/dialogStart.rb +189 -0
  16. data/lib/dialog_ruby.rb +59 -0
  17. data/lib/exec.sh +61 -0
  18. data/lib/exec_conf/cli_config +7 -0
  19. data/lib/exec_conf/dialog__sync.service +14 -0
  20. data/lib/exec_conf/dialog__sync.timer +11 -0
  21. data/lib/exec_conf/dialog_bot@.path +6 -0
  22. data/lib/exec_conf/dialog_bot@.service +18 -0
  23. data/lib/exec_conf/dialog_bot_dev@.path +6 -0
  24. data/lib/exec_conf/dialog_bot_dev_pre@.service +16 -0
  25. data/lib/exec_conf/dialog_bot_pre@.service +16 -0
  26. data/lib/exec_conf/dialog_redis@.service +14 -0
  27. data/lib/exec_conf/post-merge +5 -0
  28. data/lib/exec_conf/redis_global.conf +49 -0
  29. data/lib/exec_conf/redis_local.conf +4 -0
  30. data/lib/lang/global_ru.yml +29 -0
  31. data/lib/lib/dialect/canvas/canvas.rb +35 -0
  32. data/lib/lib/dialect/canvas/element/convert/SearchBaloo.rb +45 -0
  33. data/lib/lib/dialect/canvas/element/data/search.rb +34 -0
  34. data/lib/lib/dialect/canvas/element/send/Inline_query_result.rb +32 -0
  35. data/lib/lib/dialect/canvas/element/send/bot_message.rb +38 -0
  36. data/lib/lib/dialect/canvas/element/send/keyboards.rb +59 -0
  37. data/lib/lib/dialect/canvas/element/send/recognize.rb +51 -0
  38. data/lib/lib/dialect/canvas/element/send/restrict.rb +42 -0
  39. data/lib/lib/dialect/canvas/element/send/tdlib_chat.rb +33 -0
  40. data/lib/lib/dialect/canvas/element/send/tdlib_message.rb +38 -0
  41. data/lib/lib/dialect/canvas/mod/send/_Inline_query_result.rb +38 -0
  42. data/lib/lib/dialect/canvas/mod/send/_keyboards.rb +40 -0
  43. data/lib/lib/dialect/canvas/mod/send/func.rb +98 -0
  44. data/lib/lib/dialect/canvas/mod/send/general/_heads.rb +27 -0
  45. data/lib/lib/dialect/canvas/mod/send/general/chat.rb +38 -0
  46. data/lib/lib/dialect/canvas/mod/send/general/common.rb +32 -0
  47. data/lib/lib/dialect/canvas/mod/send/general/message.rb +37 -0
  48. data/lib/lib/dialect/canvas/mod/send/general/user.rb +36 -0
  49. data/lib/lib/dialect/canvas/mod/send/inline_query_result/common.rb +36 -0
  50. data/lib/lib/dialect/codegen/codegen.rb +74 -0
  51. data/lib/lib/dialect/codegen/erb/data/1.ModReceive2GetData.erb +27 -0
  52. data/lib/lib/dialect/codegen/erb/data/2.GetData2Elements.erb +27 -0
  53. data/lib/lib/dialect/codegen/erb/data/3.GenData2Dest.erb +34 -0
  54. data/lib/lib/dialect/codegen/erb/functional/1.Expect2Events.erb +37 -0
  55. data/lib/lib/dialect/codegen/erb/functional/2.1.Events2AppEvent.erb +26 -0
  56. data/lib/lib/dialect/codegen/erb/functional/2.2.1.Events2ModReceive.erb +73 -0
  57. data/lib/lib/dialect/codegen/erb/functional/2.2.2.ModReceive2AppEvent.erb +59 -0
  58. data/lib/lib/dialect/codegen/erb/functional/3.Appevent2EventBus.erb +35 -0
  59. data/lib/lib/dialect/codegen/erb/functional/4.1.AppEvent2Elements.erb +72 -0
  60. data/lib/lib/dialect/codegen/erb/functional/5.1.Element2ModElements.erb +70 -0
  61. data/lib/lib/dialect/codegen/erb/functional/5.2.Element2ModSend.erb +69 -0
  62. data/lib/lib/dialect/codegen/erb/functional/7.ElementChains.erb +91 -0
  63. data/lib/lib/dialect/codegen/repack/constructor/DockedGroupings2AppFunctions.rb +36 -0
  64. data/lib/lib/dialect/codegen/repack/constructor/Element2ModSend.rb +49 -0
  65. data/lib/lib/dialect/codegen/repack/constructor/ElementsInElements.rb +34 -0
  66. data/lib/lib/dialect/codegen/repack/functional/1.Expect2Events.rb +35 -0
  67. data/lib/lib/dialect/codegen/repack/functional/2.2.1.Events2ModReceive.rb +71 -0
  68. data/lib/lib/dialect/codegen/repack/functional/2.2.2.ModReceive2AppEvent.rb +45 -0
  69. data/lib/lib/dialect/codegen/repack/functional/5.1.Element2ModElements.rb +90 -0
  70. data/lib/lib/dialect/codegen/repack/functional/5.2.Element2ModSend.rb +60 -0
  71. data/lib/lib/dialect/codegen/repack/functional/7.ElementChains.rb +88 -0
  72. data/lib/lib/dialect/codegen/run.rb +79 -0
  73. data/lib/lib/metamess/_run.rb +162 -0
  74. data/lib/lib/metamess/content/content_o-command_f.rb +100 -0
  75. data/lib/lib/metamess/content/content_o-media_f.rb +149 -0
  76. data/lib/lib/metamess/content/content_o-simple_f.rb +35 -0
  77. data/lib/lib/metamess/content/content_o.rb +245 -0
  78. data/lib/lib/metamess/event/notify_o-chatmember_f.rb +124 -0
  79. data/lib/lib/metamess/event/notify_o-chattitle_f.rb +34 -0
  80. data/lib/lib/metamess/event/notify_o-create_f.rb +42 -0
  81. data/lib/lib/metamess/event/notify_o-migrate_f.rb +34 -0
  82. data/lib/lib/metamess/event/notify_o-pinned_f.rb +34 -0
  83. data/lib/lib/metamess/event/notify_o.rb +28 -0
  84. data/lib/lib/metamess/event_c.rb +26 -0
  85. data/lib/lib/metamess/func.rb +220 -0
  86. data/lib/lib/metamess/service/service_o-callback_f.rb +33 -0
  87. data/lib/lib/metamess/service/service_o-inline_f.rb +55 -0
  88. data/lib/lib/metamess/service/service_o.rb +26 -0
  89. data/lib/lib/naming.rb +130 -0
  90. data/lib/lib/storage/redis/redisPubSub.rb +51 -0
  91. data/lib/lib/storage/redis/rediscached.rb +97 -0
  92. data/lib/lib/tdlib/auth.rb +141 -0
  93. data/lib/lib/tdlib/func.rb +34 -0
  94. data/lib/lib/tdlib/init.rb +39 -0
  95. data/lib/lib/telegram/botapi.rb +71 -0
  96. data/lib/lib/telegram/infra_info.rb +50 -0
  97. data/lib/lib/telegram/wrappers.rb +41 -0
  98. data/lib/lib/tooling/lang.rb +24 -0
  99. data/lib/lib/tooling/log.rb +54 -0
  100. data/lib/lib/tooling/ruby.rb +25 -0
  101. data/lib/version.rb +3 -0
  102. data/logo.png +0 -0
  103. metadata +305 -0
data/lib/lib/naming.rb ADDED
@@ -0,0 +1,130 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 2 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+
13
+ module Dialog; module Naming;
14
+ module ChatContext
15
+ def ChatContext.Private; 'Private'; end
16
+ def ChatContext.Noman; 'Noman'; end
17
+ def ChatContext.Botman; 'Botman'; end
18
+ def ChatContext.Climan; 'Climan'; end
19
+ def ChatContext.Fullman; 'Fullman'; end
20
+ end
21
+
22
+ module Class
23
+
24
+ def Class.Event; 'event'; end
25
+ module Event; module Order
26
+
27
+ def Order.Content; 'content'; end
28
+ module Content; module Type
29
+ def Type.Original; 'original'; end
30
+ def Type.Edit; 'edit'; end
31
+ def Type.Reply; 'reply'; end
32
+ def Type.Forward; 'forward'; end
33
+ end; end;
34
+
35
+ module Content; module Family
36
+ def Family.Media; 'media'; end
37
+ module Media; module Genus
38
+ def Genus.Photo; 'photo'; end
39
+ def Genus.Document; 'document'; end
40
+ def Genus.Voice; 'voice'; end
41
+ def Genus.Audio; 'audio'; end
42
+ def Genus.Video; 'video'; end
43
+ def Genus.Videonote; 'videonote'; end
44
+ def Genus.Sticker; 'sticker'; end
45
+ end; end
46
+
47
+ def Family.Command; 'command'; end
48
+ module Command; module Genus
49
+ def Genus.Telegram; 'telegram'; end
50
+ def Genus.Dialog; 'dialog'; end
51
+ end; end
52
+
53
+ def Family.Simple; 'simple'; end
54
+ module Simple; module Genus
55
+ def Genus.Text; 'text'; end
56
+ end; end
57
+ def Family.Notext; 'notext'; end
58
+
59
+ def Family.Contact; 'contact'; end
60
+ def Family.Location; 'location'; end
61
+ def Family.Invoice; 'invoice'; end
62
+ end; end
63
+
64
+ def Order.Notify; 'notify'; end
65
+ module Notify; module Family
66
+ def Family.ChatTitle; 'chattitle'; end
67
+ def Family.Passport; 'passport'; end
68
+ module Passport; module Genus
69
+ def Genus.Personal_details; 'personal_details'; end
70
+ def Genus.Passport; 'passport'; end
71
+ def Genus.Driver_license; 'driver_license'; end
72
+ def Genus.Identity_card; 'identity_card'; end
73
+ def Genus.Internal_passport; 'internal_passport'; end
74
+ def Genus.Address; 'address'; end
75
+ def Genus.Utility_bill; 'utility_bill'; end
76
+ def Genus.Bank_statement; 'bank_statement'; end
77
+ def Genus.Rental_agreement; 'rental_agreement'; end
78
+ def Genus.Passport_registration; 'passport_registration'; end
79
+ def Genus.Temporary_registration; 'temporary_registration'; end
80
+ def Genus.Phone_number; 'phone_number'; end
81
+ def Genus.Email; 'email'; end
82
+ end; end
83
+ def Family.ChatMember; 'chatmember'; end
84
+ module ChatMember; module Genus
85
+ def Genus.In_open; 'in_open'; end
86
+ def Genus.In_link; 'in_link'; end
87
+ def Genus.Invite; 'invite'; end
88
+ def Genus.Leave; 'leave'; end
89
+ def Genus.Ban; 'ban'; end
90
+ end; end
91
+ def Family.ChatPhoto; 'chatphoto'; end
92
+ def Family.Create; 'create'; end
93
+ def Family.Migrate; 'migrate'; end
94
+ def Family.Pinned; 'pinned'; end
95
+ def Family.Login; 'login'; end
96
+ end; end;
97
+
98
+ def Order.Service; 'service'; end
99
+ module Service; module Family
100
+ def Family.Inline; 'inline'; end
101
+ module Inline; module Genus
102
+ def Genus.Query; 'query'; end
103
+ def Genus.Cresult; 'cresult'; end
104
+ # def Genus.Answer; 'answer'; end
105
+ end; end;
106
+
107
+ def Family.Callback; 'callback'; end
108
+ module Callback; module Genus
109
+ def Genus.Query; 'query'; end
110
+ end; end;
111
+ end; end;
112
+
113
+ def Order.Default; 'default'; end
114
+ module Default; module Family
115
+ def Family.Default; 'default'; end
116
+ module Inline; module Genus
117
+ def Default.Main; 'main'; end
118
+ end; end;
119
+ end; end;
120
+
121
+ end; end;
122
+ end
123
+ end; end;
124
+
125
+ # module Message; module Family
126
+ # def Family.EditMessage; 'EditMessage'; end
127
+ # def Family.Pin; 'Pin'; end
128
+ # def Family.WebLogin; 'WebLogin'; end
129
+ # def Family.GenusNone; 'GenusNone'; end
130
+ # end; end;
@@ -0,0 +1,51 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 2 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+
13
+ module Dialog
14
+ module RedisPubSub
15
+ class << self
16
+
17
+ def subGetUnsub1(args)
18
+ redisChannelPrefix = args[:x][:redis][:user_id]
19
+ redisSubTimeout = 1
20
+
21
+ subGetUnsub(args,redisChannelPrefix,redisSubTimeout)
22
+
23
+ end
24
+
25
+ def subGetUnsub2(args)
26
+ redisChannelPrefix = args[:mmsg][:user_id]
27
+ redisSubTimeout = 300
28
+
29
+ subGetUnsub(args,redisChannelPrefix,redisSubTimeout)
30
+
31
+ end
32
+
33
+ def subGetUnsub(args,redisChannelPrefix,redisSubTimeout)
34
+ args[:x][:redis][:redisChannelpostfix].nil? ? args[:x][:redis][:redisChannelpostfix] = "" : true
35
+ redisChannel = "#{redisChannelPrefix}__#{args[:x][:redis][:subPostfix]}_#{args[:x][:redis][:redisChannelpostfix]}"
36
+ redis ||= Redis.new(path: Bot.configuration.redis_url)
37
+ redis.subscribe_with_timeout(redisSubTimeout, redisChannel) do |on, subscriptions|
38
+ Dialog.logger.debug "Subscribed to #{redisChannel} (#{subscriptions} subscriptions)"
39
+ on.message do |channel, msg|
40
+ Dialog.logger.debug "Redis READ from #{channel}, MSG: #{msg}"
41
+ args[:x][:redis][:answer] = Oj.load(msg)
42
+ redis.unsubscribe(redisChannel)
43
+ end
44
+ end
45
+ rescue Redis::TimeoutError => @e
46
+ true
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,97 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 2 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+
13
+ module Dialog
14
+ module RedisCached
15
+ class << self
16
+
17
+ def areaDescr(args)
18
+ case args[:x][:redis][:region]
19
+ when 'chat'
20
+ args[:x][:redis][:area] = args[:mmsg][:fqndata][:o][:chat][:id]
21
+ args[:pushCache] = true if args[:x][:redis][:territory] == 'context'
22
+ when 'user'
23
+ args[:x][:redis][:area] = args[:mmsg][:user_id]
24
+ end
25
+ end
26
+
27
+
28
+ def pullCached(args)
29
+ # Using a "REGION -> AREA -> TERRITORY" semantics
30
+ # Means: hash 'REGION:AREA' key 'TERRITORY'
31
+ areaDescr(args)
32
+ # redis ||= Redis.new(path: Bot.configuration.redis_url) ### May be BUG - needs additional Redis connection
33
+ a = Dialog::redis.hmget("#{args[:x][:redis][:region]}:#{args[:x][:redis][:area]}", ":#{args[:x][:redis][:territory]}")[0] # possible BUG - first array element
34
+ Dialog.logger.debug "Redis Request: \"#{args[:x][:redis][:region]}:#{args[:x][:redis][:area]}\" Key: \":#{args[:x][:redis][:territory]}\" Answer: \"#{a}\", x: #{args[:x][:redis]}"
35
+
36
+ if a.nil? and args[:pushCache] == true
37
+ a = pushCached(args)
38
+ end
39
+ Dialog.logger.debug "Using RedisCached for the upper request"
40
+ Dialog.clearRedis(args)
41
+ a
42
+ end
43
+
44
+
45
+ def pushCached(args)
46
+ areaDescr(args)
47
+ Dialog.logger.debug "Redis pushToCache, area::#{args[:x][:redis][:area]}, region::#{args[:x][:redis][:region]}"
48
+ case args[:x][:redis][:region]
49
+ when 'chat'
50
+
51
+ case args[:x][:redis][:territory]
52
+ when 'context'
53
+ pushCachedContext(args)
54
+ end
55
+
56
+ when 'user'
57
+ case args[:x][:redis][:territory]
58
+ when 'settings'
59
+ @v = true
60
+ end
61
+ end
62
+
63
+ @v=redisWrite_ChatCached({hname: "#{args[:x][:redis][:region]}:#{args[:x][:redis][:area]}", k: args[:x][:redis][:territory], v: @v}, args)
64
+ @v
65
+ end
66
+
67
+
68
+ def pushCachedContext(args)
69
+ Dialog.clearApi(args)
70
+ args[:smsg] = {chat_id: args[:mmsg][:fqndata][:o][:chat][:id]}
71
+ args[:api][:op] = 'ChatAdministrators'
72
+ a = Dialog::BotApi.apiActionGet(args)
73
+ bman = 0; cman = 0
74
+ a['result'].each do |user|
75
+ Dialog.logger.debug "userId #{user['user']['id']}, userStatus #{user['status']}; cliId #{args[:globals][:cliId]}, botId #{Dialog.config.naming.id}"
76
+ cman = 1 if (user['user']['id'].to_i == args[:globals][:cliId] and user['status'] == 'creator')
77
+ bman = 1 if (user['user']['id'].to_i == Dialog.config.naming.id and user['status'] == 'administrator')
78
+ end
79
+ Dialog.logger.debug "Context args: @bman=#{bman} @cman=#{cman}"
80
+ @v = Dialog::Naming::ChatContext.Fullman if (bman == 1 and cman == 1)
81
+ @v = Dialog::Naming::ChatContext.Botman if (bman == 1 and cman == 0)
82
+ @v = Dialog::Naming::ChatContext.Climan if (bman == 0 and cman == 1)
83
+ @v = Dialog::Naming::ChatContext.Noman if (bman == 0 and cman == 0)
84
+
85
+ end
86
+
87
+ def redisWrite_ChatCached(vals, args)
88
+ Dialog.redis.hmset("#{vals[:hname]}", ":#{vals[:k]}", vals[:v])
89
+ args[:x][:redis].key?(:ttl) ? true : args[:x][:redis][:ttl] = 600
90
+ Dialog.redis.expire "#{vals[:hname]}", args[:x][:redis][:ttl]
91
+ Dialog.logger.debug "Redis SET - #{vals[:hname]} K:#{vals[:k]} V: #{vals[:v]} with ttl #{args[:x][:redis][:ttl]}"
92
+ vals[:v]
93
+ end
94
+
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,141 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 2 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ module Dialog
13
+ module TDLib
14
+ class << self
15
+
16
+ def tdlibAuth(mode, tgSess)
17
+ case mode
18
+ when 'bot'
19
+ bot_auth(tgSess)
20
+ when 'cli'
21
+ cli_auth(tgSess)
22
+ end
23
+ end
24
+
25
+
26
+ def proxy
27
+ proxy = {
28
+ '@type' => 'addProxy',
29
+ 'server' => Dialog.config.proxy.host,
30
+ 'port' => Dialog.config.proxy.port,
31
+ 'enable' => true,
32
+ 'type' => {
33
+ '@type' => 'proxyTypeSocks5',
34
+ 'username' => Dialog.config.proxy.login,
35
+ 'password' => Dialog.config.proxy.pass
36
+ }
37
+ }
38
+ return proxy
39
+ end
40
+
41
+ def bot_auth(tgSess)
42
+ state = nil
43
+
44
+ tgSess.on('updateAuthorizationState') do |update|
45
+ next unless update.dig('authorization_state', '@type') == 'authorizationStateWaitPhoneNumber'
46
+ state = :wait_token
47
+ end
48
+
49
+ tgSess.on('updateAuthorizationState') do |update|
50
+ next unless update.dig('authorization_state', '@type') == 'authorizationStateReady'
51
+ state = :ready
52
+ end
53
+
54
+ loop do
55
+ case state
56
+ when :wait_token
57
+ p 'Please enter bot token:'
58
+ token = STDIN.gets.strip
59
+ params = {
60
+ '@type' => 'checkAuthenticationBotToken',
61
+ 'token' => token
62
+ }
63
+ tgSess.broadcast_and_receive(params).tap(&error_handler)
64
+
65
+ when :ready
66
+ @me = tgSess.broadcast_and_receive('@type' => 'getMe')
67
+ break
68
+
69
+ end
70
+ end
71
+ close(tgSess)
72
+ end
73
+
74
+
75
+
76
+ def cli_auth(tgSess)
77
+ state = nil
78
+
79
+ tgSess.broadcast(proxy)
80
+
81
+ tgSess.on('updateAuthorizationState') do |update|
82
+ next unless update.dig('authorization_state', '@type') == 'authorizationStateWaitPhoneNumber'
83
+ state = :wait_phone
84
+ end
85
+
86
+ tgSess.on('updateAuthorizationState') do |update|
87
+ next unless update.dig('authorization_state', '@type') == 'authorizationStateWaitPassword'
88
+ state = :wait_password
89
+ end
90
+
91
+ tgSess.on('updateAuthorizationState') do |update|
92
+ next unless update.dig('authorization_state', '@type') == 'authorizationStateWaitCode'
93
+ state = :wait_code
94
+ end
95
+
96
+ tgSess.on('updateAuthorizationState') do |update|
97
+ next unless update.dig('authorization_state', '@type') == 'authorizationStateReady'
98
+ state = :ready
99
+ end
100
+
101
+ loop do
102
+ p state
103
+ case state
104
+ when :wait_phone
105
+ p 'Please enter phone number:'
106
+ phone = STDIN.gets.strip
107
+ params = {
108
+ '@type' => 'setAuthenticationPhoneNumber',
109
+ 'phone_number' => phone
110
+ }
111
+ tgSess.broadcast_and_receive(params).tap(&error_handler)
112
+
113
+ when :wait_code
114
+ p 'Please enter code from SMS:'
115
+ code = STDIN.gets.strip
116
+ params = {
117
+ '@type' => 'checkAuthenticationCode',
118
+ 'code' => code
119
+ }
120
+ tgSess.broadcast_and_receive(params).tap(&error_handler)
121
+
122
+ when :wait_password
123
+ p 'Please enter password:'
124
+ password = STDIN.gets.strip
125
+ params = {
126
+ '@type' => 'checkAuthenticationPassword',
127
+ 'password' => password
128
+ }
129
+ tgSess.broadcast_and_receive(params).tap(&error_handler)
130
+ when :ready
131
+ @me = tgSess.broadcast_and_receive('@type' => 'getMe')
132
+ break
133
+ end
134
+ end
135
+
136
+ close(tgSess)
137
+ end
138
+
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,34 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 2 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ module Dialog
13
+ module TDLib
14
+ class << self
15
+
16
+ def error_handler
17
+ proc do |result|
18
+ if result['@type'] == 'error'
19
+ msg = "Failed to process request: #{result['code']} #{result['message']}"
20
+ p msg
21
+ raise msg
22
+ end
23
+ end
24
+ end
25
+
26
+ def close(tgSess)
27
+ # ensure
28
+ tgSess.close
29
+ # end
30
+ end
31
+
32
+ end
33
+ end
34
+ end