te_bot 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84afe807cfff02952abed21f9ad1e9cd4c4a337c2fc9d789960fe68de2e37b6c
4
- data.tar.gz: 6b0616f98f5fca8cfe3583e97f59a5ce4149adaadfd2bb130f88a9f9449f436b
3
+ metadata.gz: cf6752512a52e78b548544788d5a92b93d5024c6a2c4f51e94c214515162b7b2
4
+ data.tar.gz: 070aac9bbc7ba3b362e4a4c7b2b69bb5bd8640dd78ee8e99bc9ecc7b27f2528f
5
5
  SHA512:
6
- metadata.gz: 1fe827e9835f85e930776fd4cb35964f20c3565d99ab2d2bb893cee9e0d61ab713858b3e218ef9157380d9e3af12b8f1c41ab511f559f36e0bd9f5f90392254d
7
- data.tar.gz: 2cfbf9af5f37a95b1581cc2d44b883ecc8c49ffc1e639f693d53564115bbf705c315ad20ee5dbe9c23914621d40f8f06b89945a06987af5605c275c068c01b03
6
+ metadata.gz: f9bef1be0f891861390692b4ba0ebb3c50f0ce9eeb07d3d686c21510f488a47eba422dbbcdafda0273be661ceb62c96a3c365641789392310b05fd04e971cb88
7
+ data.tar.gz: eeec9a81680b40c8c7e9ced4813e772f473892df59c0820526b1fe16800d3926c6c715eca85546e4ad261021417b7edd3424de0c3c18b2b7e752f9d7a34b7650
data/.standard.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  # For available configuration options, see:
2
2
  # https://github.com/testdouble/standard
3
- ruby_version: 2.6
3
+ ruby_version: 2.7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
- ## [Unreleased]
1
+ ## [Released]
2
2
 
3
3
  ## [0.1.0] - 2022-06-25
4
4
 
5
5
  - Initial release
6
+
7
+
8
+ ## [Released]
9
+
10
+ ## [0.2.0] - 2022-07-02
11
+
12
+ - Change the implementation message replier from `reply(conn, message_string)` to `conn.reply text: message_string`.
13
+ - Add support for other message types such as audio, video, animation, markdown, and document
14
+
15
+ ## [Unreleased]
16
+
17
+ ## [0.3.0] - 2022-07-02
18
+
19
+ - Support for the handler to return response direcly by returning rack array or hash.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- te_bot (0.2.0)
4
+ te_bot (0.3.0)
5
5
  faraday (~> 2.3)
6
6
  rack (~> 2.2)
7
7
 
data/README.md CHANGED
@@ -10,7 +10,7 @@ This gem is used to handle telegram webhook and sending message with telegram bo
10
10
 
11
11
  Install the gem and add to the application's Gemfile
12
12
 
13
- gem 'te_bot', '~> 0.2.0'
13
+ gem 'te_bot', '~> 0.3.0'
14
14
 
15
15
  Then run
16
16
 
@@ -89,7 +89,7 @@ class MyWebhookApp < TeBot::Court
89
89
  end
90
90
  end
