kamigo 0.32.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d15e3dc7411c04c32ef80effe128552d278a41abf7447f5f1e62c6c3244ec00
4
- data.tar.gz: 6d3a3b34f99195d4e512d8b636f5f569887028cb79f0482c525608dae63b13df
3
+ metadata.gz: 99c87ea21c2cb09558c1df023ee44f556df03e7db35c26e1e6b7bea33b017d1f
4
+ data.tar.gz: deed64bef99684260407e97415f0e7804663de6c756d23fd8b2ef213933363ed
5
5
  SHA512:
6
- metadata.gz: 1decc3bee52276e5ed150834654f6e6620cc299c6053e2360f979c67e70b258395aed6c948e069a10903f9066c40de3ab0ed6c1dd7c4875070bb081d90f965a8
7
- data.tar.gz: bb2dd6bee47627e8bf1f556f2df6f917abb06e17fc4376380cf7396c8f3a776f075deae0c3063bd19b6b102553e10f7ebecc9db9df25fc6872d48fe4278d0940
6
+ metadata.gz: 98ffb73592c2f9e7626000ca92fcc34995861107f264309ee62d0a213aaa8045be2df837f48482bfb10525ce6a2b8af8f878357b14537f12b19140885dc2343e
7
+ data.tar.gz: c74d894eb19f681c87650b139bfcc42e438392b045cd0f83686bcd76d22acac645e101b5fce573fdfc35fabf4b9c2b7a35f22db59c561004c0da4c3ec16e5254
data/README.md CHANGED
@@ -133,6 +133,91 @@ LIFF_FULL=這裡填入你的 FULL_LIFF_URL
133
133
  - `LINE_CHANNEL_ACCESS_TOKEN` 可以在 Messaging API 後台的 Messaging API 分頁中找到。
134
134
  - `COMPACT_LIFF_URL`、`TALL_LIFF_URL` 和 `FULL_LIFF_URL` 需要到 LINE 後台的 LIFF 分頁新增後,即可獲得一組 LIFF URL。
135
135
 
136
+ # 進階設定
137
+
138
+ 在 `config/initializers/kamigo.rb` 中,你可以自訂各種設定:
139
+
140
+ ```ruby
141
+ Kamigo.setup do |config|
142
+ # LINE Messaging API 設定
143
+ # 預設會從環境變數讀取,但你也可以直接在這裡設定
144
+ # config.line_messaging_api_channel_id = "your_channel_id"
145
+ # config.line_messaging_api_channel_secret = "your_channel_secret"
146
+ # config.line_messaging_api_channel_token = "your_channel_token"
147
+
148
+ # 當使用者輸入不符合路由時的預設路徑和 HTTP 方法
149
+ # config.default_path = "/"
150
+ # config.default_http_method = "GET"
151
+
152
+ # 當 Kamigo 不知道如何回應時,會回覆這個訊息
153
+ # config.line_default_message = {
154
+ # type: "text",
155
+ # text: "Sorry, I don't understand your message."
156
+ # }
157
+ # 設為 nil 則不回覆訊息
158
+
159
+ # 設定訊息處理器,可以自訂處理邏輯
160
+ # config.line_event_processors = [
161
+ # EventProcessors::RailsRouterProcessor.new,
162
+ # EventProcessors::DefaultPathProcessor.new,
163
+ # EventProcessors::DefaultMessageProcessor.new
164
+ # ]
165
+ end
166
+ ```
167
+
168
+ # 自定義訊息處理器(Event Processor)
169
+
170
+ Kamigo 允許你自定義訊息處理器來處理 LINE 的訊息。每個處理器都需要實作 `process` 方法,該方法接收一個 `event` 參數並回傳處理結果。
171
+
172
+ 以下是一個簡單的處理器範例:
173
+
174
+ ```ruby
175
+ module Kamigo
176
+ module EventProcessors
177
+ class MyCustomProcessor
178
+ # 處理器可以存取 request 物件
179
+ attr_accessor :request
180
+
181
+ def process(event)
182
+ # event 物件包含以下資訊:
183
+ # - event.platform_type # 平台類型(例如:line)
184
+ # - event.message # 使用者發送的訊息
185
+ # - event.platform_params # 平台相關的參數
186
+ # - event.source_group_id # 群組 ID(如果是群組訊息)
187
+
188
+ # 在這裡實作你的處理邏輯
189
+ return nil if event.message != "hello" # 返回 nil 表示不處理此訊息
190
+
191
+ # 返回要回覆給使用者的訊息(支援 LINE Messaging API 的所有訊息格式)
192
+ {
193
+ type: "text",
194
+ text: "Hello! 你好!"
195
+ }
196
+ end
197
+ end
198
+ end
199
+ end
200
+
201
+ # 在 config/initializers/kamigo.rb 中註冊你的處理器
202
+ Kamigo.setup do |config|
203
+ config.line_event_processors = [
204
+ # 你可以完全自定義處理器順序
205
+ EventProcessors::MyCustomProcessor.new,
206
+ EventProcessors::RailsRouterProcessor.new,
207
+ EventProcessors::DefaultPathProcessor.new,
208
+ EventProcessors::DefaultMessageProcessor.new
209
+ ]
210
+ end
211
+ ```
212
+
213
+ 處理器會按照註冊順序依次處理訊息,直到某個處理器返回非 nil 的結果。這讓你可以:
214
+
215
+ 1. 建立特定關鍵字的回應
216
+ 2. 實作自定義的語意理解
217
+ 3. 整合第三方 NLP 服務
218
+ 4. 處理特殊類型的訊息(圖片、音訊等)
219
+ 5. 實作多輪對話
220
+
136
221
  Kamigo 預設的 LIFF Size 為 Compact,你也可以只新增 Compact LIFF URL。
