RemoteControlLimeSurvey2

From Request Tracker Wiki
Jump to: navigation, search

Implementing a Survey using LimeSurvey Version 2 with RT 3.8

With this article, I would like to help you to implement a survey for every ticket, if desired.

Setup

  1. Add a Custom Field called "CustomerSurveyToken"
  2. Setup Limesurvey and activate JSON-RPC (http://manual.limesurvey.org/wiki/RemoteControl_2_API)
  3. Change the Global Template "Resolved" as following: Subject: Your subject Content-type: text/plain; charset=utf-8 Your text... [...] { use strict; use warnings; use JSON::RPC::Client; ; }{ my $baseurl = 'https://your.server/limesurvey/index.php'; my $apiurl = $baseurl . '/admin/remotecontrol'; my $surveyurl = $baseurl . '/survey/index/sid/%s/token/%s'; my $cf_name = 'CustomerSurveyToken'; my $user = 'username for limesurvey-api'; my $password = 'password for limesurvey-api'; my $survey_id = your survey-id; my $token = $Ticket->FirstCustomFieldValue($cf_name); my ($toEmailAddr) = $Ticket->Requestors->MemberEmailAddresses; my $partData = [ { email => $toEmailAddr }, ]; if($token eq && $toEmailAddr) { my $client = JSON::RPC::Client->new(); $client->{id} = 1; my $sessionKeyResult = $client->call($apiurl, { method => 'get_session_key', params => [$user, $password] }); if($sessionKeyResult && !$sessionKeyResult->is_error) { my $sessionKey = $sessionKeyResult->result; my $participantResult = $client->call($apiurl, { method => 'add_participants', params => [$sessionKey, $survey_id, $partData] }); if($participantResult && !$participantResult->is_error) { $token = $participantResult->result->[0]->{'token'}; my $cf_obj = RT::CustomField->new($RT::SystemUser); $cf_obj->LoadByName( Name => $cf_name ); $Ticket->AddCustomFieldValue(Field => $cf_obj, Value => $token, RecordTransaction => 0); } $client->call($apiurl, { method => 'release_session_key', params => [$sessionKey] }); } } my $url = ; if($token) { $url = sprintf($surveyurl, $survey_id, $token); } $url; } [...] your footer [...]