91
91
  ```
92
- And also we can define a macro for defaul action `#default_action` if the request does not match with this [Documentation](https://core.telegram.org/bots/webhooks#testing-your-bot-with-updates), Or we have not create the handler for that specific message type.
92
+ And also we can define a macro for default action `#default_action` if the request does not match with this [Documentation](https://core.telegram.org/bots/webhooks#testing-your-bot-with-updates), Or we have not created the handler for that specific message type.
93
93
 
94
94
  ```rb
95
95
  # app.rb
@@ -100,7 +100,7 @@ class MyWebhookApp < TeBot::Court
100
100
  end
101
101
  end
102
102
  ```
103
- Since this app implements rack interface, and railr is also a rack based application. We can mount this app direcly inside rails app.
103
+ Since this app implements rack interface, and rails is also a rack based application. We can mount this app direcly inside rails app.
104
104
 
105
105
  ```rb
106
106
  # config/routes.rb
@@ -114,8 +114,8 @@ end
114
114
 
115
115
  ### Sending Message to Telegram
116
116
  To send message direcly to telegram, we can use this module `TeBot::Wire`
117
- and need to require `"te_bot/sender_options"` to add default handler for different type of message.
118
- Available message types are `:text`, `:markdown`, `:photo`, `:audio`, `:document`, `:video`, `:animation`, `:voice`
117
+ and need to require `"te_bot/sender_options"` to add default handler for different type of messages.
118
+ Available message types are `:text`, `:markdown`, `:photo`, `:audio`, `:document`, `:video`, `:animation` amd `:voice`
119
119
 
120
120
  Some supported message by default:
121
121
  ```rb
@@ -135,7 +135,7 @@ sender.send_message(chat_id, animation: { animation: url, caption: caption})
135
135
  For markdown telegram supports MArkdownV2 [refer to this](https://core.telegram.org/bots/api#markdownv2-style)
136
136
  Please check the [documentation](https://core.telegram.org/bots/api#sendmessage) for more details.
137
137
 
138
- Of course you add more handler by extending the `TeBot::Wire` class
138
+ Of course you can add more handler by extending the `TeBot::Wire` class
139
139
 
140
140
  ```ruby
141
141
  # in/your/custom_handler.rb
data/lib/te_bot/court.rb CHANGED
@@ -27,19 +27,31 @@ module TeBot
27
27
 
28
28
  ::TeBot::Message::GENERAL_MESSAGE_TYPES.each do |m|
29
29
  define_method(m) do |&block|
30
- instance_variable_get("@#{m}") || instance_variable_set("@#{m}", block)
31
- instance_variable_get("@#{m}")
30
+ @message_handlers ||= {}
31
+
32
+ if block.respond_to?(:call)
33
+ @message_handlers[m] = block
34
+ else
35
+ @message_handlers[m]
36
+ end
32
37
  end
33
38
  end
39
+
40
+ def message_handlers(handler)
41
+ @message_handlers ||= {}
42
+ @message_handlers[handler]
43
+ end
34
44
  end
35
45
 
36
46
  def call(env)
37
47
  json_only(env) do |body|
38
48
  response = handle_request(body)
39
49
 
40
- if response.is_a?(Array)
41
- status, headers, body = response
42
- [status, headers, body]
50
+ case response
51
+ in [Integer, Hash, Array] => rack_response
52
+ rack_response
53
+ in Hash => json_body
54
+ [200, {"Content-Type" => "application/json"}, [JSON.generate(json_body)]]
43
55
  else
44
56
  [200, {"Content-Type" => "application/json"}, [JSON.generate({"message" => "success"})]]
45
57
  end
@@ -78,9 +90,9 @@ module TeBot
78
90
  end
79
91
  end
80
92
 
81
- ::TeBot::Message::GENERAL_MESSAGE_TYPES.each do |f|
82
- message.public_send(f) do
83
- handler = self.class.public_send(f)
93
+ ::TeBot::Message::GENERAL_MESSAGE_TYPES.each do |message_type|
94
+ message.public_send(message_type) do
95
+ handler = self.class.message_handlers(message_type)
84
96
 
85
97
  next unless handler.respond_to?(:call)
86
98
  handler.call(conn)
@@ -17,17 +17,17 @@ module TeBot
17
17
  @message
18
18
  end
19
19
 
20
- MESSAGE_TYPES.each do |format|
21
- define_method(format) do |&block|
22
- instance_variable_set("@#{format}", block)
20
+ MESSAGE_TYPES.each do |f|
21
+ define_method(f) do |&block|
22
+ @formats ||= {}
23
+ @formats[f.to_s] = block
23
24
  end
24
25
  end
25
26
 
26
27
  def handler
27
28
  return unless data || data.content
28
29
  content_class = data.content.class.name.split("::").last.downcase
29
-
30
- instance_variable_get("@#{content_class}")
30
+ @formats[content_class]
31
31
  end
32
32
 
33
33
  def call
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TeBot
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/te_bot.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "Self-contaned telegram bot handler."
12
12
  spec.description = "All at one telegram bot."
13
13
  spec.homepage = "https://github.com/aaripurna/te_bot"
14
- spec.required_ruby_version = ">= 2.6.0"
14
+ spec.required_ruby_version = ">= 2.7.0"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = "https://github.com/aaripurna/te_bot"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: te_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nawa Aripurna
@@ -75,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: 2.6.0
78
+ version: 2.7.0
79
79
  required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="