kamigo 0.20.0 → 0.21.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 +4 -4
- data/README.md +4 -8
- data/lib/generators/rails/kamigo/state_generator.rb +56 -0
- data/lib/kamigo/event_parsers/line_event_parser.rb +19 -2
- data/lib/kamigo/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 603369132a555eac9c1006ef6c72942613f949a7969062cbb6a1113082cdfa01
|
4
|
+
data.tar.gz: 1723ac2a6317728974b8f8605e244490277851e652732524637ac41ba208bc1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12a69d80119b1b44d96c65aa917c4df52cf7103b6588938d1004bc7c110d022bd6d1dc749c88539d93fe734c2916cca73e53bc0d4966dc7997c79331f5778583
|
7
|
+
data.tar.gz: 51e23e962faafa4abd7a7fd153c3187147d1a9bb7f1905f32fda1efeb91ad63db00e1a26d70f41703317423fdf229f0e24f468eeceaeed734dac537c9e574645
|
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 詳細的說明文件
|
2
|
+
|
3
|
+
[Kamigo 詳細說明](https://etrex.tw/kamigo/)
|
4
|
+
|
1
5
|
# Kamigo 簡介
|
2
6
|
Kamigo 是一個基於 Rails 的 Chatbot MVC Framework。
|
3
7
|
|
@@ -139,14 +143,6 @@ Kamigo 預設使用基本的語意理解模型,會將使用者輸入視為在
|
|
139
143
|
- 守護寵物機器人
|
140
144
|
<p><img width="100" height="100" src="/doc/images/pet_loved_qrcode.png"></p>
|
141
145
|
|
142
|
-
# 詳細的說明文件
|
143
|
-
- [Kamigo 架構概觀](/doc/01_intro.md)
|
144
|
-
- [Route 的使用說明](/doc/02_route.md)
|
145
|
-
- [Controller 的使用說明](/doc/03_controller.md)
|
146
|
-
- [View 的使用說明](/doc/04_view.md)
|
147
|
-
- [Form 的使用說明](/doc/05_form.md)
|
148
|
-
- [Kamigo 相關設定與 QA](/doc/06_setting.md)
|
149
|
-
|
150
146
|
# 計畫
|
151
147
|
- 提供多種語意理解模型串接
|
152
148
|
- DialogFlow
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
require 'rails/generators/resource_helpers'
|
3
|
+
|
4
|
+
module Rails
|
5
|
+
module Generators
|
6
|
+
class CreateStateGenerator < NamedBase
|
7
|
+
include Rails::Generators::ResourceHelpers
|
8
|
+
namespace "devise"
|
9
|
+
argument :attributes, type: :string, default: 'kamigo_state'
|
10
|
+
|
11
|
+
class_option :timestamps, type: :boolean, default: true
|
12
|
+
|
13
|
+
def create_root_folder
|
14
|
+
path = File.join('app/views', controller_file_path)
|
15
|
+
empty_directory path unless File.directory?(path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_view_files
|
19
|
+
filenames.each do |filename|
|
20
|
+
template filename, File.join('app/views', controller_file_path, filename)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def attributes_names
|
27
|
+
[:id] + super
|
28
|
+
end
|
29
|
+
|
30
|
+
def filenames
|
31
|
+
[
|
32
|
+
"index.line.erb",
|
33
|
+
"show.line.erb",
|
34
|
+
"edit.liff.erb",
|
35
|
+
"new.liff.erb",
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
def full_attributes_list
|
40
|
+
if options[:timestamps]
|
41
|
+
attributes_list(attributes_names + %w(created_at updated_at))
|
42
|
+
else
|
43
|
+
attributes_list(attributes_names)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def attributes_list(attributes = attributes_names)
|
48
|
+
if self.attributes.any? {|attr| attr.name == 'password' && attr.type == :digest}
|
49
|
+
attributes = attributes.reject {|name| %w(password password_confirmation).include? name}
|
50
|
+
end
|
51
|
+
|
52
|
+
attributes.map { |a| ":#{a}"} * ', '
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -14,18 +14,35 @@ module Kamigo
|
|
14
14
|
def parse(event)
|
15
15
|
event_hash = JSON.parse(event.to_json, symbolize_names: true)
|
16
16
|
payload = event_hash[:src] || event_hash
|
17
|
-
response = client.get_profile(payload[:source][:userId])
|
18
17
|
line_event = Kamigo::Events::LineEvent.new
|
19
18
|
line_event.payload = payload
|
20
19
|
line_event.reply_token = event['replyToken']
|
21
|
-
line_event.profile = JSON.parse(response.body)
|
22
20
|
line_event.source_type = payload.dig(:source, :type)
|
23
21
|
line_event.source_group_id = payload.dig(:source, :groupId) || payload.dig(:source, :roomId) || payload.dig(:source, :userId)
|
24
22
|
line_event.source_user_id = payload.dig(:source, :userId) || payload.dig(:source, :groupId) || payload.dig(:source, :roomId)
|
25
23
|
line_event.message_type = payload.dig(:message, :type) || payload.dig(:type)
|
26
24
|
line_event.message = payload.dig(:message, :text) || payload.dig(:postback, :data) || payload.dig(:message, :address) || line_event.message_type
|
25
|
+
line_event.profile = get_profile(line_event)
|
27
26
|
line_event
|
28
27
|
end
|
28
|
+
|
29
|
+
def get_profile(line_event)
|
30
|
+
case line_event.source_type
|
31
|
+
when 'group'
|
32
|
+
response = client.get_group_member_profile(
|
33
|
+
line_event.source_group_id,
|
34
|
+
line_event.source_user_id
|
35
|
+
)
|
36
|
+
when 'room'
|
37
|
+
response = client.get_room_member_profile(
|
38
|
+
line_event.source_group_id,
|
39
|
+
line_event.source_user_id
|
40
|
+
)
|
41
|
+
else
|
42
|
+
response = client.get_profile(line_event.source_user_id)
|
43
|
+
end
|
44
|
+
JSON.parse(response.body)
|
45
|
+
end
|
29
46
|
end
|
30
47
|
end
|
31
48
|
end
|
data/lib/kamigo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +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.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- etrex
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- lib/generators/kamigo/install_generator.rb
|
110
110
|
- lib/generators/rails/kamigo/USAGE
|
111
111
|
- lib/generators/rails/kamigo/kamigo_generator.rb
|
112
|
+
- lib/generators/rails/kamigo/state_generator.rb
|
112
113
|
- lib/generators/rails/kamigo/templates/edit.liff.erb
|
113
114
|
- lib/generators/rails/kamigo/templates/index.line.erb
|
114
115
|
- lib/generators/rails/kamigo/templates/new.liff.erb
|