Skip to content

Commit e65da0e

Browse files
committed
Add a call to create thread in HelpScout
It's useful to create a note and such
1 parent 7be7052 commit e65da0e

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

lib/help_scout.rb

+23
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,29 @@ def reports_user_ratings(user_id, rating, start_date, end_date, options)
115115
get("reports/user/ratings", options)
116116
end
117117

118+
119+
# Public: Creates conversation thread
120+
#
121+
# conversion_id - conversation id
122+
# thread - thread content to be created
123+
# imported - When set to true no outgoing emails or notifications will be
124+
# generated
125+
# reload - Set to true to get the entire conversation in the result
126+
#
127+
# More info: http://developer.helpscout.net/help-desk-api/conversations/create-thread/
128+
#
129+
# Returns true if created, false otherwise
130+
def create_thread(conversation_id:, thread:, imported: nil, reload: nil)
131+
query = {}
132+
{ reload: reload, imported: imported }.each do |key, value|
133+
query[key] = value unless value.nil?
134+
end
135+
136+
post("conversations/#{conversation_id}", body: thread, query: query)
137+
138+
last_response.code == HTTP_CREATED
139+
end
140+
118141
protected
119142

120143
def post(path, options = {})

spec/helpscout_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,28 @@
8888
expect(client.search_conversations("tag:conversion")).to eq conversations["items"]
8989
end
9090
end
91+
92+
describe '#create_thread' do
93+
let(:thread) do
94+
{
95+
createdBy: {
96+
type: 'user',
97+
id: 42,
98+
},
99+
type: 'note',
100+
body: "Hello, I'm a noteworthy!"
101+
}
102+
end
103+
104+
it 'does the correct query' do
105+
url = 'https://api.helpscout.net/v1/conversations/4242.json'
106+
req = stub_request(:post, url).
107+
with(body: thread.to_json).
108+
to_return(status: 201)
109+
110+
expect(client.create_thread(conversation_id: 4242, thread: thread)).
111+
to eq(true)
112+
expect(req).to have_been_requested
113+
end
114+
end
91115
end

0 commit comments

Comments
 (0)