137
222
  詳細的 LIFF 設定說明可以服用此帖 [LIFF 設定 QA](/doc/07_setting.md#LIFF-設定-QA)。
138
223
 
@@ -13,5 +13,18 @@ Kamigo.setup do |config|
13
13
  # config.line_default_message = nil
14
14
 
15
15
  # When Kamigo receive a request, then Kamigo will process the request with the following processors.
16
- # config.line_event_processors = [Kamigo::EventProcessors::RailsRouterProcessor.new]
16
+ # config.line_event_processors = [
17
+ # EventProcessors::RailsRouterProcessor.new,
18
+ # EventProcessors::DefaultPathProcessor.new,
19
+ # EventProcessors::DefaultMessageProcessor.new
20
+ # ]
21
+
22
+ # LINE Messaging API configuration
23
+ # By default, these values are read from environment variables:
24
+ # LINE_CHANNEL_ID, LINE_CHANNEL_SECRET, and LINE_CHANNEL_TOKEN
25
+ # You can override them here if needed:
26
+ #
27
+ # config.line_messaging_api_channel_id = "your_channel_id"
28
+ # config.line_messaging_api_channel_secret = "your_channel_secret"
29
+ # config.line_messaging_api_channel_token = "your_channel_token"
17
30
  end
@@ -41,7 +41,6 @@ module Kamigo
41
41
  else
42
42
  response = client.get_profile(line_event.source_user_id)
43
43
  end
44
- debugger
45
44
  JSON.parse(response.body)
46
45
  end
47
46
  end
@@ -1,3 +1,3 @@
1
1
  module Kamigo
2
- VERSION = '0.32.0'.freeze
2
+ VERSION = '0.34.0'.freeze
3
3
  end
data/lib/kamigo.rb CHANGED
@@ -32,22 +32,15 @@ module Kamigo
32
32
  EventProcessors::DefaultMessageProcessor.new
33
33
  ]
34
34
 
35
- # env
36
- mattr_writer :line_messaging_api_channel_id
37
- mattr_writer :line_messaging_api_channel_secret
38
- mattr_writer :line_messaging_api_channel_token
35
+ # LINE Messaging API configuration
36
+ mattr_accessor :line_messaging_api_channel_id
37
+ @@line_messaging_api_channel_id = ENV["LINE_CHANNEL_ID"]
39
38
 
40
- def self.line_messaging_api_channel_id
41
- @@line_message_api_channel_id = ENV["LINE_CHANNEL_ID"]
42
- end
43
-
44
- def self.line_messaging_api_channel_secret
45
- @@line_message_api_channel_secret = ENV["LINE_CHANNEL_SECRET"]
46
- end
39
+ mattr_accessor :line_messaging_api_channel_secret
40
+ @@line_messaging_api_channel_secret = ENV["LINE_CHANNEL_SECRET"]
47
41
 
48
- def self.line_messaging_api_channel_token
49
- @@line_message_api_channel_token = ENV["LINE_CHANNEL_TOKEN"]
50
- end
42
+ mattr_accessor :line_messaging_api_channel_token
43
+ @@line_messaging_api_channel_token = ENV["LINE_CHANNEL_TOKEN"]
51
44
 
52
45
  class << self
53
46
  delegate :line_login_channel_id, :line_login_channel_id=, to: :Kamiliff
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamigo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.0
4
+ version: 0.34.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - etrex
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-10-23 00:00:00.000000000 Z
10
+ date: 2025-04-05 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
@@ -82,16 +81,16 @@ dependencies:
82
81
  name: sqlite3
83
82
  requirement: !ruby/object:Gem::Requirement
84
83
  requirements:
85
- - - "~>"
84
+ - - ">="
86
85
  - !ruby/object:Gem::Version
87
- version: '1.0'
86
+ version: '0'
88
87
  type: :development
89
88
  prerelease: false
90
89
  version_requirements: !ruby/object:Gem::Requirement
91
90
  requirements:
92
- - - "~>"
91
+ - - ">="
93
92
  - !ruby/object:Gem::Version
94
- version: '1.0'
93
+ version: '0'
95
94
  description: a chatbot framework based on rails
96
95
  email:
97
96
  - et284vu065k3@gmail.com
@@ -134,7 +133,6 @@ homepage: https://github.com/etrex/kamigo
134
133
  licenses:
135
134
  - MIT
136
135
  metadata: {}
137
- post_install_message:
138
136
  rdoc_options: []
139
137
  require_paths:
140
138
  - lib
@@ -149,8 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
147
  - !ruby/object:Gem::Version
150
148
  version: '0'
151
149
  requirements: []
152
- rubygems_version: 3.1.6
153
- signing_key:
150
+ rubygems_version: 3.6.2
154
151
  specification_version: 4
155
152
  summary: a chatbot framework based on rails
156
153
  test_files: []