facebook-messenger 0.12.0 → 0.13.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddbb553d6b155a4f6cbb160cfb404605df0705d6
|
4
|
+
data.tar.gz: 23899394ed7e89b77701b6f634b595e770b735f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8192c8d31b9bd123d836d37a3f67fe6aa823c5aa442db7e0b5221f6dba01817d8c66d9c0a571b2350f182f106f2797d5651cb44c581caf8631bf8c439c61e8c
|
7
|
+
data.tar.gz: 5c3fdd4ddd9e19fdbde71cdb075b149155d8c3c8b9804163d2b2f0a344f91fbfd1e4dc60d2f1d80568a792ea704a2cb09b7076f49754d32f1dd127ea0d297d2f
|
data/README.md
CHANGED
@@ -125,7 +125,7 @@ end
|
|
125
125
|
Show the human you are preparing a message for them:
|
126
126
|
|
127
127
|
```ruby
|
128
|
-
Bot.on :message do |message|
|
128
|
+
Bot.on :message do |message|
|
129
129
|
message.typing_on
|
130
130
|
|
131
131
|
# Do something expensive
|
@@ -137,7 +137,7 @@ end
|
|
137
137
|
Or that you changed your mind:
|
138
138
|
|
139
139
|
```ruby
|
140
|
-
Bot.on :message do |message|
|
140
|
+
Bot.on :message do |message|
|
141
141
|
message.typing_on
|
142
142
|
|
143
143
|
if # something
|
@@ -204,16 +204,22 @@ Bot.on :referral do |referral|
|
|
204
204
|
end
|
205
205
|
```
|
206
206
|
|
207
|
-
#### Change
|
207
|
+
#### Change messenger profile
|
208
208
|
|
209
|
-
You can greet new humans to entice them into talking to you:
|
209
|
+
You can greet new humans to entice them into talking to you, in different locales:
|
210
210
|
|
211
211
|
```ruby
|
212
|
-
Facebook::Messenger::
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
212
|
+
Facebook::Messenger::Profile.set({
|
213
|
+
greeting: [
|
214
|
+
{
|
215
|
+
locale: 'default',
|
216
|
+
text: 'Welcome to your new bot overlord!'
|
217
|
+
},
|
218
|
+
{
|
219
|
+
locale: 'fr_FR',
|
220
|
+
text: 'Bienvenue dans le bot du Wagon !'
|
221
|
+
}
|
222
|
+
]
|
217
223
|
}, access_token: ENV['ACCESS_TOKEN'])
|
218
224
|
```
|
219
225
|
|
@@ -221,38 +227,54 @@ You can define the action to trigger when new humans click on the Get
|
|
221
227
|
Started button. Before doing it you should check to select the messaging_postbacks field when setting up your webhook.
|
222
228
|
|
223
229
|
```ruby
|
224
|
-
Facebook::Messenger::
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
{
|
229
|
-
payload: 'DEVELOPER_DEFINED_PAYLOAD_FOR_WELCOME'
|
230
|
-
}
|
231
|
-
]
|
230
|
+
Facebook::Messenger::Profile.set({
|
231
|
+
get_started: {
|
232
|
+
payload: 'GET_STARTED_PAYLOAD'
|
233
|
+
}
|
232
234
|
}, access_token: ENV['ACCESS_TOKEN'])
|
233
235
|
```
|
234
236
|
|
235
237
|
You can show a persistent menu to humans.
|
236
238
|
|
237
239
|
```ruby
|
238
|
-
Facebook::Messenger::
|
239
|
-
|
240
|
-
thread_state: 'existing_thread',
|
241
|
-
call_to_actions: [
|
242
|
-
{
|
243
|
-
type: 'postback',
|
244
|
-
title: 'Help',
|
245
|
-
payload: 'DEVELOPER_DEFINED_PAYLOAD_FOR_HELP'
|
246
|
-
},
|
240
|
+
Facebook::Messenger::Profile.set({
|
241
|
+
persistent_menu: [
|
247
242
|
{
|
248
|
-
|
249
|
-
|
250
|
-
|
243
|
+
locale: 'default',
|
244
|
+
composer_input_disabled: true,
|
245
|
+
call_to_actions: [
|
246
|
+
{
|
247
|
+
title: 'My Account',
|
248
|
+
type: 'nested',
|
249
|
+
call_to_actions: [
|
250
|
+
{
|
251
|
+
title: 'What's a chatbot?',
|
252
|
+
type: 'postback',
|
253
|
+
payload: 'EXTERMINATE'
|
254
|
+
},
|
255
|
+
{
|
256
|
+
title: 'History',
|
257
|
+
type: 'postback',
|
258
|
+
payload: 'HISTORY_PAYLOAD'
|
259
|
+
},
|
260
|
+
{
|
261
|
+
title: 'Contact Info',
|
262
|
+
type: 'postback',
|
263
|
+
payload: 'CONTACT_INFO_PAYLOAD'
|
264
|
+
}
|
265
|
+
]
|
266
|
+
},
|
267
|
+
{
|
268
|
+
type: 'web_url',
|
269
|
+
title: 'Get some help',
|
270
|
+
url: 'https://github.com/hyperoslo/facebook-messenger',
|
271
|
+
webview_height_ratio: 'full'
|
272
|
+
}
|
273
|
+
]
|
251
274
|
},
|
252
275
|
{
|
253
|
-
|
254
|
-
|
255
|
-
url: 'http://example.com/'
|
276
|
+
locale: 'zh_CN',
|
277
|
+
composer_input_disabled: false
|
256
278
|
}
|
257
279
|
]
|
258
280
|
}, access_token: ENV['ACCESS_TOKEN'])
|
@@ -262,17 +284,14 @@ Facebook::Messenger::Thread.set({
|
|
262
284
|
|
263
285
|
### Create an Application on Facebook
|
264
286
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
Create a new webhook, enter the domain your bot is connected to and a verify
|
269
|
-
token of your choosing.
|
270
|
-
|
271
|
-

|
287
|
+
Follow the [Quick Start][quick-start] guide to create an Application on
|
288
|
+
Facebook.
|
272
289
|
|
273
290
|
*Note*: Don't subscribe to `message_echoes`; it'll echo your bot's own messages
|
274
291
|
back to you, effectively DDOSing yourself.
|
275
292
|
|
293
|
+
[quick-start]: https://developers.facebook.com/docs/messenger-platform/guides/quick-start
|
294
|
+
|
276
295
|
### Make a configuration provider
|
277
296
|
|
278
297
|
Use the generated access token and your verify token to configure your bot. Most
|
@@ -418,6 +437,14 @@ commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.or
|
|
418
437
|
Bug reports and pull requests are welcome on GitHub at
|
419
438
|
https://github.com/hyperoslo/facebook-messenger.
|
420
439
|
|
440
|
+
## Projects using Facebook Messenger
|
441
|
+
|
442
|
+
* [Rubotnik](https://github.com/progapandist/rubotnik-boilerplate) is a boilerplate
|
443
|
+
for Facebook Messenger, and a great place to start if you're new to bots.
|
444
|
+
|
445
|
+
* [Chatwoot](http://chatwoot.com/) use Facebook Messenger to integrate their customer
|
446
|
+
support bots with, well, Facebook Messenger.
|
447
|
+
|
421
448
|
## Hyper loves you
|
422
449
|
|
423
450
|
[Hyper] made this. We're a bunch of folks who love building things. You should
|
data/lib/facebook/messenger.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'facebook/messenger/version'
|
2
2
|
require 'facebook/messenger/error'
|
3
3
|
require 'facebook/messenger/subscriptions'
|
4
|
-
require 'facebook/messenger/
|
4
|
+
require 'facebook/messenger/profile'
|
5
5
|
require 'facebook/messenger/bot'
|
6
6
|
require 'facebook/messenger/server'
|
7
7
|
require 'facebook/messenger/configuration'
|
@@ -9,8 +9,9 @@ module Facebook
|
|
9
9
|
|
10
10
|
base_uri 'https://graph.facebook.com/v2.6/me'
|
11
11
|
|
12
|
-
EVENTS = [
|
13
|
-
|
12
|
+
EVENTS = %i[
|
13
|
+
message delivery postback optin read account_linking referral
|
14
|
+
].freeze
|
14
15
|
|
15
16
|
class << self
|
16
17
|
# Deliver a message with the given payload.
|
@@ -82,6 +83,7 @@ module Facebook
|
|
82
83
|
# Default HTTParty options.
|
83
84
|
def default_options
|
84
85
|
super.merge(
|
86
|
+
read_timeout: 300,
|
85
87
|
headers: {
|
86
88
|
'Content-Type' => 'application/json'
|
87
89
|
}
|
@@ -5,6 +5,8 @@ module Facebook
|
|
5
5
|
class Message
|
6
6
|
include Facebook::Messenger::Incoming::Common
|
7
7
|
|
8
|
+
ATTACHMENT_TYPES = %w[image audio video file location fallback].freeze
|
9
|
+
|
8
10
|
def id
|
9
11
|
@messaging['message']['mid']
|
10
12
|
end
|
@@ -25,11 +27,47 @@ module Facebook
|
|
25
27
|
@messaging['message']['attachments']
|
26
28
|
end
|
27
29
|
|
30
|
+
def app_id
|
31
|
+
@messaging['message']['app_id']
|
32
|
+
end
|
33
|
+
|
34
|
+
ATTACHMENT_TYPES.each do |attachment_type|
|
35
|
+
define_method "#{attachment_type}_attachment?" do
|
36
|
+
attachment_type?(attachment_type)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def attachment_type
|
41
|
+
return if attachments.nil?
|
42
|
+
|
43
|
+
attachments.first['type']
|
44
|
+
end
|
45
|
+
|
46
|
+
def attachment_url
|
47
|
+
return if attachments.nil?
|
48
|
+
return unless %w[image audio video file].include? attachment_type
|
49
|
+
|
50
|
+
attachments.first['payload']['url']
|
51
|
+
end
|
52
|
+
|
53
|
+
def location_coordinates
|
54
|
+
return [] unless attachment_type?('location')
|
55
|
+
|
56
|
+
coordinates_data = attachments.first['payload']['coordinates']
|
57
|
+
[coordinates_data['lat'], coordinates_data['long']]
|
58
|
+
end
|
59
|
+
|
28
60
|
def quick_reply
|
29
61
|
return unless @messaging['message']['quick_reply']
|
30
62
|
|
31
63
|
@messaging['message']['quick_reply']['payload']
|
32
64
|
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def attachment_type?(attachment_type)
|
69
|
+
!attachments.nil? && attachments.first['type'] == attachment_type
|
70
|
+
end
|
33
71
|
end
|
34
72
|
end
|
35
73
|
end
|
@@ -2,10 +2,10 @@ require 'httparty'
|
|
2
2
|
|
3
3
|
module Facebook
|
4
4
|
module Messenger
|
5
|
-
# This module handles changing
|
5
|
+
# This module handles changing messenger profile (menu, start & greeting).
|
6
6
|
#
|
7
|
-
# https://developers.facebook.com/docs/messenger-platform/
|
8
|
-
module
|
7
|
+
# https://developers.facebook.com/docs/messenger-platform/messenger-profile
|
8
|
+
module Profile
|
9
9
|
include HTTParty
|
10
10
|
|
11
11
|
base_uri 'https://graph.facebook.com/v2.6/me'
|
@@ -15,7 +15,7 @@ module Facebook
|
|
15
15
|
module_function
|
16
16
|
|
17
17
|
def set(settings, access_token:)
|
18
|
-
response = post '/
|
18
|
+
response = post '/messenger_profile', body: settings.to_json, query: {
|
19
19
|
access_token: access_token
|
20
20
|
}
|
21
21
|
|
@@ -25,7 +25,7 @@ module Facebook
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def unset(settings, access_token:)
|
28
|
-
response = delete '/
|
28
|
+
response = delete '/messenger_profile', body: settings.to_json, query: {
|
29
29
|
access_token: access_token
|
30
30
|
}
|
31
31
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facebook-messenger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johannes Gorset
|
@@ -92,14 +92,14 @@ dependencies:
|
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
95
|
+
version: 0.48.1
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
102
|
+
version: 0.48.1
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: webmock
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,9 +184,9 @@ files:
|
|
184
184
|
- lib/facebook/messenger/incoming/postback.rb
|
185
185
|
- lib/facebook/messenger/incoming/read.rb
|
186
186
|
- lib/facebook/messenger/incoming/referral.rb
|
187
|
+
- lib/facebook/messenger/profile.rb
|
187
188
|
- lib/facebook/messenger/server.rb
|
188
189
|
- lib/facebook/messenger/subscriptions.rb
|
189
|
-
- lib/facebook/messenger/thread.rb
|
190
190
|
- lib/facebook/messenger/version.rb
|
191
191
|
homepage: https://github.com/hyperoslo/facebook-messenger
|
192
192
|
licenses:
|