facebook-messenger 0.2.0 → 0.3.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 +25 -1
- data/lib/facebook/messenger/bot.rb +2 -1
- data/lib/facebook/messenger/incoming.rb +3 -1
- data/lib/facebook/messenger/incoming/optin.rb +31 -0
- data/lib/facebook/messenger/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a67d299ebe188c1b50d8adcae153084eb694c4c
|
4
|
+
data.tar.gz: 2b882acad66c7260c99670b8b11dcd6771c18b1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fa27eacf08884194a942969822356c84e1de6c74d88b02451a858c5227351305a77e33d4c7eeba4dae146891b8d3c9d429924009bacb2055433db4c3947c071
|
7
|
+
data.tar.gz: 9f7975f548098478e922daf12433e19c28483edde278f0b7b6ee885ca2748c4d4107c06c4e25693f640210f35f1dc407fe9e3a5f461292fdade85fc4a9249933
|
data/README.md
CHANGED
@@ -111,6 +111,29 @@ end
|
|
111
111
|
|
112
112
|
*See Facebook's [documentation][message-documentation] for all message options.*
|
113
113
|
|
114
|
+
#### Send to Facebook
|
115
|
+
|
116
|
+
When the human clicks the [Send to Messenger button][send-to-messenger-plugin]
|
117
|
+
embedded on a website, you will receive an `optin` event.
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
Bot.on :optin do |optin|
|
121
|
+
postback.sender # => { id: '1008372609250235' }
|
122
|
+
postback.recipient # => { id: '2015573629214912' }
|
123
|
+
postback.sent_at # => 2016-04-22 21:30:36 +0200
|
124
|
+
postback.ref # => 'CONTACT_SKYNET'
|
125
|
+
|
126
|
+
Bot.deliver(
|
127
|
+
recipient: {
|
128
|
+
id: '45123'
|
129
|
+
},
|
130
|
+
message: {
|
131
|
+
text: 'Ah, human!'
|
132
|
+
}
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
|
114
137
|
#### Message delivery receipts
|
115
138
|
|
116
139
|
You can stalk the human:
|
@@ -123,7 +146,7 @@ Bot.on :delivery do |delivery|
|
|
123
146
|
delivery.at # => 2016-04-22 21:30:36 +0200
|
124
147
|
delivery.seq # => 37
|
125
148
|
|
126
|
-
puts "Human
|
149
|
+
puts "Human was online at #{delivery.at}"
|
127
150
|
end
|
128
151
|
```
|
129
152
|
|
@@ -204,3 +227,4 @@ If you're using Facebook Messenger, we probably want to [hire you].
|
|
204
227
|
[message-documentation]: https://developers.facebook.com/docs/messenger-platform/send-api-reference#request
|
205
228
|
[facebook-developers]: https://developers.facebook.com
|
206
229
|
[rack]: https://github.com/rack/rack
|
230
|
+
[send-to-messenger-plugin]: https://developers.facebook.com/docs/messenger-platform/plugin-reference
|
@@ -6,7 +6,7 @@ module Facebook
|
|
6
6
|
|
7
7
|
base_uri 'https://graph.facebook.com/v2.6/me'
|
8
8
|
|
9
|
-
EVENTS = [:message, :delivery].freeze
|
9
|
+
EVENTS = [:message, :delivery, :postback, :optin].freeze
|
10
10
|
|
11
11
|
class << self
|
12
12
|
# Deliver a message with the given payload.
|
@@ -51,6 +51,7 @@ module Facebook
|
|
51
51
|
when Incoming::Message then trigger(:message, klass)
|
52
52
|
when Incoming::Delivery then trigger(:delivery, klass)
|
53
53
|
when Incoming::Postback then trigger(:postback, klass)
|
54
|
+
when Incoming::Optin then trigger(:optin, klass)
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'facebook/messenger/incoming/message'
|
2
2
|
require 'facebook/messenger/incoming/delivery'
|
3
3
|
require 'facebook/messenger/incoming/postback'
|
4
|
+
require 'facebook/messenger/incoming/optin'
|
4
5
|
|
5
6
|
module Facebook
|
6
7
|
module Messenger
|
@@ -16,7 +17,8 @@ module Facebook
|
|
16
17
|
{
|
17
18
|
'message' => Message,
|
18
19
|
'delivery' => Delivery,
|
19
|
-
'postback' => Postback
|
20
|
+
'postback' => Postback,
|
21
|
+
'optin' => Optin
|
20
22
|
}.each do |key, klass|
|
21
23
|
return klass.new(payload) if payload.key? key
|
22
24
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Facebook
|
2
|
+
module Messenger
|
3
|
+
module Incoming
|
4
|
+
# The Optin class represents an incoming Facebook Messenger optin,
|
5
|
+
# which occurs when a user engages by using the Send-to-Messenger Plugin.
|
6
|
+
#
|
7
|
+
# https://developers.facebook.com/docs/messenger-platform/plugin-reference
|
8
|
+
class Optin
|
9
|
+
def initialize(payload)
|
10
|
+
@payload = payload
|
11
|
+
end
|
12
|
+
|
13
|
+
def sender
|
14
|
+
@payload['sender']
|
15
|
+
end
|
16
|
+
|
17
|
+
def recipient
|
18
|
+
@payload['recipient']
|
19
|
+
end
|
20
|
+
|
21
|
+
def sent_at
|
22
|
+
Time.at(@payload['timestamp'] / 1000)
|
23
|
+
end
|
24
|
+
|
25
|
+
def ref
|
26
|
+
@payload['optin']['ref']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
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.
|
4
|
+
version: 0.3.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-04-
|
11
|
+
date: 2016-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/facebook/messenger/incoming.rb
|
154
154
|
- lib/facebook/messenger/incoming/delivery.rb
|
155
155
|
- lib/facebook/messenger/incoming/message.rb
|
156
|
+
- lib/facebook/messenger/incoming/optin.rb
|
156
157
|
- lib/facebook/messenger/incoming/postback.rb
|
157
158
|
- lib/facebook/messenger/server.rb
|
158
159
|
- lib/facebook/messenger/subscriptions.rb
|