ruboty-line 0.1.0 → 0.2.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
- SHA1:
3
- metadata.gz: 077b976bdc23c573e7f97c719cb313b8b35c3532
4
- data.tar.gz: 3f325a187c660d9a35ec2d8fb71169c392a9e681
2
+ SHA256:
3
+ metadata.gz: ff75258dba6172f970e5aacc4befa9850e662117d77fbc5ae9d16d9dfc78b4d8
4
+ data.tar.gz: 1b6f9cfad6d73d7e748f8f8e02df789055c2ee545d1ac45fdb5176b530636ce0
5
5
  SHA512:
6
- metadata.gz: eba29af7cbaea7dc4b217ddc7473fa0999cce467970becd3c9e6534fabebf6619f3cb37f1ab04830c584dc39e7f3f8edd4ac400eaaf2bbaed0f72c240480321b
7
- data.tar.gz: 8face0e1c6fe19b1a83b199c7c829d7626f4eca08f3d3e6c05830cb861c095d61a68a6c54e47c873f186d2a99f9e626bdcb6e7936cd293d6e33c6bee903a677d
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
- RUBOTY_LINE_CHANNEL_MID - YOUR LINE BOT MID'
18
- RUBOTY_LINE_ENDPOINT - LINE bot endpoint(Callback URL). (e.g. '/ruboty/line'
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
@@ -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 :RUBOTY_LINE_CHANNEL_MID, "YOUR LINE BOT MID"
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.send_text(
41
- to_mid: to,
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(Proc.new{ |env|
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 = ::Line::Bot::Receive::Request.new(env)
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 req
47
+ def on_post request
60
48
  Ruboty.logger.info "======= LINE#on_post ======="
61
- Ruboty.logger.debug "request : #{req}"
62
49
 
63
- return "OK" unless req.post? && req.fullpath == ENV["RUBOTY_LINE_ENDPOINT"]
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
- Ruboty.logger.debug "request.body : #{req.data}"
59
+ events = client.parse_events_from(body)
60
+
66
61
 
67
- req.data.each { |message|
68
- case message.content
69
- when ::Line::Bot::Message::Text
70
- on_message message
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 msg
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: msg.content[:text],
84
- from: msg.from_mid,
85
- to: msg.from_mid,
86
- message: msg)
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.channel_mid = ENV["RUBOTY_LINE_CHANNEL_MID"]
92
+ config.channel_token = ENV["RUBOTY_LINE_CHANNEL_TOKEN"]
95
93
  }
96
94
  end
97
95
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Line
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
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.1.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: 2016-07-07 00:00:00.000000000 Z
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.4.5.1
149
+ rubygems_version: 2.7.3
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: LINE adapter for Ruboty.