kanal-interfaces-telegram 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec97da09dbf6a19e7b65b361c5b7ab53b735a265ba0ed0eb80bd1451ab476a71
4
- data.tar.gz: b5a7ba8bbf3d590d39babc65445942c433491205985403c1c51575e0ca63fc0a
3
+ metadata.gz: c0443fcd3d0798e1f0d9765f25790852ec5f99635b88d78dd51b30a4c1491166
4
+ data.tar.gz: a0c4f6a617e075a62e2d2a15802d25267eb297b0cf85991c4ffd7c2908a470bb
5
5
  SHA512:
6
- metadata.gz: 359c32decdf13beb0e80e78c1ac6ae660886fd0e781514cd5d19c4ad0ecd844a713ac1152af92ede60a703e51ad59707bbe05f057988306e1fd48511b99e40f3
7
- data.tar.gz: 34d5fa6508289862c9f68be3fb435a3db12d284cb28668bb1c221130f0f907b0e59b139ae8dbe0e67bf736128e0bc8f59e2a0c4f9dbfcda25715fe031ae757aa
6
+ metadata.gz: 541a8cdc495e3def560db1209f9a0274b476b528d2887d1686de7557dae3d8e3cb24447ddedb763b0a11d64baf040d02cb888c4d01037a3df54e2c3714501c07
7
+ data.tar.gz: a6d4e89bda323eff32315cbc0acaf47e6bdd5f87c685c2e7a499f5f955d44b905373e477ec0a6e02e4464015adea1b59154966436fc14f77c4b4603411f5c1a8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2023-01-30
4
+
5
+ - Library now can send images via .tg_image_path
6
+ - Populating separate field in input
7
+ - Using output.tg_chat_id and not the one inside interface, this is preparations for future sending outputs in separate methods... Probably
8
+
3
9
  ## [0.1.0] - 2022-11-21
4
10
 
5
11
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kanal-interfaces-telegram (0.1.2)
4
+ kanal-interfaces-telegram (0.2.0)
5
5
  telegram-bot-ruby
6
6
 
7
7
  GEM
@@ -17,8 +17,16 @@ module Kanal
17
17
 
18
18
  def register_parameters(core)
19
19
  core.register_input_parameter :tg_message, readonly: true
20
+ core.register_input_parameter :tg_text, readonly: true
21
+ core.register_input_parameter :tg_chat_id, readonly: true
22
+ core.register_input_parameter :tg_username, readonly: true
23
+
24
+ core.register_output_parameter :tg_chat_id
20
25
  core.register_output_parameter :tg_text
21
26
  core.register_output_parameter :tg_reply_markup
27
+ core.register_output_parameter :tg_image_path
28
+ core.register_output_parameter :tg_audio_path
29
+ core.register_output_parameter :tg_document_path
22
30
  end
23
31
 
24
32
  def register_hooks(core)
@@ -27,11 +35,12 @@ module Kanal
27
35
  end
28
36
 
29
37
  core.hooks.attach :input_before_router do |input|
30
- input.body = input.tg_message.text
38
+ input.body = input.tg_text
31
39
  end
32
40
 
33
41
  core.hooks.attach :output_before_returned do |input, output|
34
42
  output.tg_text = output.body
43
+ output.tg_chat_id = input.tg_chat_id
35
44
  end
36
45
  end
37
46
  end
@@ -26,17 +26,48 @@ module Kanal
26
26
  input = @core.create_input
27
27
 
28
28
  input.tg_message = message
29
+ input.tg_text = message.text
30
+ input.tg_chat_id = message.chat.id
31
+ input.tg_username = message.try(:chat).try(:username) || input.tg_message.try(:from).try(:username)
29
32
 
30
33
  output = router.create_output_for_input input
31
34
 
32
35
  bot.api.send_message(
33
- chat_id: message.chat.id,
36
+ chat_id: output.tg_chat_id,
34
37
  text: output.tg_text,
35
38
  reply_markup: output.tg_reply_markup
36
39
  )
40
+
41
+ image_path = output.tg_image_path
42
+
43
+ if image_path && File.exist?(image_path)
44
+ bot.api.send_photo(
45
+ chat_id: message.chat.id,
46
+ photo: Faraday::UploadIO.new(image_path, guess_mimetype(image_path))
47
+ )
48
+ end
37
49
  end
38
50
  end
39
51
  end
52
+
53
+ private
54
+
55
+ def guess_mimetype(filename)
56
+ images = {
57
+ "image/jpeg" => %w[jpg jpeg],
58
+ "image/png" => ["png"],
59
+ "image/bmp" => ["bmp"]
60
+ }
61
+
62
+ # TODO: rewrite with .find or .each
63
+ for mime, types in [images] do
64
+ for type in types do
65
+ return mime if filename.include? type
66
+ end
67
+ end
68
+
69
+ "application/octet-stream"
70
+ end
40
71
  end
41
72
  end
42
73
  end
@@ -3,7 +3,7 @@
3
3
  module Kanal
4
4
  module Interfaces
5
5
  module Telegram
6
- VERSION = "0.1.2"
6
+ VERSION = "0.2.0"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanal-interfaces-telegram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - idchlife
@@ -47,7 +47,6 @@ files:
47
47
  - lib/kanal/interfaces/telegram/plugins/telegram_integration_plugin.rb
48
48
  - lib/kanal/interfaces/telegram/telegram_interface.rb
49
49
  - lib/kanal/interfaces/telegram/version.rb
50
- - pep.rb
51
50
  - sig/kanal/interfaces/telegram.rbs
52
51
  homepage: https://github.com/idchlife/kanal-interfaces-telegram
53
52
  licenses:
data/pep.rb DELETED
@@ -1,8 +0,0 @@
1
- a = nil
2
-
3
- until a.is_a?(Numeric) do
4
- puts "Введите первое число:"
5
- input = STDIN.gets.chomp
6
-
7
- a = Integer(input, exception: false)
8
- end