Skip to content

Instantly share code, notes, and snippets.

View tstachl's full-sized avatar

Thomas Stachl tstachl

  • Pilina
  • Remote
View GitHub Profile
@tstachl
tstachl / case_theme.html
Created October 10, 2013 19:46
Very simple example of how you can use JavaScript within case themes.
<div id="save_{{case.id}}">
<div class="agent_ticket_section">
{{subject}}
</div>
<div class="agent_ticket_section">
@tstachl
tstachl / pagination_LastToFirst_example.js
Created October 22, 2013 00:26
This is an example of how you can use the desk.js pagination from the last page to the first page.
// get the first cases page
client.cases(function(err, cases) {
// define a worker function that handles the
// cases and starts over with the previous page
// make sure you have a "callback" (doSomethingElse)
// function defined before going into this loop
function workCases(err, cases) {
// test if cases is null (previous will return null
// if there is no previous page)
if (cases !== null) {
@tstachl
tstachl / import_customers.rb
Created October 29, 2013 16:56
Simple example of importing customers to desk.com using the API with the API wrapper gem https://github.com/tstachl/desk.
require 'desk_api'
require 'csv'
client = DeskApi::Client.new({
username: 'you@example.com', # your desk.com username
password: 'yourpassword', # your desk.com password
subdomain: 'yoursubdomain' # your desk.com subdomain (https://this.desk.com)
})
CSV.foreach('./customers.csv', headers: true) do |row|
@tstachl
tstachl / DeskLabelService.class
Created October 31, 2013 01:02
This gist shows how you can add additional information (in this case we fetch the labels) from desk.com with the Sealsforce integration.
public class DeskLabelService
{
private static String OAUTH_KEY = 'your_consumer_key';
private static String OAUTH_SECRET = 'your_consumer_secret';
private static String ACCESS_TOKEN = 'your_access_token';
private static String ACCESS_TOKEN_SECRET = 'your_access_token_secret';
public static String DESK_DOMAIN = 'yourdomain.desk.com';
@future(callout=true)
require 'desk_api'
require 'json'
site = {
username: 'you@example.com',
password: 'yourpassword',
site_name: 'yoursubdomain'
}
client = DeskApi::Client.new username: site[:username], password: site[:password], subdomain: site[:site_name]
<?php
$case = array(
'type' => 'email',
'subject' => 'Email Case Subject',
'priority' => 4,
'status' => 'open',
'labels' => array('Spam', 'Ignore'),
'message' => array(
'direction' => 'in',
global class FetchGroupsAndUsers implements Schedulable, Database.Batchable<DeskResource>, Database.AllowsCallouts
{
public static String CRON_EXPRESSION = '0 0 0 * * ? *';
global static final DeskClient DESK_CLIENT = new DeskClient(new Map<String, String>{
'username' => 'support@example.com',
'password' => 'somepassword',
'subdomain' => 'devel'
});
@tstachl
tstachl / AdminReport.html
Created December 18, 2013 02:36
This gist shows a very simple way of fetching all admin users in your desk.com account and displaying it in a knowledge base article. IMPORTANT: this will only work if you're logged in as a desk.com agent and should never be a public article.
<style>
table#users { width: 100%; }
table#users th { font-weight: bold; font-size: 120%; }
</style>
<table class="table table-striped" id="users">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
@tstachl
tstachl / search_customer_create_case.php
Created December 18, 2013 19:35
This php script shows how you search for a customer before creating the case, however it doesn't plan for the customer not existing, you'd have to check the response for total_entries == 0 or an empty entries array and create the customer accordingly.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://yoursite.desk.com/api/v2/customers/search?email=thomas%40stachl.me");
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_USERPWD, "email:password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@tstachl
tstachl / Gemfile
Created January 15, 2014 16:43
Export knowledge base articles from desk.com and zip them up for a salesforce.com import.
source 'https://rubygems.org'
ruby '2.0.0'
gem 'desk_api', '0.5.0'
gem 'rubyzip', '1.1.0'
gem 'open_uri_redirections', '0.1.4'