kamigo 0.35.0 → 0.36.1
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 +4 -4
- data/app/controllers/line_controller.rb +2 -1
- data/config/routes.rb +1 -0
- data/lib/kamigo/event_parsers/line_event_parser.rb +4 -0
- data/lib/kamigo/event_processors/default_message_processor.rb +1 -0
- data/lib/kamigo/event_processors/default_path_processor.rb +5 -2
- data/lib/kamigo/event_processors/rails_router_processor.rb +1 -0
- data/lib/kamigo/event_responsers/line_event_responser.rb +4 -0
- data/lib/kamigo/events/basic_event.rb +3 -1
- data/lib/kamigo/events/line_event.rb +4 -0
- data/lib/kamigo/line_account.rb +22 -0
- data/lib/kamigo/request_handlers/line_request_handler.rb +7 -4
- data/lib/kamigo/version.rb +1 -1
- data/lib/kamigo.rb +29 -1
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3c1b111bcaa2c2d3f6b3aed53fe178e70fbb32987741b50ba895a29406718603
|
|
4
|
+
data.tar.gz: 04de941918e775e9f24cfc8a8befe2c2697c1d43705e6888216b71a761c24a88
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9664028c32c31865552a92fcb786c177e2a15eb886804c28ad52db8069130825a1954f70e59bf1ca5d7ba67205a2f4d52f828d10ebbc883963afdca1ca9bc88f
|
|
7
|
+
data.tar.gz: 9299a29a2530da8f8f56171dce2765dc9f28c2fdb5b62ff0bbb035ea8ba1b0378568982f6129da547ee5e1209c5211eefbb678c3784caa19ba756be44fbf865c
|
|
@@ -4,7 +4,8 @@ class LineController < ActionController::Base
|
|
|
4
4
|
protect_from_forgery with: :null_session
|
|
5
5
|
|
|
6
6
|
def entry
|
|
7
|
-
|
|
7
|
+
account = Kamigo.find_account(params[:account_name])
|
|
8
|
+
request_handler = Kamigo::RequestHandlers::LineRequestHandler.new(request, form_authenticity_token, account: account)
|
|
8
9
|
request_handler.handle
|
|
9
10
|
head :ok
|
|
10
11
|
end
|
data/config/routes.rb
CHANGED
|
@@ -3,10 +3,13 @@ module Kamigo
|
|
|
3
3
|
class DefaultPathProcessor
|
|
4
4
|
attr_accessor :request
|
|
5
5
|
attr_accessor :form_authenticity_token
|
|
6
|
+
attr_accessor :account
|
|
6
7
|
|
|
7
8
|
def process(event)
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
path = @account&.default_path || Kamigo.default_path
|
|
10
|
+
return nil if path.nil?
|
|
11
|
+
http_method = @account&.default_http_method || Kamigo.default_http_method
|
|
12
|
+
reserve_route(URI::Parser.new.escape(path), http_method: http_method, request_params: event.platform_params, format: :line)
|
|
10
13
|
end
|
|
11
14
|
|
|
12
15
|
private
|
|
@@ -3,6 +3,10 @@ module Kamigo
|
|
|
3
3
|
class LineEventResponser
|
|
4
4
|
include Kamigo::Clients::LineClient
|
|
5
5
|
|
|
6
|
+
def initialize(account: nil)
|
|
7
|
+
@client = account&.client
|
|
8
|
+
end
|
|
9
|
+
|
|
6
10
|
def response_event(event, message)
|
|
7
11
|
return nil if message.blank?
|
|
8
12
|
message = JSON.parse(message) if message.is_a?(String) && (message.start_with?("{") || message.start_with?("["))
|
|
@@ -9,6 +9,7 @@ module Kamigo
|
|
|
9
9
|
attr_accessor :source_user_id
|
|
10
10
|
attr_accessor :profile
|
|
11
11
|
attr_accessor :payload
|
|
12
|
+
attr_accessor :account_name
|
|
12
13
|
|
|
13
14
|
def platform_params
|
|
14
15
|
{
|
|
@@ -19,7 +20,8 @@ module Kamigo
|
|
|
19
20
|
source_group_id: source_group_id,
|
|
20
21
|
source_user_id: source_user_id,
|
|
21
22
|
profile: profile,
|
|
22
|
-
payload: payload
|
|
23
|
+
payload: payload,
|
|
24
|
+
account_name: account_name
|
|
23
25
|
}
|
|
24
26
|
end
|
|
25
27
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Kamigo
|
|
2
|
+
class LineAccount
|
|
3
|
+
attr_accessor :name, :channel_id, :channel_secret, :channel_token
|
|
4
|
+
attr_accessor :default_path, :default_http_method
|
|
5
|
+
|
|
6
|
+
def initialize(name)
|
|
7
|
+
@name = name.to_s
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def client
|
|
11
|
+
@client ||= Line::Bot::Client.new do |config|
|
|
12
|
+
config.channel_id = channel_id
|
|
13
|
+
config.channel_secret = channel_secret
|
|
14
|
+
config.channel_token = channel_token
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def reset_client
|
|
19
|
+
@client = nil
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
module Kamigo
|
|
2
2
|
module RequestHandlers
|
|
3
3
|
class LineRequestHandler
|
|
4
|
-
def initialize(request, form_authenticity_token)
|
|
4
|
+
def initialize(request, form_authenticity_token, account: nil)
|
|
5
5
|
@request = request
|
|
6
6
|
@form_authenticity_token = form_authenticity_token
|
|
7
|
+
@account = account || Kamigo.default_account
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
def handle
|
|
10
|
-
parser = EventParsers::LineEventParser.new
|
|
11
|
+
parser = EventParsers::LineEventParser.new(account: @account)
|
|
11
12
|
events = parser.parse_events(@request)
|
|
12
13
|
events.each do |event|
|
|
14
|
+
event.account_name = @account.name
|
|
13
15
|
output = process_event(event)
|
|
14
|
-
responser = EventResponsers::LineEventResponser.new
|
|
16
|
+
responser = EventResponsers::LineEventResponser.new(account: @account)
|
|
15
17
|
response = responser.response_event(event, output)
|
|
16
18
|
end
|
|
17
19
|
end
|
|
@@ -22,6 +24,7 @@ module Kamigo
|
|
|
22
24
|
Kamigo.line_event_processors.each do |processor|
|
|
23
25
|
processor.request = @request
|
|
24
26
|
processor.form_authenticity_token = @form_authenticity_token
|
|
27
|
+
processor.account = @account if processor.respond_to?(:account=)
|
|
25
28
|
output = processor.process(event)
|
|
26
29
|
return output if output.present?
|
|
27
30
|
end
|
|
@@ -29,4 +32,4 @@ module Kamigo
|
|
|
29
32
|
end
|
|
30
33
|
end
|
|
31
34
|
end
|
|
32
|
-
end
|
|
35
|
+
end
|
data/lib/kamigo/version.rb
CHANGED
data/lib/kamigo.rb
CHANGED
|
@@ -3,6 +3,7 @@ require "line-bot-api"
|
|
|
3
3
|
require "kamiflex"
|
|
4
4
|
require "kamiliff"
|
|
5
5
|
require "kamigo/clients/line_client"
|
|
6
|
+
require "kamigo/line_account"
|
|
6
7
|
require "kamigo/events/basic_event"
|
|
7
8
|
require "kamigo/events/line_event"
|
|
8
9
|
require "kamigo/event_parsers/line_event_parser"
|
|
@@ -32,7 +33,7 @@ module Kamigo
|
|
|
32
33
|
EventProcessors::DefaultMessageProcessor.new
|
|
33
34
|
]
|
|
34
35
|
|
|
35
|
-
# LINE Messaging API configuration
|
|
36
|
+
# LINE Messaging API configuration (single account, backward compatible)
|
|
36
37
|
mattr_accessor :line_messaging_api_channel_id
|
|
37
38
|
@@line_messaging_api_channel_id = ENV["LINE_CHANNEL_ID"]
|
|
38
39
|
|
|
@@ -42,6 +43,10 @@ module Kamigo
|
|
|
42
43
|
mattr_accessor :line_messaging_api_channel_token
|
|
43
44
|
@@line_messaging_api_channel_token = ENV["LINE_CHANNEL_TOKEN"]
|
|
44
45
|
|
|
46
|
+
# Multi-account registry
|
|
47
|
+
mattr_accessor :line_accounts
|
|
48
|
+
@@line_accounts = {}
|
|
49
|
+
|
|
45
50
|
class << self
|
|
46
51
|
delegate :line_login_channel_id, :line_login_channel_id=, to: :Kamiliff
|
|
47
52
|
delegate :line_login_channel_secret, :line_login_channel_secret=, to: :Kamiliff
|
|
@@ -54,4 +59,27 @@ module Kamigo
|
|
|
54
59
|
def self.setup
|
|
55
60
|
yield self
|
|
56
61
|
end
|
|
62
|
+
|
|
63
|
+
def self.line_account(name)
|
|
64
|
+
account = LineAccount.new(name)
|
|
65
|
+
yield account
|
|
66
|
+
@@line_accounts[name.to_s] = account
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def self.find_account(name)
|
|
70
|
+
return default_account if name.blank?
|
|
71
|
+
@@line_accounts[name.to_s] || default_account
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.default_account
|
|
75
|
+
return @@line_accounts.values.first if @@line_accounts.any?
|
|
76
|
+
|
|
77
|
+
account = LineAccount.new("default")
|
|
78
|
+
account.channel_id = line_messaging_api_channel_id
|
|
79
|
+
account.channel_secret = line_messaging_api_channel_secret
|
|
80
|
+
account.channel_token = line_messaging_api_channel_token
|
|
81
|
+
account.default_path = default_path
|
|
82
|
+
account.default_http_method = default_http_method
|
|
83
|
+
account
|
|
84
|
+
end
|
|
57
85
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kamigo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.36.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- etrex
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-04-22 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: rails
|
|
@@ -126,6 +127,7 @@ files:
|
|
|
126
127
|
- lib/kamigo/event_responsers/line_event_responser.rb
|
|
127
128
|
- lib/kamigo/events/basic_event.rb
|
|
128
129
|
- lib/kamigo/events/line_event.rb
|
|
130
|
+
- lib/kamigo/line_account.rb
|
|
129
131
|
- lib/kamigo/railtie.rb
|
|
130
132
|
- lib/kamigo/request_handlers/line_request_handler.rb
|
|
131
133
|
- lib/kamigo/version.rb
|
|
@@ -133,6 +135,7 @@ homepage: https://github.com/etrex/kamigo
|
|
|
133
135
|
licenses:
|
|
134
136
|
- MIT
|
|
135
137
|
metadata: {}
|
|
138
|
+
post_install_message:
|
|
136
139
|
rdoc_options: []
|
|
137
140
|
require_paths:
|
|
138
141
|
- lib
|
|
@@ -147,7 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
147
150
|
- !ruby/object:Gem::Version
|
|
148
151
|
version: '0'
|
|
149
152
|
requirements: []
|
|
150
|
-
rubygems_version: 3.
|
|
153
|
+
rubygems_version: 3.5.16
|
|
154
|
+
signing_key:
|
|
151
155
|
specification_version: 4
|
|
152
156
|
summary: a chatbot framework based on rails
|
|
153
157
|
test_files: []
|