stealth-facebook 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +367 -0
- data/VERSION +1 -1
- data/lib/stealth/services/facebook/client.rb +1 -1
- data/lib/stealth/services/facebook/reply_handler.rb +6 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4afb61139e924f882b91bab086c46185a1271263a98b6a80e926f70e42ae6fa9
|
4
|
+
data.tar.gz: 0d7620024cbca82662fa974b8084099addd45cf98e1d6b5e16bad03d32ad36cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94b17189ecda693601b2cd242d795fcdfe7e3e3fd5084f7e62182328453cfadf9b9e4d7e35d096d0cb49b250714a3a33efd200a6de410cb1d6136e9de24a8a5d
|
7
|
+
data.tar.gz: 92c32d8c406546acb10199a0a77debaaf8085c6e2714156b0ee5e27d9f04a27812cd1eaab056c48eb2c4b00ea71dc96bd1af891fe8886363eb7fa2c76042a6f2
|
data/README.md
CHANGED
@@ -1 +1,368 @@
|
|
1
1
|
# Stealth Facebook
|
2
|
+
|
3
|
+
This integration adds support for Facebook bots within Stealth.
|
4
|
+
|
5
|
+
## Configure Your Facebook Page
|
6
|
+
|
7
|
+
Add instructions
|
8
|
+
|
9
|
+
## Configure The Integration
|
10
|
+
|
11
|
+
```yaml
|
12
|
+
default: &default
|
13
|
+
facebook:
|
14
|
+
verify_token: <%= ENV['FACEBOOK_VERIFY_TOKEN'] %>
|
15
|
+
page_access_token: <%= ENV['FACEBOOK_ACCESS_TOKEN'] %>
|
16
|
+
setup:
|
17
|
+
greeting: # Greetings are broken up by locale
|
18
|
+
- locale: default
|
19
|
+
text: "Welcome to my Facebook Bot."
|
20
|
+
get_started:
|
21
|
+
payload: new_user
|
22
|
+
persistent_menu:
|
23
|
+
- locale: default
|
24
|
+
composer_input_disabled: false
|
25
|
+
call_to_actions:
|
26
|
+
- type: payload
|
27
|
+
text: Some Button
|
28
|
+
payload: some_button
|
29
|
+
|
30
|
+
production:
|
31
|
+
<<: *default
|
32
|
+
|
33
|
+
development:
|
34
|
+
facebook:
|
35
|
+
verify_token: <%= ENV['FACEBOOK_VERIFY_TOKEN'] %>
|
36
|
+
page_access_token: <%= ENV['FACEBOOK_ACCESS_TOKEN'] %>
|
37
|
+
setup:
|
38
|
+
greeting: # Greetings are broken up by locale
|
39
|
+
- locale: default
|
40
|
+
text: "Welcome to my Facebook Bot."
|
41
|
+
get_started:
|
42
|
+
payload: new_user
|
43
|
+
persistent_menu:
|
44
|
+
- locale: default
|
45
|
+
composer_input_disabled: false
|
46
|
+
call_to_actions:
|
47
|
+
- type: payload
|
48
|
+
text: Some Button
|
49
|
+
payload: some_button
|
50
|
+
- type: nested
|
51
|
+
text: Developer
|
52
|
+
buttons:
|
53
|
+
- type: payload
|
54
|
+
text: Restart
|
55
|
+
payload: developer_restart
|
56
|
+
|
57
|
+
test:
|
58
|
+
<<: *default
|
59
|
+
```
|
60
|
+
|
61
|
+
As with all Stealth integrations, integrations can be specified by environment. You'll want to replace `FACEBOOK_VERIFY_TOKEN` and `FACEBOOK_ACCESS_TOKEN` with your respective keys from your Facebook page.
|
62
|
+
|
63
|
+
These are the supported setup options:
|
64
|
+
|
65
|
+
### greeting
|
66
|
+
This is the message a user will see via Messenger before they have ever sent your bot a message.
|
67
|
+
|
68
|
+
### get_started
|
69
|
+
When the user presses the `Get Started` button in Messenger, the `payload` specified here is the payload that will be sent to your bot.
|
70
|
+
|
71
|
+
### persistent_menu
|
72
|
+
These are the items that appear in the Facebook Messenger drawer. You can specify menu items for each locale individually or use `default` to make the menu apply to all locales.
|
73
|
+
|
74
|
+
The `composer_input_disabled` disables the keyboard input. This is helpful if you anticipate all user replies will come from suggested replies. It defaults to `false` which means the keyboard input is enabled.
|
75
|
+
|
76
|
+
The `call_to_actions` list defines the buttons. In the above example, the production environment has a single button defined with the label `Some Button`. It's type is set to `payload`. The `payload` value specifies the payload that will be sent to the bot when the button is pressed.
|
77
|
+
|
78
|
+
In the `development` environment, there is a `Developer` sub-menu that contains a single button labeled `Restart`. This just showcases the ability to have sub-menus within the drawer. It's a common practice to introduce a `developer_restart` payload button in development so you can easily restart the bot.
|
79
|
+
|
80
|
+
In addition to the `payload` type, the persistent menu supports `url` and `call` type buttons.
|
81
|
+
|
82
|
+
### Uploading the Persistent Menu
|
83
|
+
|
84
|
+
Each time you make a change to the persistent menu, you will have to upload the change to Facebook. This integration provides a command line task to automate this:
|
85
|
+
|
86
|
+
```
|
87
|
+
stealth setup facebook
|
88
|
+
```
|
89
|
+
|
90
|
+
## Replies
|
91
|
+
|
92
|
+
Here are the supported replies for the Facebook integration:
|
93
|
+
|
94
|
+
### text
|
95
|
+
|
96
|
+
These are standard text replies. It can sent like:
|
97
|
+
|
98
|
+
```yaml
|
99
|
+
- reply_type: text
|
100
|
+
text: Hello World!
|
101
|
+
```
|
102
|
+
|
103
|
+
Text replies can also include suggestions, which will be rendered as quick replies:
|
104
|
+
|
105
|
+
```yaml
|
106
|
+
- reply_type: text
|
107
|
+
text: What is your favorite color?
|
108
|
+
suggestions:
|
109
|
+
- text: Blue
|
110
|
+
- text: Red
|
111
|
+
```
|
112
|
+
|
113
|
+
Although not as common, text replies can also include buttons:
|
114
|
+
|
115
|
+
```yaml
|
116
|
+
- reply_type: text
|
117
|
+
text: Would you like to give us a call?
|
118
|
+
buttons:
|
119
|
+
- type: call
|
120
|
+
phone_number: "+15552991212"
|
121
|
+
text: 'Yes'
|
122
|
+
- type: payload
|
123
|
+
text: 'No'
|
124
|
+
payload: 'No'
|
125
|
+
```
|
126
|
+
|
127
|
+
### suggestions
|
128
|
+
|
129
|
+
Though suggestions are not a reply type on their own, they are frequently used to optimize the accuracy and speed of your bot. In the `text` reply type above, we used simple labels for our suggestions. Facebook supports a few special types of quick replies, however.
|
130
|
+
|
131
|
+
#### Location
|
132
|
+
|
133
|
+
You can ask a user for their location:
|
134
|
+
|
135
|
+
```yaml
|
136
|
+
- reply_type: text
|
137
|
+
text: "Where are you located?"
|
138
|
+
suggestions:
|
139
|
+
- type: location
|
140
|
+
```
|
141
|
+
|
142
|
+
If the user chooses to share their location, the `lat` and `lng` will be available via `current_message.location`:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
current_message.location[:lat]
|
146
|
+
current_message.location[:lng]
|
147
|
+
```
|
148
|
+
|
149
|
+
#### Email
|
150
|
+
|
151
|
+
As of Facebook Messenger Platform 2.3, Facebook now supports a standard way to ask for a user's email:
|
152
|
+
|
153
|
+
```yaml
|
154
|
+
- reply_type: text
|
155
|
+
text: "What is your email address?"
|
156
|
+
suggestions:
|
157
|
+
- type: email
|
158
|
+
```
|
159
|
+
|
160
|
+
The email address the user sends back will be available as the string in `current_message.payload`
|
161
|
+
|
162
|
+
#### Phone
|
163
|
+
|
164
|
+
As of Facebook Messenger Platform 2.3, Facebook now supports a standard way to ask for a user's phone number:
|
165
|
+
|
166
|
+
```yaml
|
167
|
+
- reply_type: text
|
168
|
+
text: "What is your phone number?"
|
169
|
+
suggestions:
|
170
|
+
- type: phone
|
171
|
+
```
|
172
|
+
|
173
|
+
The phone number the user sends back will be available as the string in `current_message.payload`
|
174
|
+
|
175
|
+
#### Images
|
176
|
+
|
177
|
+
While images are not a special quick reply type, you can include and `image_url` for a quick reply as way of adding an icon to a quick reply button:
|
178
|
+
|
179
|
+
```yaml
|
180
|
+
- reply_type: text
|
181
|
+
text: "What is your favorite color?"
|
182
|
+
suggestions:
|
183
|
+
- text: Red
|
184
|
+
image_url: "http://example.com/img/red.png"
|
185
|
+
- text: Blue
|
186
|
+
image_url: "http://example.com/img/blue.png"
|
187
|
+
```
|
188
|
+
|
189
|
+
More info [here](https://developers.facebook.com/docs/messenger-platform/send-messages/quick-replies).
|
190
|
+
|
191
|
+
### buttons
|
192
|
+
|
193
|
+
As with `suggestions`, `buttons` are not a reply type of their own but are used to make your bot more efficient. Facebook supports a few button types and these are the ones currently supported by this integration:
|
194
|
+
|
195
|
+
#### payload
|
196
|
+
|
197
|
+
This is the most common button type. When a user presses a button that is `payload` type, that payload string will be sent to your bot. For example:
|
198
|
+
|
199
|
+
```yaml
|
200
|
+
- reply_type: text
|
201
|
+
text: Please press the button below
|
202
|
+
buttons:
|
203
|
+
- type: payload
|
204
|
+
text: 'Press me!'
|
205
|
+
payload: 'button pressed'
|
206
|
+
|
207
|
+
```
|
208
|
+
|
209
|
+
When a user presses the button labeled "Press me!", the payload `button pressed` will be accessible in bot via `current_message.payload`.
|
210
|
+
|
211
|
+
#### url
|
212
|
+
|
213
|
+
The `url` button is useful when sharing a link to a website. By default, it will open up within Facebook Messenger.
|
214
|
+
|
215
|
+
```yaml
|
216
|
+
- reply_type: text
|
217
|
+
text: Find out more via our website
|
218
|
+
buttons:
|
219
|
+
- type: url
|
220
|
+
text: 'Visit website'
|
221
|
+
url: 'https://example.org'
|
222
|
+
|
223
|
+
```
|
224
|
+
|
225
|
+
You can also specify the height of the webview window that opens up in Messenger via: `webview_height`. You can choose between `compact`, `tall`, and `full`.
|
226
|
+
|
227
|
+
More info [here](https://developers.facebook.com/docs/messenger-platform/webview).
|
228
|
+
|
229
|
+
#### call
|
230
|
+
|
231
|
+
The `call` button type will prompt the user to dial the specified number. The number will be pre-filled in, but the user will still have to confirm by confirming via the modal that is shown. To create a `call` button:
|
232
|
+
|
233
|
+
```yaml
|
234
|
+
- reply_type: text
|
235
|
+
text: Give us a ring!
|
236
|
+
buttons:
|
237
|
+
- type: call
|
238
|
+
text: 'Call'
|
239
|
+
phone_number: "+15552991212"
|
240
|
+
|
241
|
+
```
|
242
|
+
|
243
|
+
### Delay
|
244
|
+
|
245
|
+
Delays are a very important part of bot design. They introduce a pause between text replies to give the user a chance to read each reply. With this integration, in addition to introducing a delay, we will also send a typing indicator to the user to indicate another reply is forthcoming. To insert a delay in your bot:
|
246
|
+
|
247
|
+
```yaml
|
248
|
+
- reply_type: delay
|
249
|
+
duration: 2
|
250
|
+
```
|
251
|
+
|
252
|
+
This will add a `2` second delay (with typing indicator). The `duration` can be specified as any floating point value, in seconds.
|
253
|
+
|
254
|
+
### Cards
|
255
|
+
|
256
|
+
Facebook distinguishes between a single card and a carousel of cards. This integration does not, however. You can send a single card the same way you would send 10 cards (the current maximum).
|
257
|
+
|
258
|
+
```yaml
|
259
|
+
- reply_type: cards
|
260
|
+
sharable: true
|
261
|
+
aspect_ratio: horizontal
|
262
|
+
elements:
|
263
|
+
- title: My App
|
264
|
+
subtitle: Download our app below or visit our website for more info.
|
265
|
+
image_url: "https://my-app.com/app-image.png"
|
266
|
+
buttons:
|
267
|
+
- type: url
|
268
|
+
url: "https://my-app.com"
|
269
|
+
text: 'View'
|
270
|
+
webview_height: 'tall'
|
271
|
+
- type: url
|
272
|
+
url: "https://itunes.apple.com/us/app/my-app"
|
273
|
+
text: 'Download iOS App'
|
274
|
+
```
|
275
|
+
|
276
|
+
The above is a single card with two buttons. If you want to include more cards, though, you would just need to specify another listing under the `elements` heading.
|
277
|
+
|
278
|
+
The `sharable` and `aspect_ratio` attributes are optional. When `sharable` is set to `true`, a native share button is shown in Messenger for the message. The `aspect_ratio` attribute specifies the aspect ratio of the main card image (specified by `image_url`). It can be set to `horizontal` or `square` with the default being `horizontal`.
|
279
|
+
|
280
|
+
More info about Facebook cards [here](https://developers.facebook.com/docs/messenger-platform/send-messages/template/generic).
|
281
|
+
|
282
|
+
### List
|
283
|
+
|
284
|
+
A Facebook list is useful for displaying things like a news feed. You can find more info about Facebook lists [here](https://developers.facebook.com/docs/messenger-platform/send-messages/template/list).
|
285
|
+
|
286
|
+
To generate a list via Stealth Facebook:
|
287
|
+
|
288
|
+
```yaml
|
289
|
+
- reply_type: list
|
290
|
+
top_element_style: large
|
291
|
+
buttons:
|
292
|
+
- type: payload
|
293
|
+
title: View More
|
294
|
+
payload: view_more
|
295
|
+
elements:
|
296
|
+
- title: Your Daily News Update
|
297
|
+
subtitle: The following stories have been curated just for you.
|
298
|
+
image_url: "https://news-articles.com/logo.png"
|
299
|
+
buttons:
|
300
|
+
- type: url
|
301
|
+
url: "https://news-articles.com/199"
|
302
|
+
text: 'View'
|
303
|
+
webview_height: 'tall'
|
304
|
+
- title: Breakthrough in AI
|
305
|
+
subtitle: Major breakthrough in the AI space.
|
306
|
+
image_url: "https://news-articles.com/ai.png"
|
307
|
+
default_action:
|
308
|
+
- url: "https://news-articles.com/232"
|
309
|
+
webview_height: 'tall'
|
310
|
+
```
|
311
|
+
|
312
|
+
The list itself supports having a single button that will be rendered on the bottom of the list. Each individual list item supports having one button as well. List items should have between 2-4 elements.
|
313
|
+
|
314
|
+
In addition to the button, a list item can specify a default action. The default action is what will fired when a user taps the list item. A default action can be specified by setting the `default_action` attribute. The `default_action` should be configured as you would a `url` type button.
|
315
|
+
|
316
|
+
The image of the first item in the list is displayed as a cover photo by default. To disable the cover image, set `top_element_style` to `compact`.
|
317
|
+
|
318
|
+
### Images
|
319
|
+
|
320
|
+
To send an image:
|
321
|
+
|
322
|
+
```yaml
|
323
|
+
- reply_type: image
|
324
|
+
image_url: 'https://example.org/image.png'
|
325
|
+
```
|
326
|
+
|
327
|
+
The `image_url` should be set to URL where the image has been uploaded.
|
328
|
+
|
329
|
+
Image replies support buttons and suggestions like text replies.
|
330
|
+
|
331
|
+
### Files
|
332
|
+
|
333
|
+
To send a file:
|
334
|
+
|
335
|
+
```yaml
|
336
|
+
- reply_type: file
|
337
|
+
file_url: 'https://example.org/some.pdf'
|
338
|
+
```
|
339
|
+
|
340
|
+
The `file_url` should be set to URL where the file has been uploaded.
|
341
|
+
|
342
|
+
File replies support buttons and suggestions like text replies.
|
343
|
+
|
344
|
+
### Video
|
345
|
+
|
346
|
+
To send a video:
|
347
|
+
|
348
|
+
```yaml
|
349
|
+
- reply_type: video
|
350
|
+
video_url: 'https://example.org/cool_video.mp4'
|
351
|
+
```
|
352
|
+
|
353
|
+
The `video_url` should be set to URL where the video has been uploaded.
|
354
|
+
|
355
|
+
Video replies support buttons and suggestions like text replies.
|
356
|
+
|
357
|
+
### Audio
|
358
|
+
|
359
|
+
To send an audio clip:
|
360
|
+
|
361
|
+
```yaml
|
362
|
+
- reply_type: audio
|
363
|
+
audio_url: 'https://example.org/podcast.mp3'
|
364
|
+
```
|
365
|
+
|
366
|
+
The `audio_url` should be set to URL where the video has been uploaded.
|
367
|
+
|
368
|
+
Audio replies support buttons and suggestions like text replies.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.10.0
|
@@ -356,11 +356,13 @@ module Stealth
|
|
356
356
|
|
357
357
|
def generate_suggestions(suggestions:)
|
358
358
|
quick_replies = suggestions.collect do |suggestion|
|
359
|
-
|
360
|
-
|
359
|
+
case suggestion["type"]
|
360
|
+
when 'location'
|
361
361
|
quick_reply = { "content_type" => "location" }
|
362
|
-
|
363
|
-
|
362
|
+
when 'phone'
|
363
|
+
quick_reply = { "content_type" => "user_phone_number" }
|
364
|
+
when 'email'
|
365
|
+
quick_reply = { "content_type" => "user_email" }
|
364
366
|
else
|
365
367
|
quick_reply = {
|
366
368
|
"content_type" => "text",
|
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.
|
4
|
+
version: 0.10.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:
|
11
|
+
date: 2018-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stealth
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.7.3
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Stealth Facebook Messenger driver
|