kamigo 0.20.0 → 0.25.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: 7378b8ac81d656a0279ae87d084410ff9ac89944054ad6f26a2571e94a3cf694
4
- data.tar.gz: 3ca981698b7693e4ff20e3fd45bb38a47b60fa4b7fe20d57339997764609d286
3
+ metadata.gz: cd8914c615cbe6e276dc27fb3e666567cffe819e1235a98eab1cb5b784738b8e
4
+ data.tar.gz: 47b4cf9cb513585ae8cad02a64238faf6c03f26bb968d0c0d77b5d690f7c8052
5
5
  SHA512:
6
- metadata.gz: 505d6d3f8d32b016d0dbd72b3d35af48a065631a500d34575eff79fc1916f203395f6b7d60439ed9633b1c973ce840d1d02b9da7778c46719232ac8bf9e40ab4
7
- data.tar.gz: 414c7828e10aea9c7c74a62b4c2dab36ab8e798c56f61bf2696c6ce51750e1e8083dd3d7d268ea38e855513f535a57a43a2ad4549cfc65d6a89d534cac4de4fc
6
+ metadata.gz: 8675bb0ffcae2124d20cd512727e67f3f73d5e2119ebf173f7fe073332b3bde5678a33ddf38bc4215bbe3baccd6475165d96c3d6ea89c008efeb0002c77b18b2
7
+ data.tar.gz: 27ba23384392a2cf0e1aab6d66957669ab3c762b4efb51d02624c6770f9971c418e8e3249cb0da6e6a8cf584fc9fe5a7362a6bd42917dd0536f2617ad6aea381
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
 
@@ -88,7 +92,7 @@ window.addEventListener("liff_submit", function(event){
88
92
  https://你的網域/line
89
93
  ```
90
94
 
91
- 第一次開發 LINE Bot 的人可以服用此帖 [Webhook URL 設定 QA](/doc/06_setting.md#Webhook-URL-設定-QA)。
95
+ 第一次開發 LINE Bot 的人可以服用此帖 [Webhook URL 設定 QA](/doc/07_setting.md#Webhook-URL-設定-QA)。
92
96
 
93
97
  # 設定聊天機器人環境變數
94
98
  請在專案根目錄下新增一個 `.env` 檔並且填入以下內容:
@@ -106,7 +110,7 @@ LIFF_FULL=這裡填入你的 FULL_LIFF_URL
106
110
  - `COMPACT_LIFF_URL`、`TALL_LIFF_URL` 和 `FULL_LIFF_URL` 需要到 LINE 後台的 LIFF 分頁新增後,即可獲得一組 LIFF URL。
107
111
 
108
112
  Kamigo 預設的 LIFF Size 為 Compact,你也可以只新增 Compact LIFF URL。
109
- 詳細的 LIFF 設定說明可以服用此帖 [LIFF 設定 QA](/doc/06_setting.md#LIFF-設定-QA)。
113
+ 詳細的 LIFF 設定說明可以服用此帖 [LIFF 設定 QA](/doc/07_setting.md#LIFF-設定-QA)。
110
114
 
111
115
  至此串接完成。
112
116
 
@@ -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
@@ -13,10 +13,13 @@ module Kamigo
13
13
  def platform_params
14
14
  {
15
15
  platform_type: platform_type,
16
+ message: message,
17
+ message_type: message_type,
16
18
  source_type: source_type,
17
19
  source_group_id: source_group_id,
18
20
  source_user_id: source_user_id,
19
- profile: profile
21
+ profile: profile,
22
+ payload: payload
20
23
  }
21
24
  end
22
25
  end
@@ -1,3 +1,3 @@
1
1
  module Kamigo
2
- VERSION = '0.20.0'.freeze
2
+ VERSION = '0.25.0'.freeze
3
3
  end
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.20.0
4
+ version: 0.25.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-04-03 00:00:00.000000000 Z
11
+ date: 2021-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,40 +30,40 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.25'
33
+ version: '0.29'
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: 0.25.0
36
+ version: 0.29.0
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: '0.25'
43
+ version: '0.29'
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 0.25.0
46
+ version: 0.29.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: kamiflex
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.11'
53
+ version: '0.17'
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 0.11.0
56
+ version: 0.17.0
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: '0.11'
63
+ version: '0.17'
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: 0.11.0
66
+ version: 0.17.0
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: line-bot-api
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -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