-
Notifications
You must be signed in to change notification settings - Fork 5
/
export.rb
41 lines (27 loc) · 1.04 KB
/
export.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'helpscout'
api_key = ARGV[0]
mailbox_id = ARGV[1]
helpscout = HelpScout::Client.new(api_key)
if mailbox_id.nil?
puts "All mailboxes"
puts "============="
mailboxes = helpscout.mailboxes
mailboxes.each do |mailbox|
puts "#{mailbox.id} - #{mailbox.name}"
end
print "Enter the number of the mailbox to export: "
mailbox_id = STDIN.gets.chomp
end
mailbox = helpscout.mailbox(mailbox_id)
puts "Exporting #{mailbox.name}..."
active_conversations = helpscout.conversations(mailbox_id, "active", nil)
pending_conversations = helpscout.conversations(mailbox_id, "pending", nil)
conversations = active_conversations + pending_conversations
CSV.open("conversations_#{mailbox_id}.csv", "wb", col_sep: ';', headers: true) do |csv|
csv << ["Number", "From", "Subject", "Created"]
conversations.each do |conversation|
customer = conversation.customer
csv << [conversation.number, customer.email, conversation.subject, conversation.createdAt]
end
end
puts "Active and pending conversations written to export_#{mailbox_id}.csv."