Class: Intercom::Service::Conversation

Inherits:
BaseService show all
Includes:
ApiOperations::Find, ApiOperations::FindAll, ApiOperations::List, ApiOperations::Load, ApiOperations::Save, ApiOperations::Search
Defined in:
lib/intercom/service/conversation.rb

Instance Attribute Summary

Attributes inherited from BaseService

#client

Instance Method Summary collapse

Methods included from ApiOperations::Search

#search

Methods included from ApiOperations::Save

#create, #identity_hash, #save

Methods included from ApiOperations::Load

#load

Methods included from ApiOperations::Find

#find

Methods included from ApiOperations::List

#all

Methods included from ApiOperations::FindAll

#find_all

Methods inherited from BaseService

#collection_name, #from_api, #initialize

Constructor Details

This class inherits a constructor from Intercom::Service::BaseService

Instance Method Details

#assign(reply_data) ⇒ Object



58
59
60
61
# File 'lib/intercom/service/conversation.rb', line 58

def assign(reply_data)
  assignee_id = reply_data.fetch(:assignee_id) { raise 'assignee_id is required' }
  reply reply_data.merge(message_type: 'assignment', assignee_id: assignee_id, type: 'admin')
end

#close(reply_data) ⇒ Object



49
50
51
# File 'lib/intercom/service/conversation.rb', line 49

def close(reply_data)
  reply reply_data.merge(message_type: 'close', type: 'admin')
end

#collection_classObject



20
21
22
# File 'lib/intercom/service/conversation.rb', line 20

def collection_class
  Intercom::Conversation
end

#collection_proxy_classObject



24
25
26
# File 'lib/intercom/service/conversation.rb', line 24

def collection_proxy_class
  Intercom::BaseCollectionProxy
end

#mark_read(id) ⇒ Object



28
29
30
# File 'lib/intercom/service/conversation.rb', line 28

def mark_read(id)
  @client.put("/conversations/#{id}", read: true)
end

#open(reply_data) ⇒ Object



45
46
47
# File 'lib/intercom/service/conversation.rb', line 45

def open(reply_data)
  reply reply_data.merge(message_type: 'open', type: 'admin')
end

#reply(reply_data) ⇒ Object



32
33
34
35
36
37
# File 'lib/intercom/service/conversation.rb', line 32

def reply(reply_data)
  id = reply_data.delete(:id)
  collection_name = Utils.resource_class_to_collection_name(collection_class)
  response = @client.post("/#{collection_name}/#{id}/reply", reply_data.merge(conversation_id: id))
  collection_class.new.from_response(response)
end

#reply_to_last(reply_data) ⇒ Object



39
40
41
42
43
# File 'lib/intercom/service/conversation.rb', line 39

def reply_to_last(reply_data)
  collection_name = Utils.resource_class_to_collection_name(collection_class)
  response = @client.post("/#{collection_name}/last/reply", reply_data)
  collection_class.new.from_response(response)
end

#run_assignment_rules(id) ⇒ Object



63
64
65
66
67
# File 'lib/intercom/service/conversation.rb', line 63

def run_assignment_rules(id)
  collection_name = Utils.resource_class_to_collection_name(collection_class)
  response = @client.post("/#{collection_name}/#{id}/run_assignment_rules", {})
  collection_class.new.from_response(response)
end

#snooze(reply_data) ⇒ Object



53
54
55
56
# File 'lib/intercom/service/conversation.rb', line 53

def snooze(reply_data)
  reply_data.fetch(:snoozed_until) { raise 'snoozed_until field is required' }
  reply reply_data.merge(message_type: 'snoozed', type: 'admin')
end