facebook-messenger 0.13.0 → 1.0.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
  SHA1:
3
- metadata.gz: ddbb553d6b155a4f6cbb160cfb404605df0705d6
4
- data.tar.gz: 23899394ed7e89b77701b6f634b595e770b735f2
3
+ metadata.gz: d44d493f7a90af8ada14c7bdcece0b54fa033abf
4
+ data.tar.gz: 5299267b035cda79e916beb6752fc736c9ec9853
5
5
  SHA512:
6
- metadata.gz: b8192c8d31b9bd123d836d37a3f67fe6aa823c5aa442db7e0b5221f6dba01817d8c66d9c0a571b2350f182f106f2797d5651cb44c581caf8631bf8c439c61e8c
7
- data.tar.gz: 5c3fdd4ddd9e19fdbde71cdb075b149155d8c3c8b9804163d2b2f0a344f91fbfd1e4dc60d2f1d80568a792ea704a2cb09b7076f49754d32f1dd127ea0d297d2f
6
+ metadata.gz: 5707bbee02a68b2bf370d841d8644c7b6bdd2acadbcc93083c0c76743d337e1aad126c731a2374a92b064e233a4bd8e1f02df7d1f958700ea81c084b04ccff63
7
+ data.tar.gz: 4db0e0fcd018f909478a98162275bbc91691a81ac1c40106ecec4eb0c2f4e276b16c1598713e6fbfcbadb580b212f2fa85266f1e66e4ca551749b7b6a9244909
data/README.md CHANGED
@@ -158,6 +158,24 @@ Bot.on :message do |message|
158
158
  end
159
159
  ```
160
160
 
161
+ ##### Record messages
162
+
163
+ You can keep track of messages sent to the human:
164
+
165
+ ```ruby
166
+ Bot.on :message_echo do |message_echo|
167
+ message_echo.id # => 'mid.1457764197618:41d102a3e1ae206a38'
168
+ message_echo.sender # => { 'id' => '1008372609250235' }
169
+ message_echo.seq # => 73
170
+ message_echo.sent_at # => 2016-04-22 21:30:36 +0200
171
+ message_echo.text # => 'Hello, bot!'
172
+ message_echo.attachments # => [ { 'type' => 'image', 'payload' => { 'url' => 'https://www.example.com/1.jpg' } } ]
173
+
174
+ # Log or store in your storage method of choice.
175
+ end
176
+ ```
177
+
178
+
161
179
  #### Send to Facebook
162
180
 
163
181
  When the human clicks the [Send to Messenger button][send-to-messenger-plugin]
@@ -287,9 +305,6 @@ Facebook::Messenger::Profile.set({
287
305
  Follow the [Quick Start][quick-start] guide to create an Application on
288
306
  Facebook.
289
307
 
290
- *Note*: Don't subscribe to `message_echoes`; it'll echo your bot's own messages
291
- back to you, effectively DDOSing yourself.
292
-
293
308
  [quick-start]: https://developers.facebook.com/docs/messenger-platform/guides/quick-start
294
309
 
295
310
  ### Make a configuration provider
@@ -342,6 +357,11 @@ from Facebook:
342
357
  Facebook::Messenger::Subscriptions.subscribe(access_token: access_token)
343
358
  ```
344
359
 
360
+ You only need to subscribe your page once. As long as your bot works and
361
+ responds to Messenger's requests in a timely fashion it will remain
362
+ subscribed, but if your bot crashes or otherwise becomes unavailable Messenger
363
+ may unsubscribe it and you'll have to subscribe again.
364
+
345
365
  ### Run it
346
366
 
347
367
  ##### ... on Rack
@@ -401,7 +421,7 @@ unless Rails.env.production?
401
421
  bot_files.each{ |file| require_dependency file }
402
422
  end
403
423
 
404
- ActionDispatch::Callbacks.to_prepare do
424
+ ActiveSupport::Reloader.to_prepare do
405
425
  bot_reloader.execute_if_updated
406
426
  end
407
427
 
@@ -445,6 +465,8 @@ for Facebook Messenger, and a great place to start if you're new to bots.
445
465
  * [Chatwoot](http://chatwoot.com/) use Facebook Messenger to integrate their customer
446
466
  support bots with, well, Facebook Messenger.
447
467
 
468
+ * [Botamp](https://botamp.com) is the all-in-one solution for Marketing Automation via messaging apps.
469
+
448
470
  ## Hyper loves you
449
471
 
450
472
  [Hyper] made this. We're a bunch of folks who love building things. You should
@@ -10,7 +10,14 @@ module Facebook
10
10
  base_uri 'https://graph.facebook.com/v2.6/me'
11
11
 
12
12
  EVENTS = %i[
13
- message delivery postback optin read account_linking referral
13
+ message
14
+ delivery
15
+ postback
16
+ optin
17
+ read
18
+ account_linking
19
+ referral
20
+ message_echo
14
21
  ].freeze
15
22
 
16
23
  class << self
@@ -1,5 +1,6 @@
1
1
  require 'facebook/messenger/incoming/common'
2
2
  require 'facebook/messenger/incoming/message'
3
+ require 'facebook/messenger/incoming/message_echo'
3
4
  require 'facebook/messenger/incoming/delivery'
4
5
  require 'facebook/messenger/incoming/postback'
5
6
  require 'facebook/messenger/incoming/optin'
@@ -19,7 +20,8 @@ module Facebook
19
20
  'optin' => Optin,
20
21
  'read' => Read,
21
22
  'account_linking' => AccountLinking,
22
- 'referral' => Referral
23
+ 'referral' => Referral,
24
+ 'message_echo' => MessageEcho
23
25
  }.freeze
24
26
 
25
27
  # Parse the given payload.
@@ -28,6 +30,8 @@ module Facebook
28
30
  #
29
31
  # * https://developers.facebook.com/docs/messenger-platform/webhook-reference
30
32
  def self.parse(payload)
33
+ return MessageEcho.new(payload) if payload_is_echo?(payload)
34
+
31
35
  EVENTS.each do |event, klass|
32
36
  return klass.new(payload) if payload.key?(event)
33
37
  end
@@ -35,6 +39,10 @@ module Facebook
35
39
  raise UnknownPayload, payload
36
40
  end
37
41
 
42
+ def self.payload_is_echo?(payload)
43
+ payload.key?('message') && payload['message']['is_echo'] == true
44
+ end
45
+
38
46
  class UnknownPayload < Facebook::Messenger::Error; end
39
47
  end
40
48
  end
@@ -0,0 +1,10 @@
1
+ module Facebook
2
+ module Messenger
3
+ module Incoming
4
+ # The Message echo class represents an
5
+ # incoming Facebook Messenger message
6
+ class MessageEcho < Message
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module Facebook
2
2
  module Messenger
3
- VERSION = '0.13.0'.freeze
3
+ VERSION = '1.0.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebook-messenger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 1.0.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: 2017-05-18 00:00:00.000000000 Z
11
+ date: 2017-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -180,6 +180,7 @@ files:
180
180
  - lib/facebook/messenger/incoming/common.rb
181
181
  - lib/facebook/messenger/incoming/delivery.rb
182
182
  - lib/facebook/messenger/incoming/message.rb
183
+ - lib/facebook/messenger/incoming/message_echo.rb
183
184
  - lib/facebook/messenger/incoming/optin.rb
184
185
  - lib/facebook/messenger/incoming/postback.rb
185
186
  - lib/facebook/messenger/incoming/read.rb