Skip to content

Instantly share code, notes, and snippets.

View oheyandy's full-sized avatar

Andrew Frauen oheyandy

  • Salesforce
  • San Francisco
View GitHub Profile
@oheyandy
oheyandy / Get_Resource_Ids.txt
Last active August 29, 2015 13:56
Example functions to get ID from a Desk.com API resource
Below are examples of functions to get the ID a resource in Desk when it's not availabie as a value on the resource itself.
There are two functions, get_resource_id() and get_collection_ids().
1. get_resource_id(resource)
- Takes one parameter, an individual resource (e.g., an article, group, etc.) which has been parsed from JSON into an object
- Returns the string as a value.
2. get_collection_ids(collection)
- Takes one parameter, a collection (e.g., a list or search result of articles, groups, etc.) which has been parsed from JSON into an array of objects
@oheyandy
oheyandy / case_theme_specificity.html
Created January 29, 2014 20:08
Quick example of how to set up a Desk.com case theme to allow specificity in JavaScript or CSS selection.
<!-- First, we'll wrap the entire case theme in a div and use Liquid to add the case ID to the element ID
so we can be specifically target elements within this case theme with CSS (or JavaScript! :D ) -->
<div id="custom_case_theme_{{case.id}}">
<style type="text/css">
/* Example of targeting an element on this specific case theme */
div#case_priority_indicator_{{case.id}} {
display: inline-block;
}
@oheyandy
oheyandy / INSTRUCTIONS.txt
Last active January 4, 2016 04:29
Instructions to import HTML articles via RSS in Desk.com w/ example XML file.
NOTE: These instructions assume that you already have all of the articles that you want to import
to Desk in HTML or plain text files (.html or .txt).
Copy the following URL and open it in a new tab in your browser:
https://gist.github.com/oheyandy/8568644/raw/001fc5a1bd07d3ff981ffc014c46594f74e5948f/sample_topic.xml
On that page, click "Save As" (generally under File > Save As in your tool or menu bar) and save
the file with the name of your topic (e.g., "my_topic.xml"). Repeat this process for each Topic that
you plan to import.
@oheyandy
oheyandy / simple_desk.rb
Last active January 3, 2016 10:09
Simple client for use with Desk.com API. Not perfect, but useful enough for testing. Beware: It's pretty sloppy. I really recommend using github.com/tstachl/desk instead.
# Create a new client, e.g.,
# myclient = DeskClient.new 'TOKEN', 'TOKEN_SECRET', 'CONSUMER_KEY', 'CONSUMER_SECRET', 'SUBDOMAIN'
#
# Make requests with GET/PUT/POST
# request bodies are automatically converted to JSON, so you can pass a hash
#
# customer = { first_name: "andy", emails: [ { type: "home", value: "andy@desk.com"} ] }
# create_customer = myclient.post '/api/v2/customers', customer
# update_customer = myclient.put '/api/v2/customers/1234', { phone: '555-123-1234' }
# show_customer = myclient.get '/api/v2/customer/1234'
@oheyandy
oheyandy / custom_image_and_hide.html
Last active January 2, 2016 21:49
Example code to use custom image with Desk.com chat or email widget, as well as to hide the widget between certain times.
<!--If you already have jquery on the page you don't need to insert this script tag-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<link href="https://d218iqt4mo6adh.cloudfront.net/assets/widget_embed_191.css" media="screen" rel="stylesheet" type="text/css" />
<!--If you already have fancybox on the page this script tag should be omitted-->
<script src="https://d218iqt4mo6adh.cloudfront.net/assets/widget_embed_libraries_191.js" type="text/javascript"></script>
<!-- Copy and paste the three resources ABOVE this comment line and place them in your page header -->
<!-- Copy and paste the code BELOW this comment line and place it one your page where you want the widget to display -->
def find_number(n)
nums = [[1,3,3,4],[2,3,3,4],[5,3,3,4],[6,3,3,4],[7,3,3,4],[8,3,3,4],[9,3,3,4],[0,3,3,4]]
maybes = Array.new(nums.size) { |num| nums[num].permutation.to_a.uniq! }
maybes.flatten!(1).sort!
"07700 90" + maybes[n-1].insert(1," ").join
end
def other_find_number(n)
nums = []
[1,2,5,6,7,8,9,0].each { |num| nums.push([num,3,3,4].permutation.to_a.uniq!)}
Create 12 custom snippets (https://support.desk.com/customer/portal/articles/566489-using-snippets-in-your-help-center) for each month (jan, feb, mar, etc.).
Below is the logic that we will use to translate the month in auto-acknowledgement by inserting a custom snippet instead of using the default "Jan", "Feb", "Mar", etc., values used by Liquid's date filter:
{% assign month = case.updated_at | in_time_zone: site.timezone | date: "%b" %}
{% if month == 'Jan' %}{{system.snippets.jan}}{% elsif month == 'Feb' %}
{{system.snippets.feb}}
{% elsif month == 'Mar' %}
{{system.snippets.mar}}
@oheyandy
oheyandy / default_signature.html
Last active December 26, 2015 10:59
Replace the comment on the third line with your default signature. Remove the example "<div>" tags if plaintext.
<div>
{% capture default_signature %}
<!-- This is where the default signature text/html should go. -->
{% endcapture %}
{% if case.user %}
{% if case.user.signature.size < 3 %}
{{default_signature}}
{%else%}
{{case.user.signature}}
{% endif %}
@oheyandy
oheyandy / company_custom_field_to_textarea.html
Created September 27, 2013 00:39
HTML example of how to display a Company custom text field as a textarea rather than an input field.
<div class="agent_company_section">
<!-- Replace all instances of "KEY" with the value of the fields KEY, e.g., "company.custom_interface_server". -->
<!-- If you do not know the key to your field, you will need to look it up in Admin > Cases > Company > Custom Fields by clicking on the name of the custom field and referencing the "Key" field. -->
<span class="agent_company_section_label label_custom label_custom_KEY">
Resolution
</span>
<div class="agent_company_section_data">
<!-- Inspect the source of the custom field that is automatically generated on your current case template (E.g., using Chrome's dev tools), and replace "custom1" in the id and name attributes of the div below with the correct value. -->
<textarea id="company_custom1" maxlength="255" name="company[custom1]" rows="2" class="default custom_field_string" type="text" cols="40" autocomplete="off" size="100">
{{company.custom_KEY}}
@oheyandy
oheyandy / label_email_from_chat.html
Last active December 23, 2015 14:09
Script to label emails submitted from Desk.com chat widget when chat unavailable.
<script type="text/javascript">
(function(){
setTimeout(function(){
var chat_widget = document.getElementsByClassName('a-desk-widget-chat')[0];
if (chat_widget.attributes['onclick'].value.indexOf('/customer/widget/emails/new') != -1) {
var email_form = chat_widget.attributes['onclick'].textContent;
var label_email = email_form.substring(0, email_form.indexOf('/emails/new?') + 12) + "ticket[labels_new]=ENTER%20YOUR%20LABEL%20HERE" + email_form.substring(email_form.indexOf('/emails/new?') + 12, email_form.length);
chat_widget.attributes['onclick'].textContent = label_email;
}
}, 1500);