Skip to content

Instantly share code, notes, and snippets.

@DeskWOW
Last active November 15, 2016 23:33
Show Gist options
  • Save DeskWOW/6539730 to your computer and use it in GitHub Desktop.
Save DeskWOW/6539730 to your computer and use it in GitHub Desktop.
Basic real-time article suggest functionality within your Desk.com support center contact form
Steps:
1) Edit your support center theme
2) Go to 'Advanced Themes' tab at the top
3) Go to "Email (New)" sub-theme on the left side
4) Insert the JavaScript below at the very bottom
5) Insert the HTML below beneath the contact form HTML
<div id="autosuggest" class="right-side" style="display: none;"></div>
<div id="common" class="right-side">
<h4>Common Questions</h4>
<ul class="no-bullets">
<li><span class="label label-info">New</span> <a class="article" href=
"/customer/portal/articles/566428-getting-started-multilingual-support">Multilingual
Support</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/351939-how-do-i-access-the-desk-com-mobile-app-">Accessing
Desk.com Mobile</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/2619-custom-fields-for-case-and-customer">Adding
and Using Custom Fields</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/1835-how-do-i-add-an-email-form-to-my-website-">Adding
an Email/Contact Form</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/1548-how-to-use-your-own-domain-for-the-portal">Change
the Address of your Portal</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/749107-integrating-desk-com-and-salesforce">Integrate
Salesforce and Desk.com</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/1376-understanding-business-rules">Understanding
Business Rules</a></li>
<li><a class="article" target="_blank" href="/customer/portal/articles/63009">Send Notifications For
Cases</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/2741-understanding-case-filters">Understanding
Case Filters</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/3085-how-do-i-add-a-chat-form-to-my-site-">Adding
Chat to your Site</a></li>
<li><a class="article" target="_blank" href=
"/customer/portal/articles/1424-understanding-the-case-lifecycle">Understanding
Case Statuses</a></li>
<li><a class="article" target="_blank" href="/customer/portal/articles/305053-glossary-of-terms">Glossary
of Terms</a></li>
</ul>
</div>
<script>
$(function() {
//populate referral page to cusom field
$("#ticket_custom_refpage").val(document.referrer);
// Skip pre-create
$('#new_email').attr('action','/customer/portal/emails');
// Real-time auto-suggest
$('#email_subject, #email_body').keyup(function() {
count = 0;
if ($('#email_subject').val().length > 2 || $('#email_body').val().length > 2) {
query = $('#email_subject').val() + " " + $('#email_body').val();
$.ajax({
url: '//YOURSITE.desk.com/customer/portal/articles/autocomplete?term=' + query,
dataType: 'json'
}).done(apiSuccess).fail(apiFail);
} else {
$("#autosuggest").hide();
$("#common").show();
}
});
});
apiSuccess = function(data) {
auto_suggest_content = "";
auto_suggest_articles = "";
auto_suggest_questions = "";
$('#autosuggest').html("<h4>Do these help?</h4><ul class='no-bullets'></ul>");
$.each(data, function() {
var html = $(this.label);
article_title = html.find(".article-autocomplete-subject").html();
if (this.id.indexOf("questions") !== -1) {
auto_suggest_questions += '<li><a target="_blank" href="' + this.id + '" class="discussion">' + article_title + '</a></li>';
} else {
auto_suggest_articles += '<li><a target="_blank" href="' + this.id + '" class="article">' + article_title + '</a></li>';
}
count++;
});
if (count > 0) {
$('#autosuggest ul').append(auto_suggest_articles + auto_suggest_questions);
$("#common").hide();
$("#autosuggest").show();
} else {
$("#autosuggest").hide();
$("#common").show();
}
};
apiFail = function(data) {
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment