facebook-messenger 2.0.0 → 2.0.1

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
  SHA256:
3
- metadata.gz: b757052cad527d03939514250e2f3fc87fbc21e0e7c86e9f78c8a2087ed925f1
4
- data.tar.gz: 9f18c41169ded5554f49e3faa2e22a94565f83461bc2de688ad87957426791a1
3
+ metadata.gz: 8b91271ca1dfd46644af4c45a6e64670c36cf2c8de5efa288ec2bf04e43bef44
4
+ data.tar.gz: 57611671a09c7784c4cfe92e461a9b9444e6d18e3f1ee02784291f5af2effaa1
5
5
  SHA512:
6
- metadata.gz: 23d252fce2c080a7d95f1b25795ca423e7efac86c52e7dc158203c4f0b840d3b7c14b499919a3d9fab58cdf49e1bed274a7220f25b31c235e0e93fb457e45ff2
7
- data.tar.gz: 1aa9d963cfecb848d000a4df931a1d30430005eff5b5f58cc18f8094092956077b354e589527770007e081b3f8d0cf7a67f1229da21a3b1ce453ff94a7dbca65
6
+ metadata.gz: c91d9b3fc8bf84c8acf14034f2f916477e67418b8baf7df1c6f87fb35f0e4a5f3d207a1386e33a70ed18b8ad1466023e93d50eb248a7c110b05c460f0154450f
7
+ data.tar.gz: aa8656efd52e1cb39980c11a86596739e1045848bb78edd13c6a568febaa1ed60f8b2ede932baa8f3f27917506f64ade3cbe2690be5892be555a7c83aaa61d4a
data/README.md CHANGED
@@ -44,27 +44,15 @@ end
44
44
  ```ruby
45
45
  Bot.deliver({
46
46
  recipient: {
47
- id: '45123'
47
+ id: YOUR_RECIPIENT_ID
48
48
  },
49
49
  message: {
50
50
  text: 'Human?'
51
51
  },
52
52
  messaging_type: Facebook::Messenger::Bot::MessagingType::UPDATE
53
- }, access_token: ENV['ACCESS_TOKEN'], app_secret_proof: app_secret_proof
54
- )
53
+ }, page_id: YOUR_PAGE_ID)
55
54
  ```
56
55
 
57
- NOTE: `app_secret_proof` is an optional parameter to [secure your requests](https://developers.facebook.com/docs/graph-api/securing-requests/),
58
- and you can generate it from your configuration provider like so:
59
-
60
- ```ruby
61
- configuration_provider = Facebook::Messenger::Configuration::Providers::Environment.new
62
- app_secret_proof = configuration_provider.app_secret_proof_for(page_id)
63
- ```
64
-
65
- For the methods you'll usually use (like `reply` and `typing_on`), the app secret proof will be set and sent
66
- automatically if you set the environment variable `APP_SECRET_PROOF_ENABLED` to `true`.
67
-
68
56
  ##### Messages with images
69
57
 
70
58
  The human may require visual aid to understand:
@@ -305,7 +293,7 @@ Facebook::Messenger::Profile.set({
305
293
  text: 'Bienvenue dans le bot du Wagon !'
306
294
  }
307
295
  ]
308
- }, access_token: ENV['ACCESS_TOKEN'])
296
+ }, page_id: YOUR_PAGE_ID)
309
297
  ```
310
298
 
311
299
  You can define the action to trigger when new humans click on the Get
@@ -316,7 +304,7 @@ Facebook::Messenger::Profile.set({
316
304
  get_started: {
317
305
  payload: 'GET_STARTED_PAYLOAD'
318
306
  }
319
- }, access_token: ENV['ACCESS_TOKEN'])
307
+ }, page_id: YOUR_PAGE_ID)
320
308
  ```
321
309
 
322
310
  You can show a persistent menu to humans.
@@ -362,10 +350,9 @@ Facebook::Messenger::Profile.set({
362
350
  composer_input_disabled: false
363
351
  }
364
352
  ]
365
- }, access_token: ENV['ACCESS_TOKEN'])
353
+ }, page_id: YOUR_PAGE_ID)
366
354
  ```
367
355
 
368
-
369
356
  #### Handle a Facebook Policy Violation
370
357
 
371
358
  See Facebook's documentation on [Messaging Policy Enforcement](https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/messaging_policy_enforcement)
@@ -376,8 +363,11 @@ Bot.on :'policy_enforcement' do |referral|
376
363
  referral.reason # => "The bot violated our Platform Policies (https://developers.facebook.com/policy/#messengerplatform). Common violations include sending out excessive spammy messages or being non-functional."
377
364
  end
378
365
  ```
366
+
379
367
  #### messaging_type
368
+
380
369
  ##### Sending Messages
370
+
381
371
  See Facebook's documentation on [Sending Messages](https://developers.facebook.com/docs/messenger-platform/send-messages#standard_messaging)
382
372
 
383
373
  As of May 7th 2018 all messages are required to include a messaging_type
@@ -391,10 +381,11 @@ Bot.deliver({
391
381
  text: 'Human?'
392
382
  },
393
383
  messaging_type: Facebook::Messenger::Bot::MessagingType::UPDATE
394
- }, access_token: ENV['ACCESS_TOKEN'])
384
+ }, page_id: YOUR_PAGE_ID)
395
385
  ```
396
386
 
397
387
  ##### MESSAGE_TAG
388
+
398
389
  See Facebook's documentation on [Message Tags](https://developers.facebook.com/docs/messenger-platform/send-messages/message-tags)
399
390
 
400
391
  When sending a message with messaging_type: MESSAGE_TAG (Facebook::Messenger::Bot::MessagingType::MESSAGE_TAG) you must ensure you add a tag: parameter
@@ -409,7 +400,7 @@ Bot.deliver({
409
400
  },
410
401
  messaging_type: Facebook::Messenger::Bot::MessagingType::MESSAGE_TAG
411
402
  tag: Facebook::Messenger::Bot::Tag::NON_PROMOTIONAL_SUBSCRIPTION
412
- }, access_token: ENV['ACCESS_TOKEN'])
403
+ }, page_id: YOUR_PAGE_ID)
413
404
  ```
