stealth-facebook 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5f352636c999182ab5ab0059b65ac878f233c921639c886d969140f4218092a
4
- data.tar.gz: fe85dd2fd4fc0093f46b1bc922b3ff152fcf71dd2552ed9972f4531827ef8a29
3
+ metadata.gz: efd8e39db98abfbcdbdae8a6203d342a3b106b1ad724375679ffd3f72ea22176
4
+ data.tar.gz: f5653657b82b3e6002122b4b0202e27075e9dbdee2655b0a92aabc7ddec761a1
5
5
  SHA512:
6
- metadata.gz: d0c9dee3070ec9efa473ab1aff1cf6596278e0fdb2adfdf8957eb0f061773df92208197a249505b9176e69a3819ba8751c7fbd4062abf958261209631c00a560
7
- data.tar.gz: 962575b7130ccff7d0e10c8870b5a7caf3c2b2a4d60e1d719541e4136eef3a69bb90f50607c0935da8dd63ae1fcb9cd3bdb17beda05764bdd685ac8ef120d471
6
+ metadata.gz: 591195dc3f5b845ba7fb1cdce466a1a5a3c530448369360ca9bc7c9c20e51c39732fd8842824b8d32c94b65c78486579044147f9fd1be24e7d22831e0dd2e5fa
7
+ data.tar.gz: aa23afc24d70d6f0284ef75428a39ed700bb9ed5d6d432e59f28a5906dd96311fcc8311dddb82aa6e14973e67928cc80fb7ac363df5323e00086055b87274bea
data/README.md CHANGED
@@ -12,7 +12,18 @@ When configuring your webhooks, you'll want to enable the `messages`, `messaging
12
12
 
13
13
  <img src='fb-config.png' width='875px' alt='Facebook Config Screenshot' />
14
14
 
15
- Make sure you don't enable `message_reads` as that is not yet supported by this gem.
15
+ ### message_reads
16
+
17
+ Beginning with version `0.13.0` of this gem, `message_reads` webhooks are supported. When enabled in your Facebook configuration, they will appear as `current_message.read`. That will return a hash:
18
+
19
+ ```ruby
20
+ {
21
+ watermark: 1458668856253,
22
+ seq: 38
23
+ }
24
+ ```
25
+
26
+ More info about `message_reads` webhooks can be found in the [Facebook Developer docs](https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/message-reads).
16
27
 
17
28
  ## Configure The Integration
18
29
 
@@ -130,9 +141,9 @@ fb_profile = Stealth::Services::Facebook::Client.fetch_profile(
130
141
 
131
142
  ### Analytics
132
143
 
133
- If you'd like to track custom bot metrics in addition to the ones provided automatically by Facebook Analytics, you can do so in starting in version `0.12.0` of this gem.
144
+ If you'd like to track custom bot metrics in addition to the ones provided automatically by Facebook Analytics, you can do so starting with version `0.12.0` of this gem.
134
145
 
135
- In order to send these metrics, you'll need to add the `app_id` of the bot as well as the `page_id` of the Facebook page (attached to the bot) to `services.yml`:
146
+ In order to send these metrics, you'll need to include the `app_id` of the bot as well as the `page_id` of the Facebook page (attached to the bot) to `services.yml`:
136
147
 
137
148
  ```yaml
138
149
  default: &default
@@ -150,7 +161,7 @@ Then to collect a metric:
150
161
  Stealth::Services::Facebook::Client.track(recipient_id: u.recipient_id, metric: 'name of your metric', value: 2)
151
162
  ```
152
163
 
153
- To specify additional options:
164
+ You can specify additional options:
154
165
 
155
166
  ```ruby
156
167
  Stealth::Services::Facebook::Client.track(recipient_id: u.recipient_id, metric: 'signup', value: 2, options: { 'fb_description' => 'A signup occured.' })
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.12.0
1
+ 0.13.0
@@ -0,0 +1,49 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+
5
+
6
+ module Stealth
7
+ module Services
8
+ module Facebook
9
+
10
+ class MessageReadsEvent
11
+
12
+ attr_reader :service_message, :params
13
+
14
+ def initialize(service_message:, params:)
15
+ @service_message = service_message
16
+ @params = params
17
+ end
18
+
19
+ def process
20
+ fetch_read
21
+ end
22
+
23
+ private
24
+
25
+ def fetch_read
26
+ service_message.read = { watermark: get_timestamp, seq: params['read']['seq'] }
27
+ end
28
+
29
+ def get_timestamp
30
+ Time.at(params['read']['watermark']/1000).to_datetime
31
+ end
32
+ end
33
+
34
+ module ReadsEvent
35
+ attr_accessor :read
36
+ def initialize(service:)
37
+ @read = {}
38
+ super
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+
45
+
46
+ class ServiceMessage
47
+ prepend Services::Facebook::ReadsEvent
48
+ end
49
+ end
@@ -3,6 +3,7 @@
3
3
 
4
4
  require 'stealth/services/facebook/events/message_event'
5
5
  require 'stealth/services/facebook/events/postback_event'
6
+ require 'stealth/services/facebook/events/message_reads_event'
6
7
 
7
8
  module Stealth
8
9
  module Services
@@ -73,6 +74,11 @@ module Stealth
73
74
  service_message: service_message,
74
75
  params: facebook_message
75
76
  )
77
+ elsif facebook_message['read'].present?
78
+ message_event = Stealth::Services::Facebook::MessageReadsEvent.new(
79
+ service_message: service_message,
80
+ params: facebook_message
81
+ )
76
82
  end
77
83
 
78
84
  message_event.process
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stealth-facebook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Gomes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-14 00:00:00.000000000 Z
11
+ date: 2018-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stealth
@@ -98,6 +98,7 @@ files:
98
98
  - lib/stealth/facebook.rb
99
99
  - lib/stealth/services/facebook/client.rb
100
100
  - lib/stealth/services/facebook/events/message_event.rb
101
+ - lib/stealth/services/facebook/events/message_reads_event.rb
101
102
  - lib/stealth/services/facebook/events/postback_event.rb
102
103
  - lib/stealth/services/facebook/message_handler.rb
103
104
  - lib/stealth/services/facebook/reply_handler.rb