ruboty-line 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/Gemfile +0 -0
- data/README.md +7 -4
- data/Rakefile +0 -0
- data/lib/ruboty/adapters/line.rb +36 -38
- data/lib/ruboty/line/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ff75258dba6172f970e5aacc4befa9850e662117d77fbc5ae9d16d9dfc78b4d8
|
4
|
+
data.tar.gz: 1b6f9cfad6d73d7e748f8f8e02df789055c2ee545d1ac45fdb5176b530636ce0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d89f1ddddbafec394d1e66b8249bac78bc96e9192d3b304b2c8bc5849d206a5bfd31fe0177ce7fb35720bda75b128be803c36cdf0aa602c4389d20d1b1e70325
|
7
|
+
data.tar.gz: 017f423d9bcfdc28fb6e39bf98f2d2daf90b0a6a15f2da880ce5844eb2242a80db47b9913396e07cee44b808150d641253337efa2e0105c374afd46554ee40d1
|
data/.gitignore
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -12,11 +12,9 @@ gem "ruboty-line"
|
|
12
12
|
## ENV
|
13
13
|
|
14
14
|
```
|
15
|
-
RUBOTY_LINE_CHANNEL_ID - YOUR LINE BOT Channel ID.
|
16
15
|
RUBOTY_LINE_CHANNEL_SECRET - YOUR LINE BOT Channel Secret.
|
17
|
-
|
18
|
-
RUBOTY_LINE_ENDPOINT - LINE bot endpoint(Callback URL). (e.g. '/
|
19
|
-
RUBOTY_FIXIE_URL - Proxy URL.
|
16
|
+
RUBOTY_LINE_CHANNEL_TOKE - YOUR LINE BOT Channel token.
|
17
|
+
RUBOTY_LINE_ENDPOINT - LINE bot endpoint(Callback URL). (e.g. '/message/reply'
|
20
18
|
LOG_LEVEL - Use Ruboty logger. If LOG_LEVEL=0, output debug log.
|
21
19
|
```
|
22
20
|
|
@@ -26,6 +24,11 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/osyo-m
|
|
26
24
|
|
27
25
|
## Release note
|
28
26
|
|
27
|
+
#### 0.2.0
|
28
|
+
|
29
|
+
* Support Message API
|
30
|
+
* Remove support LINE BOT API(Trial)
|
31
|
+
|
29
32
|
#### 0.1.0
|
30
33
|
|
31
34
|
* Release!
|
data/Rakefile
CHANGED
File without changes
|
data/lib/ruboty/adapters/line.rb
CHANGED
@@ -2,26 +2,11 @@ require "rack"
|
|
2
2
|
require 'line/bot'
|
3
3
|
require 'rest-client'
|
4
4
|
|
5
|
-
module Line
|
6
|
-
module Bot
|
7
|
-
class HTTPClient
|
8
|
-
def post(url, payload, header = {})
|
9
|
-
Ruboty.logger.debug "======= HTTPClient#post ======="
|
10
|
-
Ruboty.logger.debug "payload #{payload}"
|
11
|
-
Ruboty.logger.debug "FIXIT_URL #{ENV["RUBOTY_FIXIE_URL"]}"
|
12
|
-
RestClient.proxy = ENV["RUBOTY_FIXIE_URL"] if ENV["RUBOTY_FIXIE_URL"]
|
13
|
-
RestClient.post(url, payload, header)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
5
|
|
20
6
|
module Ruboty module Adapters
|
21
7
|
class LINE < Base
|
22
|
-
env :RUBOTY_LINE_CHANNEL_ID, "YOUR LINE BOT Channel ID"
|
23
8
|
env :RUBOTY_LINE_CHANNEL_SECRET, "YOUR LINE BOT Channel Secret"
|
24
|
-
env :
|
9
|
+
env :RUBOTY_LINE_CHANNEL_TOKEN, "YOUR LINE BOT Channel token"
|
25
10
|
env :RUBOTY_LINE_ENDPOINT, "LINE bot endpoint(Callback URL). (e.g. '/ruboty/line'"
|
26
11
|
def run
|
27
12
|
Ruboty.logger.info "======= LINE#run ======="
|
@@ -31,67 +16,80 @@ module Ruboty module Adapters
|
|
31
16
|
def say msg
|
32
17
|
Ruboty.logger.info "======= LINE#say ======="
|
33
18
|
|
19
|
+
Ruboty.logger.info "msg : #{msg}"
|
34
20
|
text = msg[:body]
|
35
21
|
to = msg[:to]
|
36
22
|
|
37
23
|
Ruboty.logger.info "text : #{text}"
|
38
24
|
Ruboty.logger.debug "to : #{to}"
|
39
25
|
|
40
|
-
client.
|
41
|
-
|
42
|
-
text: text
|
43
|
-
)
|
26
|
+
client.reply_message(to, {
|
27
|
+
type: "text",
|
28
|
+
text: text,
|
29
|
+
})
|
44
30
|
end
|
45
31
|
|
46
32
|
private
|
47
33
|
def start_server
|
48
|
-
Rack::Handler::Thin.run(
|
34
|
+
Rack::Handler::Thin.run(proc { |env|
|
49
35
|
Ruboty.logger.info "======= LINE access ======="
|
50
36
|
Ruboty.logger.debug "env : #{env}"
|
51
37
|
|
52
|
-
request = ::
|
38
|
+
request = Rack::Request.new(env)
|
39
|
+
Ruboty.logger.debug "request : #{request}"
|
40
|
+
|
53
41
|
result = on_post request
|
54
42
|
|
55
43
|
[200, {"Content-Type" => "text/plain"}, [result]]
|
56
44
|
}, { Port: ENV["PORT"] || "8080" })
|
57
45
|
end
|
58
46
|
|
59
|
-
def on_post
|
47
|
+
def on_post request
|
60
48
|
Ruboty.logger.info "======= LINE#on_post ======="
|
61
|
-
Ruboty.logger.debug "request : #{req}"
|
62
49
|
|
63
|
-
|
50
|
+
Ruboty.logger.debug "request.fullpath : #{request.fullpath}"
|
51
|
+
Ruboty.logger.debug "request.post? : #{request.post?}"
|
52
|
+
Ruboty.logger.debug "RUBOTY_LINE_ENDPOINT : #{ENV["RUBOTY_LINE_ENDPOINT"]}"
|
53
|
+
|
54
|
+
return "OK" unless request.post? && request.fullpath == ENV["RUBOTY_LINE_ENDPOINT"]
|
55
|
+
|
56
|
+
body = request.body.read
|
57
|
+
Ruboty.logger.debug "request.body : #{body}"
|
64
58
|
|
65
|
-
|
59
|
+
events = client.parse_events_from(body)
|
60
|
+
|
66
61
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
62
|
+
events.each { |event|
|
63
|
+
Ruboty.logger.debug "event : #{event}"
|
64
|
+
case event
|
65
|
+
when ::Line::Bot::Event::Message
|
66
|
+
case event.type
|
67
|
+
when ::Line::Bot::Event::MessageType::Text
|
68
|
+
on_message event
|
69
|
+
end
|
71
70
|
end
|
72
71
|
}
|
73
72
|
|
74
73
|
return ""
|
75
74
|
end
|
76
75
|
|
77
|
-
def on_message
|
76
|
+
def on_message event
|
78
77
|
Ruboty.logger.info "======= LINE#on_message ======="
|
79
|
-
Ruboty.logger.debug "content : #{msg.content}"
|
80
78
|
|
81
79
|
Thread.start {
|
82
80
|
robot.receive(
|
83
|
-
body:
|
84
|
-
from:
|
85
|
-
to:
|
86
|
-
|
81
|
+
body: event.message["text"],
|
82
|
+
from: event["replyToken"],
|
83
|
+
to: event["replyToken"],
|
84
|
+
event: event
|
85
|
+
)
|
87
86
|
}
|
88
87
|
end
|
89
88
|
|
90
89
|
def client
|
91
90
|
@client ||= ::Line::Bot::Client.new { |config|
|
92
|
-
config.channel_id = ENV["RUBOTY_LINE_CHANNEL_ID"]
|
93
91
|
config.channel_secret = ENV["RUBOTY_LINE_CHANNEL_SECRET"]
|
94
|
-
config.
|
92
|
+
config.channel_token = ENV["RUBOTY_LINE_CHANNEL_TOKEN"]
|
95
93
|
}
|
96
94
|
end
|
97
95
|
end
|
data/lib/ruboty/line/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-line
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- manga_osyo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
version: '0'
|
147
147
|
requirements: []
|
148
148
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.7.3
|
150
150
|
signing_key:
|
151
151
|
specification_version: 4
|
152
152
|
summary: LINE adapter for Ruboty.
|