facebook-messenger 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -2
- data/lib/facebook/messenger/bot.rb +4 -9
- data/lib/facebook/messenger/concerns/default_options.rb +26 -0
- data/lib/facebook/messenger/incoming.rb +4 -1
- data/lib/facebook/messenger/incoming/account_linking.rb +38 -0
- data/lib/facebook/messenger/incoming/message.rb +4 -0
- data/lib/facebook/messenger/incoming/optin.rb +1 -17
- data/lib/facebook/messenger/incoming/postback.rb +1 -17
- data/lib/facebook/messenger/version.rb +1 -1
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63684aa5b0f6fa5f0cc2539f21bf569d660d506a
|
4
|
+
data.tar.gz: a788b3312c44fde7f4150ceeeb3685c2766a37ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c39580382e83ae750ea5ec37ef8fff253fb11cba05e5f5e9aa11f43205a7ba872e74fa5c27b77d8d4ec7d0e16de22ea34b79f1e4bb38c694f22f2d94dea531f0
|
7
|
+
data.tar.gz: 3b597ced101202b833077912cd2ebb870b5f6384356ac097a339212495f811af7f0e3e6cd5432335f57666fc6e52a35329f0532965817dc06b4c55483b2344cd
|
data/README.md
CHANGED
@@ -307,15 +307,32 @@ end
|
|
307
307
|
|
308
308
|
Remember that Rails only eager loads everything in its production environment.
|
309
309
|
In the development and test environments, it only requires files as you
|
310
|
-
reference constants. You'll need to explicitly load `app/
|
310
|
+
reference constants. You'll need to explicitly load `app/bots`, then:
|
311
311
|
|
312
312
|
```ruby
|
313
313
|
# config/initializers/bot.rb
|
314
314
|
unless Rails.env.production?
|
315
|
-
Dir[
|
315
|
+
bot_files = Dir[Rails.root.join('app', 'bots', '**', '*.rb')]
|
316
|
+
bots_reloader = ActiveSupport::FileUpdateChecker.new(bot_files) do
|
317
|
+
bot_files.each{ |file| require_dependency file }
|
318
|
+
end
|
319
|
+
|
320
|
+
ActionDispatch::Callbacks.to_prepare do
|
321
|
+
bot_reloader.execute_if_updated
|
322
|
+
end
|
323
|
+
|
324
|
+
bot_files.each { |file| require_dependency file }
|
316
325
|
end
|
317
326
|
```
|
318
327
|
|
328
|
+
And add below code into `config/application.rb` to ensure rails knows bot files.
|
329
|
+
|
330
|
+
```ruby
|
331
|
+
# Auto-load bots and its subdirectories
|
332
|
+
config.paths.add File.join('app', 'bots'), glob: File.join('**', '*.rb')
|
333
|
+
config.autoload_paths += Dir[Rails.root.join('app', 'bots', '*')]
|
334
|
+
```
|
335
|
+
|
319
336
|
To test your locally running bot, you can use [ngrok]. This will create a secure
|
320
337
|
tunnel to localhost so that Facebook can reach the webhook.
|
321
338
|
|
@@ -6,7 +6,8 @@ module Facebook
|
|
6
6
|
|
7
7
|
base_uri 'https://graph.facebook.com/v2.6/me'
|
8
8
|
|
9
|
-
EVENTS = [:message, :delivery, :postback, :optin
|
9
|
+
EVENTS = [:message, :delivery, :postback, :optin,
|
10
|
+
:read, :account_linking].freeze
|
10
11
|
|
11
12
|
class << self
|
12
13
|
# Deliver a message with the given payload.
|
@@ -46,14 +47,8 @@ module Facebook
|
|
46
47
|
# * https://developers.facebook.com/docs/messenger-platform/webhook-reference
|
47
48
|
def receive(payload)
|
48
49
|
callback = Facebook::Messenger::Incoming.parse(payload)
|
49
|
-
|
50
|
-
|
51
|
-
when Incoming::Message then trigger(:message, callback)
|
52
|
-
when Incoming::Delivery then trigger(:delivery, callback)
|
53
|
-
when Incoming::Postback then trigger(:postback, callback)
|
54
|
-
when Incoming::Optin then trigger(:optin, callback)
|
55
|
-
when Incoming::Read then trigger(:read, callback)
|
56
|
-
end
|
50
|
+
event = Facebook::Messenger::Incoming::EVENTS.invert[callback.class]
|
51
|
+
trigger(event.to_sym, callback)
|
57
52
|
end
|
58
53
|
|
59
54
|
# Trigger the hook for the given event.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Facebook
|
2
|
+
module Messenger
|
3
|
+
module Concerns
|
4
|
+
# The Common options for incoming optin and postback.
|
5
|
+
module DefaultOptions
|
6
|
+
attr_reader :messaging
|
7
|
+
|
8
|
+
def initialize(messaging)
|
9
|
+
@messaging = messaging
|
10
|
+
end
|
11
|
+
|
12
|
+
def sender
|
13
|
+
@messaging['sender']
|
14
|
+
end
|
15
|
+
|
16
|
+
def recipient
|
17
|
+
@messaging['recipient']
|
18
|
+
end
|
19
|
+
|
20
|
+
def sent_at
|
21
|
+
Time.at(@messaging['timestamp'] / 1000)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
require 'facebook/messenger/concerns/default_options'
|
1
2
|
require 'facebook/messenger/incoming/message'
|
2
3
|
require 'facebook/messenger/incoming/delivery'
|
3
4
|
require 'facebook/messenger/incoming/postback'
|
4
5
|
require 'facebook/messenger/incoming/optin'
|
5
6
|
require 'facebook/messenger/incoming/read'
|
7
|
+
require 'facebook/messenger/incoming/account_linking'
|
6
8
|
|
7
9
|
module Facebook
|
8
10
|
module Messenger
|
@@ -14,7 +16,8 @@ module Facebook
|
|
14
16
|
'delivery' => Delivery,
|
15
17
|
'postback' => Postback,
|
16
18
|
'optin' => Optin,
|
17
|
-
'read' => Read
|
19
|
+
'read' => Read,
|
20
|
+
'account_linking' => AccountLinking
|
18
21
|
}.freeze
|
19
22
|
|
20
23
|
# Parse the given payload.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Facebook
|
2
|
+
module Messenger
|
3
|
+
module Incoming
|
4
|
+
# The AccountLinking class represents an incoming Facebook Messenger
|
5
|
+
# Account Linking webhook, when the Linked Account
|
6
|
+
# or Unlink Account call-to-action have been tapped
|
7
|
+
#
|
8
|
+
# https://developers.facebook.com/docs/messenger-platform/webhook-reference/account-linking
|
9
|
+
class AccountLinking
|
10
|
+
attr_reader :messaging
|
11
|
+
|
12
|
+
def initialize(messaging)
|
13
|
+
@messaging = messaging
|
14
|
+
end
|
15
|
+
|
16
|
+
def sender
|
17
|
+
@messaging['sender']
|
18
|
+
end
|
19
|
+
|
20
|
+
def recipient
|
21
|
+
@messaging['recipient']
|
22
|
+
end
|
23
|
+
|
24
|
+
def sent_at
|
25
|
+
Time.at(@messaging['timestamp'] / 1000)
|
26
|
+
end
|
27
|
+
|
28
|
+
def status
|
29
|
+
@messaging['account_linking']['status']
|
30
|
+
end
|
31
|
+
|
32
|
+
def authorization_code
|
33
|
+
@messaging['account_linking']['authorization_code']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -6,23 +6,7 @@ module Facebook
|
|
6
6
|
#
|
7
7
|
# https://developers.facebook.com/docs/messenger-platform/plugin-reference
|
8
8
|
class Optin
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(messaging)
|
12
|
-
@messaging = messaging
|
13
|
-
end
|
14
|
-
|
15
|
-
def sender
|
16
|
-
@messaging['sender']
|
17
|
-
end
|
18
|
-
|
19
|
-
def recipient
|
20
|
-
@messaging['recipient']
|
21
|
-
end
|
22
|
-
|
23
|
-
def sent_at
|
24
|
-
Time.at(@messaging['timestamp'] / 1000)
|
25
|
-
end
|
9
|
+
include Facebook::Messenger::Concerns::DefaultOptions
|
26
10
|
|
27
11
|
def ref
|
28
12
|
@messaging['optin']['ref']
|
@@ -3,23 +3,7 @@ module Facebook
|
|
3
3
|
module Incoming
|
4
4
|
# The Postback class represents an incoming Facebook Messenger postback.
|
5
5
|
class Postback
|
6
|
-
|
7
|
-
|
8
|
-
def initialize(messaging)
|
9
|
-
@messaging = messaging
|
10
|
-
end
|
11
|
-
|
12
|
-
def sender
|
13
|
-
@messaging['sender']
|
14
|
-
end
|
15
|
-
|
16
|
-
def recipient
|
17
|
-
@messaging['recipient']
|
18
|
-
end
|
19
|
-
|
20
|
-
def sent_at
|
21
|
-
Time.at(@messaging['timestamp'] / 1000)
|
22
|
-
end
|
6
|
+
include Facebook::Messenger::Concerns::DefaultOptions
|
23
7
|
|
24
8
|
def payload
|
25
9
|
@messaging['postback']['payload']
|
metadata
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facebook-messenger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johannes Gorset
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.13'
|
20
|
+
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 0.13.7
|
20
23
|
type: :runtime
|
@@ -22,6 +25,9 @@ dependencies:
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.13'
|
30
|
+
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: 0.13.7
|
27
33
|
- !ruby/object:Gem::Dependency
|
@@ -162,9 +168,11 @@ files:
|
|
162
168
|
- bin/setup
|
163
169
|
- lib/facebook/messenger.rb
|
164
170
|
- lib/facebook/messenger/bot.rb
|
171
|
+
- lib/facebook/messenger/concerns/default_options.rb
|
165
172
|
- lib/facebook/messenger/configuration.rb
|
166
173
|
- lib/facebook/messenger/error.rb
|
167
174
|
- lib/facebook/messenger/incoming.rb
|
175
|
+
- lib/facebook/messenger/incoming/account_linking.rb
|
168
176
|
- lib/facebook/messenger/incoming/delivery.rb
|
169
177
|
- lib/facebook/messenger/incoming/message.rb
|
170
178
|
- lib/facebook/messenger/incoming/optin.rb
|