11# -*- coding: utf-8 -*-
22
33from intercom import conversation
4+ from intercom import utils
45from intercom .api_operations .find import Find
56from intercom .api_operations .find_all import FindAll
67from intercom .api_operations .save import Save
@@ -14,30 +15,33 @@ class Conversation(BaseService, Find, FindAll, Save, Load):
1415 def collection_class (self ):
1516 return conversation .Conversation
1617
18+ def reply (self , ** reply_data ):
19+ return self .__reply (reply_data )
1720
18- # def mark_read(id)
19- # @client.put("/conversations/#{id}", read: true)
20- # end
21+ def assign (self , ** reply_data ):
22+ reply_data ['type' ] = 'admin'
23+ reply_data ['message_type' ] = 'assignment'
24+ return self .__reply (reply_data )
2125
22- # def reply(reply_data)
23- # id = reply_data.delete(:id)
24- # collection_name = Utils.resource_class_to_collection_name(collection_class) # noqa
25- # response = @client.post("/#{collection_name}/#{id}/reply", reply_data.merge(:conversation_id => id)) # noqa
26- # collection_class.new.from_response(response)
27- # end
26+ def open (self , ** reply_data ):
27+ reply_data ['type' ] = 'admin'
28+ reply_data ['message_type' ] = 'open'
29+ return self .__reply (reply_data )
2830
29- # def open(reply_data)
30- # reply reply_data.merge(message_type: 'open', type: 'admin')
31- # end
31+ def close (self , ** reply_data ):
32+ reply_data ['type' ] = 'admin'
33+ reply_data ['message_type' ] = 'close'
34+ return self .__reply (reply_data )
35+
36+ def __reply (self , reply_data ):
37+ _id = reply_data .pop ('id' )
38+ collection = utils .resource_class_to_collection_name (self .collection_class ) # noqa
39+ url = "/%s/%s/reply" % (collection , _id )
40+ reply_data ['conversation_id' ] = _id
41+ response = self .client .post (url , reply_data )
42+ return self .collection_class ().from_response (response )
3243
33- # def close(reply_data)
34- # reply reply_data.merge(message_type: 'close', type: 'admin')
35- # end
3644
37- # def assign(reply_data)
38- # assignee_id = reply_data.fetch(:assignee_id) { fail 'assignee_id is required' } # noqa
39- # reply reply_data.merge(message_type: 'assignment', assignee_id: assignee_id, type: 'admin') # noqa
45+ # def mark_read(id)
46+ # @client.put("/conversations/#{id}", read: true)
4047# end
41- # end
42- # end
43- # end
0 commit comments