facebook-messenger 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55e300c4f11036d518035144eaf94581e5e99ce5
4
- data.tar.gz: ca59746d98d4fab7f37284468fe57c6cf6414106
3
+ metadata.gz: a97b014f458381225a5cf3b76148fdf1b240348a
4
+ data.tar.gz: 6a3d1c139c2aa42f3891864b1080b8af1f782ecc
5
5
  SHA512:
6
- metadata.gz: 3b3e31067f8f111b86d712d68566b8f6de895ccd016a71d47b8ccc9b6a886cd99a1e84db20ec2860f006903b63cef874656a0cfc383cc0b7d6f728b32df9022c
7
- data.tar.gz: 3dc23071c67f9060f27125646afb8236c5cac30b101311ac880242611b141a80ff31012642ff04e89a93a6d100e8d7498713a565dedb91d39748810ea579564e
6
+ metadata.gz: bb9b1c17ab1057e49489153deb9fa94384abcbe550114101f1b2f16cdd5b8b3fba9b8640b241af14ada44f51f1502b345e1168d5b7e089144f4b7afd50be4ecc
7
+ data.tar.gz: d4b2d577c290b9caf6cb02861f6a1e592bb2e313918e875d5a4055db3751da9eec7651af67fcfe82b7213b7a561e823a5e8affb9c8c81121db3dd4e25bd97a0c
data/README.md CHANGED
@@ -155,6 +155,14 @@ Bot.on :delivery do |delivery|
155
155
  end
156
156
  ```
157
157
 
158
+ #### Set a welcome message
159
+
160
+ You can greet new humans to entice them into talking to you:
161
+
162
+ ```ruby
163
+ Facebook::Messenger::Welcome.set text: 'Hello, human!'
164
+ ```
165
+
158
166
  ## Configuration
159
167
 
160
168
  ### Create an Application on Facebook
@@ -1,6 +1,7 @@
1
1
  require 'facebook/messenger/version'
2
2
  require 'facebook/messenger/error'
3
3
  require 'facebook/messenger/subscriptions'
4
+ require 'facebook/messenger/welcome'
4
5
  require 'facebook/messenger/bot'
5
6
  require 'facebook/messenger/server'
6
7
  require 'facebook/messenger/configuration'
@@ -1,5 +1,5 @@
1
1
  module Facebook
2
2
  module Messenger
3
- VERSION = '0.6.0'.freeze
3
+ VERSION = '0.7.0'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,61 @@
1
+ require 'httparty'
2
+
3
+ module Facebook
4
+ module Messenger
5
+ # This module handles setting welcome messages.
6
+ #
7
+ # https://developers.facebook.com/docs/messenger-platform/send-api-reference#welcome_message_configuration
8
+ module Welcome
9
+ include HTTParty
10
+
11
+ base_uri 'https://graph.facebook.com/v2.6/me'
12
+
13
+ format :json
14
+
15
+ module_function
16
+
17
+ def set(message)
18
+ response = post '/thread_settings',
19
+ body: welcome_setting_for(message).to_json
20
+
21
+ raise_errors(response)
22
+
23
+ true
24
+ end
25
+
26
+ def unset
27
+ response = post '/thread_settings',
28
+ body: welcome_setting_for(nil).to_json
29
+
30
+ raise_errors(response)
31
+
32
+ true
33
+ end
34
+
35
+ def raise_errors(response)
36
+ raise Error, response['error']['message'] if response.key? 'error'
37
+ end
38
+
39
+ def default_options
40
+ super.merge(
41
+ query: {
42
+ access_token: Facebook::Messenger.config.access_token
43
+ },
44
+ headers: {
45
+ 'Content-Type' => 'application/json'
46
+ }
47
+ )
48
+ end
49
+
50
+ def welcome_setting_for(payload)
51
+ {
52
+ setting_type: 'call_to_actions',
53
+ thread_state: 'new_thread',
54
+ call_to_actions: payload ? [{ message: payload }] : []
55
+ }
56
+ end
57
+
58
+ class Error < Facebook::Messenger::Error; end
59
+ end
60
+ end
61
+ 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.6.0
4
+ version: 0.7.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-06-08 00:00:00.000000000 Z
11
+ date: 2016-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -173,6 +173,7 @@ files:
173
173
  - lib/facebook/messenger/server.rb
174
174
  - lib/facebook/messenger/subscriptions.rb
175
175
  - lib/facebook/messenger/version.rb
176
+ - lib/facebook/messenger/welcome.rb
176
177
  homepage: https://github.com/hyperoslo/facebook-messenger
177
178
  licenses:
178
179
  - MIT