414
405
 
415
406
  ## Configuration
@@ -582,6 +573,7 @@ config.autoload_paths += Dir[Rails.root.join('app', 'bot', '*')]
582
573
  ### Test it...
583
574
 
584
575
  ##### ...locally
576
+
585
577
  To test your locally running bot, you can use [ngrok]. This will create a secure
586
578
  tunnel to localhost so that Facebook can reach the webhook.
587
579
 
@@ -589,7 +581,8 @@ tunnel to localhost so that Facebook can reach the webhook.
589
581
 
590
582
  In order to test that behaviour when a new event from Facebook is registered, you can use the gem's `trigger` method. This method accepts as its first argument the type of event that it will receive, and can then be followed by other arguments that mock objects received from Messenger. Using Ruby's [Struct](https://ruby-doc.org/core-2.5.0/Struct.html) class can be very useful for creating these mock objects.
591
583
 
592
- In this case, subscribing to Messenger events has been extracted into a `Listener` class.
584
+ In this case, subscribing to Messenger events has been extracted into a `Listener` class.
585
+
593
586
  ```ruby
594
587
  # app/bot/listener.rb
595
588
  require 'facebook/messenger'
@@ -598,7 +591,7 @@ include Facebook::Messenger
598
591
 
599
592
  class Listener
600
593
  Facebook::Messenger::Subscriptions.subscribe(
601
- access_token: ENV["FB_ACCESS_TOKEN"],
594
+ access_token: ENV['ACCESS_TOKEN'],
602
595
  subscribed_fields: %w[feed mention name]
603
596
  )
604
597
 
@@ -608,11 +601,13 @@ class Listener
608
601
  message: {
609
602
  text: 'Uploading your message to skynet.'
610
603
  }
611
- }, access_token: ENV['FB_ACCESS_TOKEN'])
604
+ }, access_token: ENV['ACCESS_TOKEN'])
612
605
  end
613
606
  end
614
607
  ```
608
+
615
609
  Its respective test file then ensures that the `Bot` object receives a call to `deliver`. This is just a basic test, but check out the [RSpec docs](http://rspec.info/) for more information on testing with RSpec.
610
+
616
611
  ```ruby
617
612
  require 'rails_helper'
618
613
 
@@ -638,7 +633,6 @@ RSpec.describe Listener do
638
633
  end
639
634
  ```
640
635
 
641
-
642
636
  ## Development
643
637
 
644
638
  After checking out the repo, run `bin/setup` to install dependencies. You can also run
@@ -40,14 +40,14 @@ module Facebook
40
40
  # @raise [Facebook::Messenger::Bot::SendError] if there is any error
41
41
  # in response while sending message.
42
42
  #
43
- # @param [Hash] message A Hash describing the recipient and the message.
44
- # @param [String] page_id A String describing the Facebook Page ID to send the message from.
43
+ # @param [Hash] message The message payload
44
+ # @param [String] page_id The page to send the message from
45
45
  #
46
46
  # Returns a String describing the message ID if the message was sent,
47
47
  # or raises an exception if it was not.
48
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)
49
+ access_token = config.provider.access_token_for(page_id)
50
+ app_secret_proof = config.provider.app_secret_proof_for(page_id)
51
51
 
52
52
  query = { access_token: access_token }
53
53
  query[:appsecret_proof] = app_secret_proof if app_secret_proof
@@ -138,6 +138,12 @@ module Facebook
138
138
  }
139
139
  )
140
140
  end
141
+
142
+ private
143
+
144
+ def config
145
+ Facebook::Messenger.config
146
+ end
141
147
  end
142
148
  end
143
149
  end
@@ -12,8 +12,6 @@ module Facebook
12
12
  # A default caching implentation of generating the app_secret_proof
13
13
  # for a given page_id
14
14
  def app_secret_proof_for(page_id = nil)
15
- return unless fetch_app_secret_proof_enabled?
16
-
17
15
  memo_key = [app_secret_for(page_id), access_token_for(page_id)]
18
16
  memoized_app_secret_proofs[memo_key] ||=
19
17
  calculate_app_secret_proof(*memo_key)
@@ -43,10 +41,6 @@ module Facebook
43
41
  def memoized_app_secret_proofs
44
42
  @memoized_app_secret_proofs ||= {}
45
43
  end
46
-
47
- def fetch_app_secret_proof_enabled?
48
- false
49
- end
50
44
  end
51
45
  end
52
46
  end
@@ -22,10 +22,6 @@ module Facebook
22
22
  def access_token_for(*)
23
23
  ENV['ACCESS_TOKEN']
24
24
  end
25
-
26
- def fetch_app_secret_proof_enabled?
27
- ENV['APP_SECRET_PROOF_ENABLED'] == 'true'.freeze
28
- end
29
25
  end
30
26
  end
31
27
  end
@@ -2,6 +2,6 @@ module Facebook
2
2
  module Messenger
3
3
  #
4
4
  # @return [String] Define the version of gem.
5
- VERSION = '2.0.0'.freeze
5
+ VERSION = '2.0.1'.freeze
6
6
  end
7
7
  end
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: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Gorset