facebook-messenger 2.0.1 → 2.1.2
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 +4 -4
- data/README.md +10 -12
- data/lib/facebook/messenger/bot.rb +32 -2
- data/lib/facebook/messenger/incoming/feed.rb +16 -0
- data/lib/facebook/messenger/incoming/feed_common.rb +17 -0
- data/lib/facebook/messenger/incoming/leadgen.rb +13 -0
- data/lib/facebook/messenger/incoming.rb +7 -2
- data/lib/facebook/messenger/profile.rb +1 -1
- data/lib/facebook/messenger/server.rb +18 -7
- data/lib/facebook/messenger/subscriptions.rb +1 -1
- data/lib/facebook/messenger/version.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4f6b7cdaf4658871a6b72a385cb5e2df054abac1849f809bd7e02f760ef09bb0
|
|
4
|
+
data.tar.gz: 53a3dc676588d46a339bbf1d4117addafc88b28ecb35a81e14c49e91e0124905
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cc00a75c7a6bacdb963a5fd71747788676cdb23c35eab75bc13b5bf289708451a279ccdb444d69f86938caec99ab6c82581382c5853155f06e785dadb06cfb88
|
|
7
|
+
data.tar.gz: 90eba5323395d6085bf7d4e4729e3649a046a15b9fa37497df8cca4b99969bae7e4d6fb45481a958e5a3f4c750a60593cbbff1772bf4095c49689b9cc788a1ef
|
data/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://
|
|
2
|
+
<img src="https://github.com/jgorset/facebook-messenger/blob/master/docs/conversation.gif?raw=true">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
|
|
@@ -24,9 +24,7 @@ You can reply to messages sent by the human:
|
|
|
24
24
|
# bot.rb
|
|
25
25
|
require 'facebook/messenger'
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Bot.on :message do |message|
|
|
27
|
+
Facebook::Messenger::Bot.on :message do |message|
|
|
30
28
|
message.id # => 'mid.1457764197618:41d102a3e1ae206a38'
|
|
31
29
|
message.sender # => { 'id' => '1008372609250235' }
|
|
32
30
|
message.recipient # => { 'id' => '2015573629214912' }
|
|
@@ -42,7 +40,7 @@ end
|
|
|
42
40
|
... or even send the human messages out of the blue:
|
|
43
41
|
|
|
44
42
|
```ruby
|
|
45
|
-
Bot.deliver({
|
|
43
|
+
Facebook::Messenger::Bot.deliver({
|
|
46
44
|
recipient: {
|
|
47
45
|
id: YOUR_RECIPIENT_ID
|
|
48
46
|
},
|
|
@@ -179,7 +177,7 @@ end
|
|
|
179
177
|
You can keep track of messages sent to the human:
|
|
180
178
|
|
|
181
179
|
```ruby
|
|
182
|
-
Bot.on :message_echo do |message_echo|
|
|
180
|
+
Facebook::Messenger::Bot.on :message_echo do |message_echo|
|
|
183
181
|
message_echo.id # => 'mid.1457764197618:41d102a3e1ae206a38'
|
|
184
182
|
message_echo.sender # => { 'id' => '1008372609250235' }
|
|
185
183
|
message_echo.seq # => 73
|
|
@@ -258,7 +256,7 @@ When the human follows a m.me link with a ref parameter like http://m.me/mybot?r
|
|
|
258
256
|
you will receive a `referral` event.
|
|
259
257
|
|
|
260
258
|
```ruby
|
|
261
|
-
Bot.on :referral do |referral|
|
|
259
|
+
Facebook::Messenger::Bot.on :referral do |referral|
|
|
262
260
|
referral.sender # => { 'id' => '1008372609250235' }
|
|
263
261
|
referral.recipient # => { 'id' => '2015573629214912' }
|
|
264
262
|
referral.sent_at # => 2016-04-22 21:30:36 +0200
|
|
@@ -271,7 +269,7 @@ end
|
|
|
271
269
|
Another bot can pass a human to you:
|
|
272
270
|
|
|
273
271
|
```ruby
|
|
274
|
-
Bot.on :pass_thread_control do |pass_thread_control|
|
|
272
|
+
Facebook::Messenger::Bot.on :pass_thread_control do |pass_thread_control|
|
|
275
273
|
pass_thread_control.new_owner_app_id # => '123456789'
|
|
276
274
|
pass_thread_control.metadata # => 'Additional content that the caller wants to set'
|
|
277
275
|
end
|
|
@@ -358,7 +356,7 @@ Facebook::Messenger::Profile.set({
|
|
|
358
356
|
See Facebook's documentation on [Messaging Policy Enforcement](https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/messaging_policy_enforcement)
|
|
359
357
|
|
|
360
358
|
```ruby
|
|
361
|
-
Bot.on :'policy_enforcement' do |referral|
|
|
359
|
+
Facebook::Messenger::Bot.on :'policy_enforcement' do |referral|
|
|
362
360
|
referral.action # => 'block'
|
|
363
361
|
referral.reason # => "The bot violated our Platform Policies (https://developers.facebook.com/policy/#messengerplatform). Common violations include sending out excessive spammy messages or being non-functional."
|
|
364
362
|
end
|
|
@@ -373,7 +371,7 @@ See Facebook's documentation on [Sending Messages](https://developers.facebook.c
|
|
|
373
371
|
As of May 7th 2018 all messages are required to include a messaging_type
|
|
374
372
|
|
|
375
373
|
```ruby
|
|
376
|
-
Bot.deliver({
|
|
374
|
+
Facebook::Messenger::Bot.deliver({
|
|
377
375
|
recipient: {
|
|
378
376
|
id: '45123'
|
|
379
377
|
},
|
|
@@ -391,7 +389,7 @@ See Facebook's documentation on [Message Tags](https://developers.facebook.com/d
|
|
|
391
389
|
When sending a message with messaging_type: MESSAGE_TAG (Facebook::Messenger::Bot::MessagingType::MESSAGE_TAG) you must ensure you add a tag: parameter
|
|
392
390
|
|
|
393
391
|
```ruby
|
|
394
|
-
Bot.deliver({
|
|
392
|
+
Facebook::Messenger::Bot.deliver({
|
|
395
393
|
recipient: {
|
|
396
394
|
id: '45123'
|
|
397
395
|
},
|
|
@@ -536,7 +534,7 @@ We suggest that you put your bot code in `app/bot`.
|
|
|
536
534
|
|
|
537
535
|
include Facebook::Messenger
|
|
538
536
|
|
|
539
|
-
Bot.on :message do |message|
|
|
537
|
+
Faceboook::Messenger::Bot.on :message do |message|
|
|
540
538
|
message.reply(text: 'Hello, human!')
|
|
541
539
|
end
|
|
542
540
|
```
|
|
@@ -13,7 +13,7 @@ module Facebook
|
|
|
13
13
|
include HTTParty
|
|
14
14
|
|
|
15
15
|
# Define base_uri for HTTParty.
|
|
16
|
-
base_uri 'https://graph.facebook.com/
|
|
16
|
+
base_uri 'https://graph.facebook.com/v20.0'
|
|
17
17
|
|
|
18
18
|
#
|
|
19
19
|
# @return [Array] Array containing the supported webhook events.
|
|
@@ -31,6 +31,8 @@ module Facebook
|
|
|
31
31
|
pass_thread_control
|
|
32
32
|
game_play
|
|
33
33
|
reaction
|
|
34
|
+
feed
|
|
35
|
+
leadgen
|
|
34
36
|
].freeze
|
|
35
37
|
|
|
36
38
|
class << self
|
|
@@ -52,7 +54,35 @@ module Facebook
|
|
|
52
54
|
query = { access_token: access_token }
|
|
53
55
|
query[:appsecret_proof] = app_secret_proof if app_secret_proof
|
|
54
56
|
|
|
55
|
-
response = post '/messages',
|
|
57
|
+
response = post '/me/messages',
|
|
58
|
+
body: JSON.dump(message),
|
|
59
|
+
format: :json,
|
|
60
|
+
query: query
|
|
61
|
+
|
|
62
|
+
Facebook::Messenger::Bot::ErrorParser.raise_errors_from(response)
|
|
63
|
+
|
|
64
|
+
response.body
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Reply to a Facebook comment.
|
|
68
|
+
# @see https://developers.facebook.com/docs/graph-api/reference/v20.0/object/comments
|
|
69
|
+
#
|
|
70
|
+
# @raise [Facebook::Messenger::Bot::SendError] if there is any error
|
|
71
|
+
# in response while sending the comment.
|
|
72
|
+
#
|
|
73
|
+
# @param [Hash] comment The comment payload
|
|
74
|
+
# @param [String] page_id The page ID to send the comment from
|
|
75
|
+
#
|
|
76
|
+
# Returns a Hash describing the API response if the comment was sent,
|
|
77
|
+
# or raises an exception if it was not.
|
|
78
|
+
def reply_to_comment(comment_id, message, page_id:)
|
|
79
|
+
access_token = config.provider.access_token_for(page_id)
|
|
80
|
+
app_secret_proof = config.provider.app_secret_proof_for(page_id)
|
|
81
|
+
|
|
82
|
+
query = { access_token: access_token }
|
|
83
|
+
query[:appsecret_proof] = app_secret_proof if app_secret_proof
|
|
84
|
+
|
|
85
|
+
response = post "/#{comment_id}/comments",
|
|
56
86
|
body: JSON.dump(message),
|
|
57
87
|
format: :json,
|
|
58
88
|
query: query
|
|
@@ -13,6 +13,9 @@ require 'facebook/messenger/incoming/policy_enforcement'
|
|
|
13
13
|
require 'facebook/messenger/incoming/pass_thread_control'
|
|
14
14
|
require 'facebook/messenger/incoming/game_play'
|
|
15
15
|
require 'facebook/messenger/incoming/message_reaction'
|
|
16
|
+
require 'facebook/messenger/incoming/feed_common'
|
|
17
|
+
require 'facebook/messenger/incoming/feed'
|
|
18
|
+
require 'facebook/messenger/incoming/leadgen'
|
|
16
19
|
|
|
17
20
|
module Facebook
|
|
18
21
|
module Messenger
|
|
@@ -37,7 +40,9 @@ module Facebook
|
|
|
37
40
|
'policy_enforcement' => PolicyEnforcement,
|
|
38
41
|
'pass_thread_control' => PassThreadControl,
|
|
39
42
|
'game_play' => GamePlay,
|
|
40
|
-
'reaction' => MessageReaction
|
|
43
|
+
'reaction' => MessageReaction,
|
|
44
|
+
'feed' => Feed,
|
|
45
|
+
'leadgen' => Leadgen,
|
|
41
46
|
}.freeze
|
|
42
47
|
|
|
43
48
|
# Parse the given payload and create new object of class related
|
|
@@ -54,7 +59,7 @@ module Facebook
|
|
|
54
59
|
return MessageEcho.new(payload) if payload_is_echo?(payload)
|
|
55
60
|
|
|
56
61
|
EVENTS.each do |event, klass|
|
|
57
|
-
return klass.new(payload) if payload.key?(event)
|
|
62
|
+
return klass.new(payload) if payload.key?(event) || payload['field'] == event
|
|
58
63
|
end
|
|
59
64
|
|
|
60
65
|
raise UnknownPayload, payload
|
|
@@ -144,8 +144,8 @@ module Facebook
|
|
|
144
144
|
#
|
|
145
145
|
def parsed_body
|
|
146
146
|
@parsed_body ||= JSON.parse(body)
|
|
147
|
-
rescue JSON::ParserError
|
|
148
|
-
raise BadRequestError,
|
|
147
|
+
rescue JSON::ParserError => error
|
|
148
|
+
raise BadRequestError, error
|
|
149
149
|
end
|
|
150
150
|
|
|
151
151
|
#
|
|
@@ -157,15 +157,26 @@ module Facebook
|
|
|
157
157
|
# Facebook may batch several items in the 'entry' array during
|
|
158
158
|
# periods of high load.
|
|
159
159
|
events['entry'.freeze].each do |entry|
|
|
160
|
-
# If the application has subscribed to webhooks other than Messenger,
|
|
161
|
-
# 'messaging' won't be available and it is not relevant to us.
|
|
162
|
-
next unless entry['messaging'.freeze]
|
|
163
160
|
|
|
164
161
|
# Facebook may batch several items in the 'messaging' array during
|
|
165
162
|
# periods of high load.
|
|
166
|
-
entry['messaging'.freeze]
|
|
167
|
-
|
|
163
|
+
if entry['messaging'.freeze]
|
|
164
|
+
entry['messaging'.freeze].each do |messaging|
|
|
165
|
+
Facebook::Messenger::Bot.receive(messaging)
|
|
166
|
+
end
|
|
168
167
|
end
|
|
168
|
+
if entry['changes'.freeze]
|
|
169
|
+
entry['changes'.freeze].each do |change|
|
|
170
|
+
Facebook::Messenger::Bot.receive(change)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
# d99d
|
|
174
|
+
if entry['standby'.freeze]
|
|
175
|
+
entry['standby'.freeze].each do |messaging|
|
|
176
|
+
Facebook::Messenger::Bot.receive(messaging)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
# .
|
|
169
180
|
end
|
|
170
181
|
end
|
|
171
182
|
|
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: 2.
|
|
4
|
+
version: 2.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Johannes Gorset
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-12-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|
|
@@ -50,14 +50,14 @@ dependencies:
|
|
|
50
50
|
requirements:
|
|
51
51
|
- - "~>"
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: 2.1
|
|
53
|
+
version: '2.1'
|
|
54
54
|
type: :development
|
|
55
55
|
prerelease: false
|
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
|
57
57
|
requirements:
|
|
58
58
|
- - "~>"
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: 2.1
|
|
60
|
+
version: '2.1'
|
|
61
61
|
- !ruby/object:Gem::Dependency
|
|
62
62
|
name: coveralls
|
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -183,7 +183,10 @@ files:
|
|
|
183
183
|
- lib/facebook/messenger/incoming/account_linking.rb
|
|
184
184
|
- lib/facebook/messenger/incoming/common.rb
|
|
185
185
|
- lib/facebook/messenger/incoming/delivery.rb
|
|
186
|
+
- lib/facebook/messenger/incoming/feed.rb
|
|
187
|
+
- lib/facebook/messenger/incoming/feed_common.rb
|
|
186
188
|
- lib/facebook/messenger/incoming/game_play.rb
|
|
189
|
+
- lib/facebook/messenger/incoming/leadgen.rb
|
|
187
190
|
- lib/facebook/messenger/incoming/message.rb
|
|
188
191
|
- lib/facebook/messenger/incoming/message_echo.rb
|
|
189
192
|
- lib/facebook/messenger/incoming/message_reaction.rb
|
|
@@ -219,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
219
222
|
- !ruby/object:Gem::Version
|
|
220
223
|
version: '0'
|
|
221
224
|
requirements: []
|
|
222
|
-
rubygems_version: 3.0.
|
|
225
|
+
rubygems_version: 3.0.3.1
|
|
223
226
|
signing_key:
|
|
224
227
|
specification_version: 4
|
|
225
228
|
summary: Facebook Messenger client
|