Class: MessageQuickly::Api::ThreadSettings

Inherits:
Base
  • Object
show all
Defined in:
lib/message_quickly/api/thread_settings.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

client, #initialize

Constructor Details

This class inherits a constructor from MessageQuickly::Api::Base

Class Method Details

.create(message) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/message_quickly/api/thread_settings.rb', line 5

def self.create(message)
  # curl -X POST -H "Content-Type: application/json" -d '{
  #   "setting_type":"call_to_actions",
  #   "thread_state":"new_thread",
  #   "call_to_actions":[
  #     {
  #       "message":{
  #         "text":"Welcome to My Company!"
  #       }
  #     }
  #   ]
  # }' "https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_ACCESS_TOKEN>"
  ThreadSettings.new.create(message)
end

.deleteObject



20
21
22
23
24
25
26
27
# File 'lib/message_quickly/api/thread_settings.rb', line 20

def self.delete
  # curl -X POST -H "Content-Type: application/json" -d '{
  #   "setting_type":"call_to_actions",
  #   "thread_state":"new_thread",
  #   "call_to_actions":[]
  # }' "https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_ACCESS_TOKEN>"
  ThreadSettings.new.delete
end

Instance Method Details

#create(message) ⇒ Object



29
30
31
32
33
# File 'lib/message_quickly/api/thread_settings.rb', line 29

def create(message)
  request_string = "#{ENV['FACEBOOK_MESSENGER_PAGE_ID']}/thread_settings"
  json = @client.post(request_string, { setting_type: 'call_to_actions', thread_state: 'new_thread', call_to_actions: [{ message: { text: message } }] })
  json['result'] == "Successfully added new_thread's CTAs"
end

#deleteObject



35
36
37
38
39
# File 'lib/message_quickly/api/thread_settings.rb', line 35

def delete
  request_string = "#{ENV['FACEBOOK_MESSENGER_PAGE_ID']}/thread_settings"
  json = @client.post(request_string, { setting_type: 'call_to_actions', thread_state: 'new_thread', call_to_actions: [] })
  json['result'] == "Successfully removed all new_thread's CTAs"
end