kanal-interfaces-telegram 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/.gitignore +8 -0
- data/.idea/kanal-interfaces-telegram.iml +72 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/CHANGELOG.md +2 -5
- data/Gemfile +1 -1
- data/Gemfile.lock +7 -4
- data/lib/kanal/interfaces/telegram/plugins/telegram_integration_plugin.rb +9 -1
- data/lib/kanal/interfaces/telegram/telegram_interface.rb +86 -22
- data/lib/kanal/interfaces/telegram/version.rb +1 -1
- data/lib/kanal/interfaces/telegram.rb +3 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d561c375f8a3d3802d78a2c03b7b8859d4d6db10cd6a4fb55242dc11776c2448
|
4
|
+
data.tar.gz: 1fe7521d6848968a584173484fbdeca37ebbf1d9cebc0ffa07cff2d8ceab6298
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93dec85818dcf56c4d578a4ad82564bfd4dde43e101d04bea1c7f32095aab0c9ca89db0e725829c2482fc179b1bceee3d6391bbda1ac5cd9f4c83dc6b1ddb641
|
7
|
+
data.tar.gz: 29e6de8af8c702984d6829f74c7ddd3393b315aade1b31a1c64f4000d0564f2528022ae5ebd4d77e952a18e009aa83c77a215735c355b9308fb4b993638ef072
|
data/.idea/.gitignore
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="inheritedJdk" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-2.7.6) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="axiom-types (v0.1.1, RVM: ruby-2.7.6) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="backport (v1.2.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="benchmark (v0.2.1, RVM: ruby-2.7.6) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.4.5, RVM: ruby-2.7.6) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="coercible (v1.0.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="descendants_tracker (v0.0.4, RVM: ruby-2.7.6) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="docile (v1.4.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="dry-inflector (v1.0.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="e2mmap (v0.1.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="faraday (v2.7.4, RVM: ruby-2.7.6) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="faraday-multipart (v1.0.4, RVM: ruby-2.7.6) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="faraday-net_http (v3.0.2, RVM: ruby-2.7.6) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="ice_nine (v0.11.2, RVM: ruby-2.7.6) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="jaro_winkler (v1.5.4, RVM: ruby-2.7.6) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="json (v2.6.3, RVM: ruby-2.7.6) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="kanal (v0.3.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="kramdown (v2.4.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="kramdown-parser-gfm (v1.1.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="multipart-post (v2.3.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.14.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.22.1, RVM: ruby-2.7.6) [gem]" level="application" />
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v3.2.0.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="racc (v1.6.2, RVM: ruby-2.7.6) [gem]" level="application" />
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, RVM: ruby-2.7.6) [gem]" level="application" />
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, RVM: ruby-2.7.6) [gem]" level="application" />
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.6.2, RVM: ruby-2.7.6) [gem]" level="application" />
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="reverse_markdown (v2.1.1, RVM: ruby-2.7.6) [gem]" level="application" />
|
43
|
+
<orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, RVM: ruby-2.7.6) [gem]" level="application" />
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.12.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
45
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.12.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
46
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.12.2, RVM: ruby-2.7.6) [gem]" level="application" />
|
47
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.12.3, RVM: ruby-2.7.6) [gem]" level="application" />
|
48
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.12.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
49
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.44.1, RVM: ruby-2.7.6) [gem]" level="application" />
|
50
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.24.1, RVM: ruby-2.7.6) [gem]" level="application" />
|
51
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby-debug-ide (v0.7.3, RVM: ruby-2.7.6) [gem]" level="application" />
|
52
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
53
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby2_keywords (v0.0.5, RVM: ruby-2.7.6) [gem]" level="application" />
|
54
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov (v0.22.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
55
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.12.3, RVM: ruby-2.7.6) [gem]" level="application" />
|
56
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov_json_formatter (v0.1.4, RVM: ruby-2.7.6) [gem]" level="application" />
|
57
|
+
<orderEntry type="library" scope="PROVIDED" name="solargraph (v0.48.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
58
|
+
<orderEntry type="library" scope="PROVIDED" name="telegram-bot-ruby (v0.23.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
59
|
+
<orderEntry type="library" scope="PROVIDED" name="thor (v1.2.1, RVM: ruby-2.7.6) [gem]" level="application" />
|
60
|
+
<orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.6, RVM: ruby-2.7.6) [gem]" level="application" />
|
61
|
+
<orderEntry type="library" scope="PROVIDED" name="tilt (v2.0.11, RVM: ruby-2.7.6) [gem]" level="application" />
|
62
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.4.2, RVM: ruby-2.7.6) [gem]" level="application" />
|
63
|
+
<orderEntry type="library" scope="PROVIDED" name="virtus (v2.0.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
64
|
+
<orderEntry type="library" scope="PROVIDED" name="webrick (v1.7.0, RVM: ruby-2.7.6) [gem]" level="application" />
|
65
|
+
<orderEntry type="library" scope="PROVIDED" name="yard (v0.9.28, RVM: ruby-2.7.6) [gem]" level="application" />
|
66
|
+
</component>
|
67
|
+
<component name="RakeTasksCache">
|
68
|
+
<option name="myRootTask">
|
69
|
+
<RakeTaskImpl id="rake" />
|
70
|
+
</option>
|
71
|
+
</component>
|
72
|
+
</module>
|
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/kanal-interfaces-telegram.iml" filepath="$PROJECT_DIR$/.idea/kanal-interfaces-telegram.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.idea/vcs.xml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.
|
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
|
3
|
+
## [0.3.0] - 2023-03-10
|
4
|
+
- Reworked interface with the new Kanal release, now it uses Interface base class properly
|
8
5
|
|
9
6
|
## [0.1.0] - 2022-11-21
|
10
7
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kanal-interfaces-telegram (0.2.
|
4
|
+
kanal-interfaces-telegram (0.2.1)
|
5
5
|
telegram-bot-ruby
|
6
6
|
|
7
7
|
GEM
|
@@ -31,7 +31,7 @@ GEM
|
|
31
31
|
ice_nine (0.11.2)
|
32
32
|
jaro_winkler (1.5.4)
|
33
33
|
json (2.6.3)
|
34
|
-
kanal (0.
|
34
|
+
kanal (0.4.0)
|
35
35
|
kramdown (2.4.0)
|
36
36
|
rexml
|
37
37
|
kramdown-parser-gfm (1.1.0)
|
@@ -39,6 +39,8 @@ GEM
|
|
39
39
|
multipart-post (2.3.0)
|
40
40
|
nokogiri (1.14.0-x86_64-darwin)
|
41
41
|
racc (~> 1.4)
|
42
|
+
nokogiri (1.14.0-x86_64-linux)
|
43
|
+
racc (~> 1.4)
|
42
44
|
parallel (1.22.1)
|
43
45
|
parser (3.2.0.0)
|
44
46
|
ast (~> 2.4.1)
|
@@ -118,9 +120,10 @@ GEM
|
|
118
120
|
|
119
121
|
PLATFORMS
|
120
122
|
x86_64-darwin-21
|
123
|
+
x86_64-linux
|
121
124
|
|
122
125
|
DEPENDENCIES
|
123
|
-
kanal
|
126
|
+
kanal (= 0.4.0)
|
124
127
|
kanal-interfaces-telegram!
|
125
128
|
rake (~> 13.0)
|
126
129
|
rspec (~> 3.0)
|
@@ -131,4 +134,4 @@ DEPENDENCIES
|
|
131
134
|
yard
|
132
135
|
|
133
136
|
BUNDLED WITH
|
134
|
-
2.
|
137
|
+
2.4.5
|
@@ -18,8 +18,12 @@ module Kanal
|
|
18
18
|
def register_parameters(core)
|
19
19
|
core.register_input_parameter :tg_message, readonly: true
|
20
20
|
core.register_input_parameter :tg_text, readonly: true
|
21
|
+
core.register_input_parameter :tg_callback, readonly: true
|
22
|
+
core.register_input_parameter :tg_callback_text, readonly: true
|
21
23
|
core.register_input_parameter :tg_chat_id, readonly: true
|
22
24
|
core.register_input_parameter :tg_username, readonly: true
|
25
|
+
core.register_input_parameter :tg_image_link, readonly: true
|
26
|
+
core.register_input_parameter :tg_audio_link, readonly: true
|
23
27
|
|
24
28
|
core.register_output_parameter :tg_chat_id
|
25
29
|
core.register_output_parameter :tg_text
|
@@ -35,7 +39,11 @@ module Kanal
|
|
35
39
|
end
|
36
40
|
|
37
41
|
core.hooks.attach :input_before_router do |input|
|
38
|
-
|
42
|
+
if input.tg_callback
|
43
|
+
input.body = input.tg_callback_text
|
44
|
+
else
|
45
|
+
input.body = input.tg_text
|
46
|
+
end
|
39
47
|
end
|
40
48
|
|
41
49
|
core.hooks.attach :output_before_returned do |input, output|
|
@@ -16,6 +16,8 @@ module Kanal
|
|
16
16
|
|
17
17
|
@bot_token = bot_token
|
18
18
|
|
19
|
+
@bot = ::Telegram::Bot::Client.new(bot_token)
|
20
|
+
|
19
21
|
@core.register_plugin Kanal::Plugins::Batteries::BatteriesPlugin.new
|
20
22
|
@core.register_plugin Kanal::Interfaces::Telegram::Plugins::TelegramIntegrationPlugin.new
|
21
23
|
end
|
@@ -23,34 +25,96 @@ module Kanal
|
|
23
25
|
def start
|
24
26
|
::Telegram::Bot::Client.run(@bot_token) do |bot|
|
25
27
|
bot.listen do |message|
|
26
|
-
|
28
|
+
puts "message class: #{message.class}"
|
29
|
+
|
30
|
+
if message.instance_of?(::Telegram::Bot::Types::CallbackQuery)
|
31
|
+
input = @core.create_input
|
32
|
+
|
33
|
+
input.tg_callback = message
|
34
|
+
input.tg_callback_text = message.data
|
35
|
+
input.tg_chat_id = message.from.id
|
36
|
+
input.tg_username = message.from.username
|
37
|
+
|
38
|
+
puts input.tg_username
|
39
|
+
puts input.tg_chat_id
|
40
|
+
|
41
|
+
router.consume_input input
|
27
42
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
43
|
+
# output = router.create_output_for_input input
|
44
|
+
#
|
45
|
+
# send_output bot, output
|
46
|
+
else
|
47
|
+
input = @core.create_input
|
32
48
|
|
33
|
-
|
49
|
+
if message.text.nil?
|
50
|
+
message.text = "EMPTY TEXT"
|
51
|
+
end
|
34
52
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
)
|
53
|
+
input.tg_message = message
|
54
|
+
input.tg_text = message.text
|
55
|
+
input.tg_chat_id = message.chat.id
|
56
|
+
input.tg_username = message.chat.username || input.tg_message.from.username
|
40
57
|
|
41
|
-
|
58
|
+
puts input.tg_username
|
59
|
+
puts input.tg_chat_id
|
42
60
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
61
|
+
if message.photo.count > 0
|
62
|
+
puts message.photo[0].file_id
|
63
|
+
file = bot.api.get_file(file_id: message.photo[2].file_id)
|
64
|
+
file_path = file.dig('result', 'file_path')
|
65
|
+
photo_url = "https://api.telegram.org/file/bot#{@bot_token}/#{file_path}"
|
66
|
+
puts photo_url
|
67
|
+
input.tg_image_link = photo_url
|
68
|
+
end
|
69
|
+
|
70
|
+
if message.audio.instance_of?(::Telegram::Bot::Types::Audio)
|
71
|
+
file = bot.api.get_file(file_id: message.audio.file_id)
|
72
|
+
file_path = file.dig('result', 'file_path')
|
73
|
+
audio_url = "https://api.telegram.org/file/bot#{@bot_token}/#{file_path}"
|
74
|
+
puts audio_url
|
75
|
+
input.tg_audio_link = audio_url
|
76
|
+
end
|
77
|
+
|
78
|
+
router.consume_input input
|
79
|
+
|
80
|
+
# output = router.create_output_for_input input
|
81
|
+
#
|
82
|
+
# send_output bot, output
|
48
83
|
end
|
49
84
|
end
|
50
85
|
end
|
51
86
|
end
|
52
87
|
|
88
|
+
def consume_output(output)
|
89
|
+
send_output @bot, output
|
90
|
+
end
|
91
|
+
|
53
92
|
private
|
93
|
+
def send_output(bot, output)
|
94
|
+
bot.api.send_message(
|
95
|
+
chat_id: output.tg_chat_id,
|
96
|
+
text: output.tg_text,
|
97
|
+
reply_markup: output.tg_reply_markup
|
98
|
+
)
|
99
|
+
|
100
|
+
image_path = output.tg_image_path
|
101
|
+
|
102
|
+
if !image_path.nil? && File.exist?(image_path)
|
103
|
+
bot.api.send_photo(
|
104
|
+
chat_id: output.tg_chat_id,
|
105
|
+
photo: Faraday::UploadIO.new(output.tg_image_path, guess_mimetype(output.tg_image_path))
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
audio_path = output.tg_audio_path
|
110
|
+
|
111
|
+
if !output.tg_audio_path.nil? && File.exist?(audio_path)
|
112
|
+
bot.api.send_audio(
|
113
|
+
chat_id: output.tg_chat_id,
|
114
|
+
audio: Faraday::UploadIO.new(output.tg_audio_path, "audio/mpeg3")
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
54
118
|
|
55
119
|
def guess_mimetype(filename)
|
56
120
|
images = {
|
@@ -60,13 +124,13 @@ module Kanal
|
|
60
124
|
}
|
61
125
|
|
62
126
|
# TODO: rewrite with .find or .each
|
63
|
-
for
|
64
|
-
for
|
65
|
-
|
127
|
+
for pack in [images] do
|
128
|
+
for mime, types in pack do
|
129
|
+
for type in types do
|
130
|
+
return mime if filename.include? type
|
131
|
+
end
|
66
132
|
end
|
67
133
|
end
|
68
|
-
|
69
|
-
"application/octet-stream"
|
70
134
|
end
|
71
135
|
end
|
72
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kanal-interfaces-telegram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- idchlife
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: telegram-bot-ruby
|
@@ -32,6 +32,11 @@ executables: []
|
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
+
- ".idea/.gitignore"
|
36
|
+
- ".idea/kanal-interfaces-telegram.iml"
|
37
|
+
- ".idea/misc.xml"
|
38
|
+
- ".idea/modules.xml"
|
39
|
+
- ".idea/vcs.xml"
|
35
40
|
- ".rspec"
|
36
41
|
- ".rubocop.yml"
|
37
42
|
- ".ruby-version"
|