facebook-messenger 1.2.0 → 2.0.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 +53 -7
- data/lib/facebook/messenger/bot.rb +10 -9
- data/lib/facebook/messenger/incoming.rb +7 -1
- data/lib/facebook/messenger/incoming/common.rb +6 -27
- data/lib/facebook/messenger/incoming/game_play.rb +39 -0
- data/lib/facebook/messenger/incoming/message_reaction.rb +23 -0
- data/lib/facebook/messenger/incoming/pass_thread_control.rb +22 -0
- data/lib/facebook/messenger/profile.rb +1 -1
- data/lib/facebook/messenger/subscriptions.rb +6 -4
- data/lib/facebook/messenger/version.rb +1 -1
- metadata +14 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b757052cad527d03939514250e2f3fc87fbc21e0e7c86e9f78c8a2087ed925f1
|
4
|
+
data.tar.gz: 9f18c41169ded5554f49e3faa2e22a94565f83461bc2de688ad87957426791a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23d252fce2c080a7d95f1b25795ca423e7efac86c52e7dc158203c4f0b840d3b7c14b499919a3d9fab58cdf49e1bed274a7220f25b31c235e0e93fb457e45ff2
|
7
|
+
data.tar.gz: 1aa9d963cfecb848d000a4df931a1d30430005eff5b5f58cc18f8094092956077b354e589527770007e081b3f8d0cf7a67f1229da21a3b1ce453ff94a7dbca65
|
data/README.md
CHANGED
@@ -4,9 +4,10 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
[![Gem Version](https://img.shields.io/gem/v/facebook-messenger.svg?style=flat)](https://rubygems.org/gems/facebook-messenger)
|
7
|
-
[![
|
8
|
-
[![
|
9
|
-
[![
|
7
|
+
[![Gem Downloads](https://img.shields.io/gem/dt/facebook-messenger.svg)](https://rubygems.org/gems/facebook-messenger)
|
8
|
+
[![Build Status](https://img.shields.io/travis/jgorset/facebook-messenger.svg?style=flat)](https://travis-ci.org/jgorset/facebook-messenger)
|
9
|
+
[![Code Climate](https://img.shields.io/codeclimate/maintainability/jgorset/facebook-messenger.svg)](https://codeclimate.com/github/jgorset/facebook-messenger)
|
10
|
+
[![Coverage Status](https://coveralls.io/repos/github/jgorset/facebook-messenger/badge.svg?branch=master)](https://coveralls.io/github/jgorset/facebook-messenger?branch=master)
|
10
11
|
[![Documentation Coverage](http://inch-ci.org/github/jgorset/facebook-messenger.svg?branch=master)](http://inch-ci.org/github/jgorset/facebook-messenger)
|
11
12
|
|
12
13
|
## Installation
|
@@ -28,6 +29,7 @@ include Facebook::Messenger
|
|
28
29
|
Bot.on :message do |message|
|
29
30
|
message.id # => 'mid.1457764197618:41d102a3e1ae206a38'
|
30
31
|
message.sender # => { 'id' => '1008372609250235' }
|
32
|
+
message.recipient # => { 'id' => '2015573629214912' }
|
31
33
|
message.seq # => 73
|
32
34
|
message.sent_at # => 2016-04-22 21:30:36 +0200
|
33
35
|
message.text # => 'Hello, bot!'
|
@@ -47,7 +49,7 @@ Bot.deliver({
|
|
47
49
|
message: {
|
48
50
|
text: 'Human?'
|
49
51
|
},
|
50
|
-
|
52
|
+
messaging_type: Facebook::Messenger::Bot::MessagingType::UPDATE
|
51
53
|
}, access_token: ENV['ACCESS_TOKEN'], app_secret_proof: app_secret_proof
|
52
54
|
)
|
53
55
|
```
|
@@ -56,7 +58,7 @@ NOTE: `app_secret_proof` is an optional parameter to [secure your requests](http
|
|
56
58
|
and you can generate it from your configuration provider like so:
|
57
59
|
|
58
60
|
```ruby
|
59
|
-
configuration_provider = Facebook::Messenger::Configuration::Providers
|
61
|
+
configuration_provider = Facebook::Messenger::Configuration::Providers::Environment.new
|
60
62
|
app_secret_proof = configuration_provider.app_secret_proof_for(page_id)
|
61
63
|
```
|
62
64
|
|
@@ -132,6 +134,20 @@ end
|
|
132
134
|
|
133
135
|
*See Facebook's [documentation][message-documentation] for all message options.*
|
134
136
|
|
137
|
+
##### Reactions
|
138
|
+
|
139
|
+
Humans have feelings, and they can react to your messages. You can pretend to understand:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
Bot.on :reaction do |message|
|
143
|
+
message.emoji # => "👍"
|
144
|
+
message.action # => "react"
|
145
|
+
message.reaction # => "like"
|
146
|
+
|
147
|
+
message.reply(text: 'Your feelings have been registered')
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
135
151
|
##### Typing indicator
|
136
152
|
|
137
153
|
Show the human you are preparing a message for them:
|
@@ -199,6 +215,23 @@ Bot.on :message_request do |message_request|
|
|
199
215
|
end
|
200
216
|
```
|
201
217
|
|
218
|
+
##### Record instant game progress
|
219
|
+
|
220
|
+
You can keep track of instant game progress:
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
Bot.on :game_play do |game_play|
|
224
|
+
game_play.sender # => { 'id' => '1008372609250235' }
|
225
|
+
game_play.recipient # => { 'id' => '2015573629214912' }
|
226
|
+
game_play.sent_at # => 2016-04-22 21:30:36 +0200
|
227
|
+
game_play.game # => "<GAME-APP-ID>"
|
228
|
+
game_play.player # => "<PLAYER-ID>"
|
229
|
+
game_play.context # => { 'context_type' => "<CONTEXT-TYPE:SOLO|THREAD>", 'context_id' => "<CONTEXT-ID>" }
|
230
|
+
game_play.score # => 100
|
231
|
+
game_play.payload # => "<PAYLOAD>"
|
232
|
+
end
|
233
|
+
```
|
234
|
+
|
202
235
|
#### Send to Facebook
|
203
236
|
|
204
237
|
When the human clicks the [Send to Messenger button][send-to-messenger-plugin]
|
@@ -245,6 +278,17 @@ Bot.on :referral do |referral|
|
|
245
278
|
end
|
246
279
|
```
|
247
280
|
|
281
|
+
#### Pass thread control
|
282
|
+
|
283
|
+
Another bot can pass a human to you:
|
284
|
+
|
285
|
+
```ruby
|
286
|
+
Bot.on :pass_thread_control do |pass_thread_control|
|
287
|
+
pass_thread_control.new_owner_app_id # => '123456789'
|
288
|
+
pass_thread_control.metadata # => 'Additional content that the caller wants to set'
|
289
|
+
end
|
290
|
+
```
|
291
|
+
|
248
292
|
#### Change messenger profile
|
249
293
|
|
250
294
|
You can greet new humans to entice them into talking to you, in different locales:
|
@@ -346,7 +390,7 @@ Bot.deliver({
|
|
346
390
|
message: {
|
347
391
|
text: 'Human?'
|
348
392
|
},
|
349
|
-
|
393
|
+
messaging_type: Facebook::Messenger::Bot::MessagingType::UPDATE
|
350
394
|
}, access_token: ENV['ACCESS_TOKEN'])
|
351
395
|
```
|
352
396
|
|
@@ -363,7 +407,7 @@ Bot.deliver({
|
|
363
407
|
message: {
|
364
408
|
text: 'Human?'
|
365
409
|
},
|
366
|
-
|
410
|
+
messaging_type: Facebook::Messenger::Bot::MessagingType::MESSAGE_TAG
|
367
411
|
tag: Facebook::Messenger::Bot::Tag::NON_PROMOTIONAL_SUBSCRIPTION
|
368
412
|
}, access_token: ENV['ACCESS_TOKEN'])
|
369
413
|
```
|
@@ -438,6 +482,8 @@ Facebook::Messenger.configure do |config|
|
|
438
482
|
end
|
439
483
|
```
|
440
484
|
|
485
|
+
You can get the current configuration provider with `Facebook::Messenger.config.provider`.
|
486
|
+
|
441
487
|
### Subscribe your Application to a Page
|
442
488
|
|
443
489
|
Once you've configured your bot, subscribe it to the Page to get messages
|
@@ -28,6 +28,9 @@ module Facebook
|
|
28
28
|
message_echo
|
29
29
|
payment
|
30
30
|
policy_enforcement
|
31
|
+
pass_thread_control
|
32
|
+
game_play
|
33
|
+
reaction
|
31
34
|
].freeze
|
32
35
|
|
33
36
|
class << self
|
@@ -38,19 +41,17 @@ module Facebook
|
|
38
41
|
# in response while sending message.
|
39
42
|
#
|
40
43
|
# @param [Hash] message A Hash describing the recipient and the message.
|
41
|
-
# @param [String]
|
42
|
-
# @param [String] app_secret_proof proof of the app_secret
|
43
|
-
# https://developers.facebook.com/docs/graph-api/securing-requests/
|
44
|
-
# Note: we provide a helper function available at
|
45
|
-
# Messenger::Configuration::Providers::Base#calculate_app_secret_proof
|
44
|
+
# @param [String] page_id A String describing the Facebook Page ID to send the message from.
|
46
45
|
#
|
47
46
|
# Returns a String describing the message ID if the message was sent,
|
48
47
|
# or raises an exception if it was not.
|
49
|
-
def deliver(message,
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
def deliver(message, page_id:)
|
49
|
+
access_token = Facebook::Messenger.config.provider.access_token_for(page_id)
|
50
|
+
app_secret_proof = Facebook::Messenger.config.provider.app_secret_proof_for(page_id)
|
51
|
+
|
52
|
+
query = { access_token: access_token }
|
53
53
|
query[:appsecret_proof] = app_secret_proof if app_secret_proof
|
54
|
+
|
54
55
|
response = post '/messages',
|
55
56
|
body: JSON.dump(message),
|
56
57
|
format: :json,
|
@@ -10,6 +10,9 @@ require 'facebook/messenger/incoming/account_linking'
|
|
10
10
|
require 'facebook/messenger/incoming/referral'
|
11
11
|
require 'facebook/messenger/incoming/payment'
|
12
12
|
require 'facebook/messenger/incoming/policy_enforcement'
|
13
|
+
require 'facebook/messenger/incoming/pass_thread_control'
|
14
|
+
require 'facebook/messenger/incoming/game_play'
|
15
|
+
require 'facebook/messenger/incoming/message_reaction'
|
13
16
|
|
14
17
|
module Facebook
|
15
18
|
module Messenger
|
@@ -31,7 +34,10 @@ module Facebook
|
|
31
34
|
'message_echo' => MessageEcho,
|
32
35
|
'message_request' => MessageRequest,
|
33
36
|
'payment' => Payment,
|
34
|
-
'policy_enforcement' => PolicyEnforcement
|
37
|
+
'policy_enforcement' => PolicyEnforcement,
|
38
|
+
'pass_thread_control' => PassThreadControl,
|
39
|
+
'game_play' => GamePlay,
|
40
|
+
'reaction' => MessageReaction
|
35
41
|
}.freeze
|
36
42
|
|
37
43
|
# Parse the given payload and create new object of class related
|
@@ -18,6 +18,7 @@ module Facebook
|
|
18
18
|
|
19
19
|
#
|
20
20
|
# Function return PSID of sender.
|
21
|
+
#
|
21
22
|
# @see https://developers.facebook.com/docs/messenger-platform/identity
|
22
23
|
# Info about PSID.
|
23
24
|
# @see https://developers.facebook.com/docs/messenger-platform/webhook#format
|
@@ -30,7 +31,7 @@ module Facebook
|
|
30
31
|
end
|
31
32
|
|
32
33
|
#
|
33
|
-
# Function return the page
|
34
|
+
# Function return id of the page from which the message has arrived.
|
34
35
|
#
|
35
36
|
# @return [String] Facebook page id.
|
36
37
|
#
|
@@ -54,7 +55,6 @@ module Facebook
|
|
54
55
|
#
|
55
56
|
# Function return timestamp when message is sent.
|
56
57
|
#
|
57
|
-
#
|
58
58
|
# @return [Object] Message time sent.
|
59
59
|
#
|
60
60
|
def sent_at
|
@@ -74,7 +74,7 @@ module Facebook
|
|
74
74
|
sender_action: 'typing_on'
|
75
75
|
}
|
76
76
|
|
77
|
-
|
77
|
+
Facebook::Messenger::Bot.deliver(payload, page_id: recipient['id'])
|
78
78
|
end
|
79
79
|
|
80
80
|
#
|
@@ -90,7 +90,7 @@ module Facebook
|
|
90
90
|
sender_action: 'typing_off'
|
91
91
|
}
|
92
92
|
|
93
|
-
|
93
|
+
Facebook::Messenger::Bot.deliver(payload, page_id: recipient['id'])
|
94
94
|
end
|
95
95
|
|
96
96
|
#
|
@@ -106,7 +106,7 @@ module Facebook
|
|
106
106
|
sender_action: 'mark_seen'
|
107
107
|
}
|
108
108
|
|
109
|
-
|
109
|
+
Facebook::Messenger::Bot.deliver(payload, page_id: recipient['id'])
|
110
110
|
end
|
111
111
|
|
112
112
|
#
|
@@ -123,28 +123,7 @@ module Facebook
|
|
123
123
|
message_type: Facebook::Messenger::Bot::MessageType::RESPONSE
|
124
124
|
}
|
125
125
|
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
#
|
130
|
-
# Function returns the configured access token.
|
131
|
-
#
|
132
|
-
# @return [String] Access token.
|
133
|
-
#
|
134
|
-
def access_token
|
135
|
-
Facebook::Messenger.config.provider.access_token_for(recipient)
|
136
|
-
end
|
137
|
-
|
138
|
-
def app_secret_proof
|
139
|
-
Facebook::Messenger.config.provider.app_secret_proof_for(recipient)
|
140
|
-
end
|
141
|
-
|
142
|
-
private
|
143
|
-
|
144
|
-
def deliver_payload(payload)
|
145
|
-
Facebook::Messenger::Bot.deliver(payload,
|
146
|
-
access_token: access_token,
|
147
|
-
app_secret_proof: app_secret_proof)
|
126
|
+
Facebook::Messenger::Bot.deliver(payload, page_id: recipient['id'])
|
148
127
|
end
|
149
128
|
end
|
150
129
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Facebook
|
2
|
+
module Messenger
|
3
|
+
module Incoming
|
4
|
+
# The GamePlay class represents an incoming Facebook Messenger
|
5
|
+
# game_play events.
|
6
|
+
# @see https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/messaging_game_plays
|
7
|
+
class GamePlay
|
8
|
+
include Facebook::Messenger::Incoming::Common
|
9
|
+
|
10
|
+
def game_play
|
11
|
+
@messaging['game_play']
|
12
|
+
end
|
13
|
+
|
14
|
+
def payload
|
15
|
+
game_play['payload']
|
16
|
+
end
|
17
|
+
|
18
|
+
def score
|
19
|
+
game_play['score']
|
20
|
+
end
|
21
|
+
|
22
|
+
def game
|
23
|
+
game_play['game_id']
|
24
|
+
end
|
25
|
+
|
26
|
+
def player
|
27
|
+
game_play['player_id']
|
28
|
+
end
|
29
|
+
|
30
|
+
def context
|
31
|
+
{
|
32
|
+
context_id: game_play['context_id'],
|
33
|
+
context_type: game_play['context_type']
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Facebook
|
2
|
+
module Messenger
|
3
|
+
module Incoming
|
4
|
+
# The Message echo class represents an incoming Facebook Messenger message
|
5
|
+
# @see https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/message-reactions
|
6
|
+
class MessageReaction
|
7
|
+
include Facebook::Messenger::Incoming::Common
|
8
|
+
|
9
|
+
def action
|
10
|
+
@messaging['reaction']['action']
|
11
|
+
end
|
12
|
+
|
13
|
+
def emoji
|
14
|
+
@messaging['reaction']['emoji']
|
15
|
+
end
|
16
|
+
|
17
|
+
def reaction
|
18
|
+
@messaging['reaction']['reaction']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Facebook
|
2
|
+
module Messenger
|
3
|
+
module Incoming
|
4
|
+
# The PassThreadControl class represents an incoming Facebook Messenger
|
5
|
+
# pass thread control event.
|
6
|
+
#
|
7
|
+
# @see https://developers.facebook.com/docs/messenger-platform/handover-protocol/pass-thread-control
|
8
|
+
# @see https://developers.facebook.com/docs/messenger-platform/reference/handover-protocol/pass-thread-control
|
9
|
+
class PassThreadControl
|
10
|
+
include Facebook::Messenger::Incoming::Common
|
11
|
+
|
12
|
+
def new_owner_app_id
|
13
|
+
@messaging['pass_thread_control']['new_owner_app_id']
|
14
|
+
end
|
15
|
+
|
16
|
+
def metadata
|
17
|
+
@messaging['pass_thread_control']['metadata']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -28,10 +28,12 @@ module Facebook
|
|
28
28
|
# @return [Boolean] TRUE
|
29
29
|
#
|
30
30
|
def subscribe(access_token:, subscribed_fields: [])
|
31
|
-
response = post '/subscribed_apps',
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
response = post '/subscribed_apps',
|
32
|
+
headers: { 'Content-Type' => 'application/json' },
|
33
|
+
body: {
|
34
|
+
access_token: access_token,
|
35
|
+
subscribed_fields: subscribed_fields
|
36
|
+
}.to_json
|
35
37
|
|
36
38
|
raise_errors(response)
|
37
39
|
|
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:
|
4
|
+
version: 2.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:
|
11
|
+
date: 2020-07-31 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:
|
53
|
+
version: 2.1.4
|
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:
|
60
|
+
version: 2.1.4
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: coveralls
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,28 +106,28 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
109
|
+
version: 13.0.1
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
116
|
+
version: 13.0.1
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: rspec
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: '3.
|
123
|
+
version: '3.9'
|
124
124
|
type: :development
|
125
125
|
prerelease: false
|
126
126
|
version_requirements: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
128
|
- - "~>"
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version: '3.
|
130
|
+
version: '3.9'
|
131
131
|
- !ruby/object:Gem::Dependency
|
132
132
|
name: rubocop
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -148,14 +148,14 @@ dependencies:
|
|
148
148
|
requirements:
|
149
149
|
- - "~>"
|
150
150
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
151
|
+
version: 3.8.1
|
152
152
|
type: :development
|
153
153
|
prerelease: false
|
154
154
|
version_requirements: !ruby/object:Gem::Requirement
|
155
155
|
requirements:
|
156
156
|
- - "~>"
|
157
157
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
158
|
+
version: 3.8.1
|
159
159
|
description: Facebook Messenger client
|
160
160
|
email:
|
161
161
|
- jgorset@gmail.com
|
@@ -183,10 +183,13 @@ 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/game_play.rb
|
186
187
|
- lib/facebook/messenger/incoming/message.rb
|
187
188
|
- lib/facebook/messenger/incoming/message_echo.rb
|
189
|
+
- lib/facebook/messenger/incoming/message_reaction.rb
|
188
190
|
- lib/facebook/messenger/incoming/message_request.rb
|
189
191
|
- lib/facebook/messenger/incoming/optin.rb
|
192
|
+
- lib/facebook/messenger/incoming/pass_thread_control.rb
|
190
193
|
- lib/facebook/messenger/incoming/payment.rb
|
191
194
|
- lib/facebook/messenger/incoming/policy_enforcement.rb
|
192
195
|
- lib/facebook/messenger/incoming/postback.rb
|
@@ -216,8 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
219
|
- !ruby/object:Gem::Version
|
217
220
|
version: '0'
|
218
221
|
requirements: []
|
219
|
-
|
220
|
-
rubygems_version: 2.7.6
|
222
|
+
rubygems_version: 3.0.6
|
221
223
|
signing_key:
|
222
224
|
specification_version: 4
|
223
225
|
summary: Facebook Messenger client
|