Created
June 8, 2015 15:43
-
-
Save tstachl/a4a86d31eda120abc849 to your computer and use it in GitHub Desktop.
Create an outbound email case for a customer by email.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'desk_api' # @see https://github.com/forcedotcom/salesforce-deskcom-api | |
# authenticate `DeskApi` with your Desk.com instance | |
##### | |
# FIND OR CREATE CUSTOMER | |
##### | |
# you should get the customer data from your system | |
customer_data = { | |
first_name: 'John', | |
last_name: 'Smith', | |
emails: [{ type: 'home', value: '[email protected]' }] | |
} | |
# find the customer by email address | |
query = customer_data.emails.map { |x| x[:value] }.join(',') | |
search = DeskApi.customers.search(email: query) | |
if search.total_entries == 0 # create customer if he doesn't exist | |
customer = DeskApi.customers.create(customer_data) | |
else # use the existing customer | |
customer = search.entries.first | |
end | |
##### | |
# CREATE THE OUTBOUND CASE | |
##### | |
# this is the email you want to send to your customer | |
email_data = { | |
direction: 'out', | |
status: 'pending', | |
subject: 'Email Subject', | |
body: 'Email Message', | |
from: 'Laura Agent <[email protected]>', | |
to: 'John Smith <[email protected]>', | |
cc: 'Mark Snider <[email protected]>', | |
bcc: 'Reid Wheeler <[email protected]>' | |
} | |
# additional ticket information | |
ticket_data = { | |
type: 'email', | |
subject: email_data[:subject], | |
priority: 4, | |
status: 'pending', | |
labels: ['Follow Up'], | |
message: email_data, | |
custom_fields: { level: 'vip' }, | |
_links: { | |
customer: customer.get_self, | |
assigned_user: { href: '/api/v2/users/1', class: 'user' }, | |
assigned_group: { href: '/api/v2/groups/1', class: 'group' } | |
} | |
} | |
# create the case | |
ticket = DeskApi.cases.create(ticket_data) | |
# at this point the case has been created | |
# and the email is queued to be sent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment