kamigo 0.9.0 → 0.14.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 +78 -17
- data/app/controllers/line_controller.rb +1 -1
- data/lib/kamigo/event_responsers/line_event_responser.rb +3 -1
- data/lib/kamigo/version.rb +1 -1
- metadata +26 -15
- data/lib/generators/rails/kamigo/state_generator.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa6261bf0404dd6f3cdc88dce3f6ed5fd1b99240986f5523c980bf67be020a18
|
4
|
+
data.tar.gz: a7936a209e8e7b7b0496e13efd9aee3ad7dc95b86c834dd447a09fc5c3a88197
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d172ea63954894592d0dbad7823e0c9a6c47aa96acbb40078cf522e0b4be31dd3f167f4347d57a644e09cfd215c767a7d93f4ebd0d8c5515603f2ae56408bd3c
|
7
|
+
data.tar.gz: df8dc0dc851a7ba5afa798b610c0574acf8602a16d4f81ebc7d97de82b37b42e83c8777207eb8eb0d554dcb11c93e5f3431b50b459eb631af45bcbeb2b5c157d
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# Kamigo 簡介
|
2
|
-
|
3
2
|
Kamigo 是一個基於 Rails 的 Chatbot MVC Framework。
|
4
3
|
|
5
4
|
Kamigo 讓你開發 Chatbot 就跟開發網站一樣容易,甚至可以同時開發網站以及 Chatbot 介面,共用 Controller 和 Model,只需要針對 Chatbot 實作 View。
|
@@ -9,7 +8,7 @@ Kamigo 提供了重要的 generator,讓你開發聊天機器人時可以快的
|
|
9
8
|
以下將說明如何使用 Kamigo 來製作 Todo 的教學文件。
|
10
9
|
|
11
10
|
# 建立新的 rails 專案
|
12
|
-
|
11
|
+
將以下指令全部複製,直接貼到 bash 執行即可。
|
13
12
|
|
14
13
|
```bash
|
15
14
|
# 建立新專案
|
@@ -26,49 +25,109 @@ rails db:migrate
|
|
26
25
|
```
|
27
26
|
|
28
27
|
# 設定首頁
|
29
|
-
在 config/routes.rb 當中加入首頁設定:
|
28
|
+
在 `config/routes.rb` 當中加入首頁設定:
|
30
29
|
|
31
30
|
```
|
32
31
|
root to: "todos#index"
|
33
32
|
```
|
34
33
|
|
35
34
|
# 安裝 js 套件
|
36
|
-
|
35
|
+
|
36
|
+
若使用 Asset Pipeline(Rails 5),請在 `app/assets/javascripts/application.js` 當中
|
37
|
+
|
38
|
+
加入以下程式碼:
|
37
39
|
|
38
40
|
```
|
39
41
|
//= require kamiliff
|
40
42
|
```
|
41
43
|
|
42
|
-
|
43
|
-
本文假設你已經有一個自己的聊天機器人,請在專案根目錄下新增一個 `.env` 檔並且填入以下內容:
|
44
|
+
或者加入以下程式碼:
|
44
45
|
|
45
46
|
```
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
/* kamiliff default behavior */
|
48
|
+
window.addEventListener("liff_ready", function(event){
|
49
|
+
register_kamiliff_submit();
|
50
|
+
});
|
51
|
+
|
52
|
+
window.addEventListener("liff_submit", function(event){
|
53
|
+
var json = JSON.stringify(event.detail.data);
|
54
|
+
var url = event.detail.url;
|
55
|
+
var method = event.detail.method;
|
56
|
+
var request_text = method + " " + url + "\n" + json;
|
57
|
+
liff_send_text_message(request_text);
|
58
|
+
});
|
51
59
|
```
|
52
60
|
|
53
|
-
|
61
|
+
若使用 Webpacker(Rails 6),請在 `app/javascript/packs/application.js` 當中
|
62
|
+
|
63
|
+
加入以下程式碼:
|
54
64
|
|
55
|
-
|
65
|
+
```
|
66
|
+
/* kamiliff default behavior */
|
67
|
+
window.addEventListener("liff_ready", function(event){
|
68
|
+
register_kamiliff_submit();
|
69
|
+
});
|
70
|
+
|
71
|
+
window.addEventListener("liff_submit", function(event){
|
72
|
+
var json = JSON.stringify(event.detail.data);
|
73
|
+
var url = event.detail.url;
|
74
|
+
var method = event.detail.method;
|
75
|
+
var request_text = method + " " + url + "\n" + json;
|
76
|
+
liff_send_text_message(request_text);
|
77
|
+
});
|
78
|
+
```
|
56
79
|
|
57
|
-
|
80
|
+
這會影響 LINE Bot 在 LIFF 送出表單時的行為。
|
58
81
|
|
59
|
-
|
82
|
+
# 設定聊天機器人 Webhook URL
|
83
|
+
本文假設你已經有一個自己的聊天機器人,請將以下網址填入 LINE Bot 的 Webhook URL 欄位中:
|
60
84
|
|
61
85
|
```
|
62
86
|
https://你的網域/line
|
63
87
|
```
|
64
88
|
|
89
|
+
第一次開發 LINE Bot 的人可以服用此帖 [Webhook URL 設定 QA](/doc/06_setting.md#Webhook-URL-設定-QA)。
|
90
|
+
|
91
|
+
# 設定聊天機器人環境變數
|
92
|
+
請在專案根目錄下新增一個 `.env` 檔並且填入以下內容:
|
93
|
+
|
94
|
+
```
|
95
|
+
LINE_CHANNEL_SECRET=這裡填入你的 LINE_CHANNEL_SECRET
|
96
|
+
LINE_CHANNEL_TOKEN=這裡填入你的 LINE_CHANNEL_ACCESS_TOKEN
|
97
|
+
LIFF_COMPACT=這裡填入你的 COMPACT_LIFF_URL
|
98
|
+
LIFF_TALL=這裡填入你的 TALL_LIFF_URL
|
99
|
+
LIFF_FULL=這裡填入你的 FULL_LIFF_URL
|
100
|
+
```
|
101
|
+
|
102
|
+
- `LINE_CHANNEL_SECRET` 可以在 Messaging API 後台的 Basic settings 分頁中找到。
|
103
|
+
- `LINE_CHANNEL_ACCESS_TOKEN` 可以在 Messaging API 後台的 Messaging API 分頁中找到。
|
104
|
+
- `COMPACT_LIFF_URL`、`TALL_LIFF_URL` 和 `FULL_LIFF_URL` 需要到 LINE 後台的 LIFF 分頁新增後,即可獲得一組 LIFF URL。
|
105
|
+
|
106
|
+
Kamigo 預設的 LIFF Size 為 Compact,你也可以只新增 Compact LIFF URL。
|
107
|
+
詳細的 LIFF 設定說明可以服用此帖 [LIFF 設定 QA](/doc/06_setting.md#LIFF-設定-QA)。
|
108
|
+
|
65
109
|
至此串接完成。
|
66
110
|
|
67
|
-
#
|
111
|
+
# Rails 6 注意事項
|
68
112
|
|
113
|
+
若使用 ngrok 在本機開發時,需要在 `config/application.rb` 加入以下程式碼:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
...
|
117
|
+
module KamigoDemo
|
118
|
+
class Application < Rails::Application
|
119
|
+
...
|
120
|
+
config.hosts << "你的亂碼.ngrok.io"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
才能正常連線。
|
126
|
+
|
127
|
+
# 實際使用
|
69
128
|
Kamigo 預設使用基本的語意理解模型,會將使用者輸入視為在瀏覽器網址上輸入文字,並且以 LINE Flex Message 來顯示對應的結果。
|
70
129
|
|
71
|
-
|
130
|
+
開啟 LINE 和聊天機器人說 `/`,就能看到首頁的樣子。
|
72
131
|
|
73
132
|
# 使用 kamigo 製作的聊天機器人
|
74
133
|
- [kamigo demo](https://github.com/etrex/kamigo_demo)
|
@@ -77,12 +136,14 @@ Kamigo 預設使用基本的語意理解模型,會將使用者輸入視為在
|
|
77
136
|
<p><img width="100" height="100" src="https://camo.githubusercontent.com/b8c51b15b20b159d356245277d079c04482acc01/68747470733a2f2f692e696d6775722e636f6d2f7534547675676e2e706e67"></p>
|
78
137
|
- 守護寵物機器人
|
79
138
|
<p><img width="100" height="100" src="/doc/images/pet_loved_qrcode.png"></p>
|
139
|
+
|
80
140
|
# 詳細的說明文件
|
81
141
|
- [Kamigo 架構概觀](/doc/01_intro.md)
|
82
142
|
- [Route 的使用說明](/doc/02_route.md)
|
83
143
|
- [Controller 的使用說明](/doc/03_controller.md)
|
84
144
|
- [View 的使用說明](/doc/04_view.md)
|
85
145
|
- [Form 的使用說明](/doc/05_form.md)
|
146
|
+
- [Kamigo 相關設定與 QA](/doc/06_setting.md)
|
86
147
|
|
87
148
|
# 計畫
|
88
149
|
- 提供多種語意理解模型串接
|
@@ -23,7 +23,7 @@ class LineController < ApplicationController
|
|
23
23
|
output = reserve_route(encoded_path, http_method: http_method, request_params: request_params, format: :line)
|
24
24
|
responser = Kamigo::EventResponsers::LineEventResponser.new
|
25
25
|
response = responser.response_event(event, output)
|
26
|
-
puts response
|
26
|
+
puts response&.body
|
27
27
|
rescue NoMethodError => e
|
28
28
|
puts e.full_message
|
29
29
|
responser = Kamigo::EventResponsers::LineEventResponser.new
|
@@ -4,7 +4,9 @@ module Kamigo
|
|
4
4
|
include Kamigo::Clients::LineClient
|
5
5
|
|
6
6
|
def response_event(event, message)
|
7
|
-
|
7
|
+
return nil if message.blank?
|
8
|
+
message = JSON.parse(message) if message.is_a?(String) && message.start_with?("{")
|
9
|
+
return nil if message.blank?
|
8
10
|
response = client.reply_message(event.reply_token, message)
|
9
11
|
response
|
10
12
|
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.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- etrex
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -28,20 +28,29 @@ dependencies:
|
|
28
28
|
name: kamiliff
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.21'
|
31
34
|
- - ">="
|
32
35
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
36
|
+
version: 0.21.0
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.21'
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
46
|
+
version: 0.21.0
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: kamiflex
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.11'
|
45
54
|
- - ">="
|
46
55
|
- !ruby/object:Gem::Version
|
47
56
|
version: 0.11.0
|
@@ -49,6 +58,9 @@ dependencies:
|
|
49
58
|
prerelease: false
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
51
60
|
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0.11'
|
52
64
|
- - ">="
|
53
65
|
- !ruby/object:Gem::Version
|
54
66
|
version: 0.11.0
|
@@ -56,30 +68,30 @@ dependencies:
|
|
56
68
|
name: line-bot-api
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
58
70
|
requirements:
|
59
|
-
- - "
|
71
|
+
- - "~>"
|
60
72
|
- !ruby/object:Gem::Version
|
61
73
|
version: '1.5'
|
62
74
|
type: :runtime
|
63
75
|
prerelease: false
|
64
76
|
version_requirements: !ruby/object:Gem::Requirement
|
65
77
|
requirements:
|
66
|
-
- - "
|
78
|
+
- - "~>"
|
67
79
|
- !ruby/object:Gem::Version
|
68
80
|
version: '1.5'
|
69
81
|
- !ruby/object:Gem::Dependency
|
70
82
|
name: sqlite3
|
71
83
|
requirement: !ruby/object:Gem::Requirement
|
72
84
|
requirements:
|
73
|
-
- - "
|
85
|
+
- - "~>"
|
74
86
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
87
|
+
version: '1.0'
|
76
88
|
type: :development
|
77
89
|
prerelease: false
|
78
90
|
version_requirements: !ruby/object:Gem::Requirement
|
79
91
|
requirements:
|
80
|
-
- - "
|
92
|
+
- - "~>"
|
81
93
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
94
|
+
version: '1.0'
|
83
95
|
description: a chatbot framework based on rails
|
84
96
|
email:
|
85
97
|
- et284vu065k3@gmail.com
|
@@ -97,7 +109,6 @@ files:
|
|
97
109
|
- config/routes.rb
|
98
110
|
- lib/generators/rails/kamigo/USAGE
|
99
111
|
- lib/generators/rails/kamigo/kamigo_generator.rb
|
100
|
-
- lib/generators/rails/kamigo/state_generator.rb
|
101
112
|
- lib/generators/rails/kamigo/templates/edit.liff.erb
|
102
113
|
- lib/generators/rails/kamigo/templates/index.line.erb
|
103
114
|
- lib/generators/rails/kamigo/templates/new.liff.erb
|
@@ -117,7 +128,7 @@ homepage: https://github.com/etrex/kamigo
|
|
117
128
|
licenses:
|
118
129
|
- MIT
|
119
130
|
metadata: {}
|
120
|
-
post_install_message:
|
131
|
+
post_install_message:
|
121
132
|
rdoc_options: []
|
122
133
|
require_paths:
|
123
134
|
- lib
|
@@ -132,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
143
|
- !ruby/object:Gem::Version
|
133
144
|
version: '0'
|
134
145
|
requirements: []
|
135
|
-
rubygems_version: 3.
|
136
|
-
signing_key:
|
146
|
+
rubygems_version: 3.1.2
|
147
|
+
signing_key:
|
137
148
|
specification_version: 4
|
138
149
|
summary: a chatbot framework based on rails
|
139
150
|
test_files: []
|
@@ -1,56 +0,0 @@
|
|
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
|