FCLT#84767 savepoint
svn path=/Website/branches/v2024.3/; revision=67894
This commit is contained in:
@@ -23,6 +23,9 @@ ANONYMOUS_Allowed = 1;
|
||||
if (ll > 0)
|
||||
__Logging = ll; // Voor de rest van dit bestand
|
||||
|
||||
var channel = getQParamSafe("channel", "");
|
||||
var xkey = getQParamInt("xkey", -1);
|
||||
|
||||
function getRequestParams(p_method, p_action, params)
|
||||
{
|
||||
var errmsg = "";
|
||||
@@ -38,7 +41,7 @@ ANONYMOUS_Allowed = 1;
|
||||
// req_conn.actie wordt gewijzigd bij attachments als params.info.boundary bestaat.
|
||||
switch (p_method)
|
||||
{
|
||||
case "GET": req_conn.ext_url = doel + (params.info.extern_id ? "/"+params.info.extern_id : "");
|
||||
case "GET": req_conn.ext_url = doel + (params.info.externid ? "/"+params.info.externid : "");
|
||||
req_conn.methode = "GET";
|
||||
req_conn.actie = p_action;
|
||||
req_conn.content = "application/json";
|
||||
@@ -48,8 +51,8 @@ ANONYMOUS_Allowed = 1;
|
||||
req_conn.actie = p_action;
|
||||
req_conn.content = "application/json";
|
||||
break;
|
||||
case "PUT": missing_id = (params.info.extern_id ? false : true);
|
||||
req_conn.ext_url = doel + "/" + params.info.extern_id;
|
||||
case "PUT": missing_id = (params.info.externid ? false : true);
|
||||
req_conn.ext_url = doel + "/" + params.info.externid;
|
||||
req_conn.methode = "PUT";
|
||||
req_conn.actie = p_action;
|
||||
req_conn.content = "application/json";
|
||||
@@ -107,7 +110,9 @@ ANONYMOUS_Allowed = 1;
|
||||
}
|
||||
else
|
||||
{ // De tekst van de foutstatus.
|
||||
request_result.errmsg = http_request.statusText;
|
||||
var response_error = (http_request.responseText ? JSON.parse( http_request.responseText) : {});
|
||||
request_result.errmsg = http_request.statusText
|
||||
+ ": " + response_error.error.title + " (" + response_error.error.message + ")";
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
@@ -118,6 +123,64 @@ ANONYMOUS_Allowed = 1;
|
||||
return request_result;
|
||||
}
|
||||
|
||||
function call_zendesk(coupler, data_to_sent)
|
||||
{
|
||||
var bevinding = {};
|
||||
if (coupler.info.method != 'NONE')
|
||||
{
|
||||
var conn_params = getRequestParams(coupler.info.method, coupler.info.action, coupler);
|
||||
if (conn_params.success)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
__Log({"conn_params": conn_params});
|
||||
__Log({"doRequest": {"req_conn": conn_params.req_conn, "data_to_sent": data_to_sent}});
|
||||
bevinding = { result: { success: true
|
||||
, status: 200
|
||||
, message: ""
|
||||
}
|
||||
, data: {ticket: {custom_fields: {}, fields: {}, audit: {}}}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var conn_result = doRequest(conn_params.req_conn, data_to_sent);
|
||||
if (conn_result.success)
|
||||
{
|
||||
bevinding = { result: { success: true
|
||||
, status: conn_result.status
|
||||
, message: conn_result.errmsg
|
||||
}
|
||||
, data: conn_result.data
|
||||
};
|
||||
}
|
||||
else
|
||||
{ // Een foutmelding van request of een algemene fout.
|
||||
bevinding = { result: { success: false
|
||||
, status: conn_result.status
|
||||
, message: conn_result.errmsg
|
||||
}};
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // Er is iets fout gegaan met het maken van de request parameters.
|
||||
bevinding = { result: { success: false
|
||||
, status: 601
|
||||
, message: conn_params.errmsg
|
||||
}};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bevinding = { result: { success: true
|
||||
, status: 200
|
||||
, message: "er hoeft geen bericht verstuurd te worden"
|
||||
}};
|
||||
}
|
||||
return bevinding;
|
||||
}
|
||||
|
||||
function encryptAuth(api_user, api_key)
|
||||
{
|
||||
var oCrypto = new ActiveXObject("SLNKDWF.Crypto");
|
||||
@@ -125,9 +188,15 @@ ANONYMOUS_Allowed = 1;
|
||||
return encoded;
|
||||
}
|
||||
|
||||
function cloneObject(obj)
|
||||
{
|
||||
var cloned_obj = JSON.parse(JSON.stringify(obj));
|
||||
return cloned_obj;
|
||||
}
|
||||
|
||||
function load_headerdata()
|
||||
{
|
||||
__Log("load_headerdata");
|
||||
__Log("load_headerdata");
|
||||
// Lees de xml-data uit de html-header.
|
||||
var xmlReq = Server.CreateObject("MSXML2.DOMDocument.6.0");
|
||||
xmlReq.load(Request);
|
||||
@@ -138,7 +207,7 @@ __Log("load_headerdata");
|
||||
|
||||
function test_loader()
|
||||
{
|
||||
__Log("TEST_LOADER");
|
||||
__Log("TEST_LOADER");
|
||||
function loadMSXML(x)
|
||||
{
|
||||
var fso = new ActiveXObject("Scripting.FileSystemObject");
|
||||
@@ -166,7 +235,7 @@ __Log("TEST_LOADER");
|
||||
var custpath = "../../CUST/WELK";
|
||||
var loader = { success: false
|
||||
, status: -1
|
||||
, xml: { file: Server.MapPath(custpath + "/xsl/" + "puo_20250121-160652_00_make_xml.xml") }
|
||||
, xml: { file: Server.MapPath(custpath + "/xsl/" + "puo_20250205-163742_00_make_xml.xml") }
|
||||
, xsl: { file: Server.MapPath(custpath + "/xsl/" + "zendesk.xsl") }
|
||||
};
|
||||
loader.xml = loadMSXML(loader.xml);
|
||||
@@ -200,10 +269,27 @@ __Log("TEST_LOADER");
|
||||
result.data = obj;
|
||||
}
|
||||
}
|
||||
__Log(result);
|
||||
//__Log(result);
|
||||
return result.data.facilitor;
|
||||
}
|
||||
|
||||
function getTypeOf(value)
|
||||
{
|
||||
if (typeof value === "string" || value instanceof String) return "isString";
|
||||
if (typeof value === "number" && isFinite(value)) return "isNumber";
|
||||
if (typeof value === "boolean") return "isBoolean";
|
||||
if (typeof value === "symbol") return "isSymbol";
|
||||
if (typeof value === "undefined") return "isUndefined";
|
||||
if (typeof value === "function") return "isFunction";
|
||||
if (value === null) return "isNull";
|
||||
if (value && typeof value === "object" && value.constructor === Array) return "isArray";
|
||||
if (value && typeof value === "object" && value.constructor === Object) return "isObject";
|
||||
if (value && typeof value === "object" && value.constructor === RegExp) return "isRegExp";
|
||||
if (value instanceof Error && typeof value.message !== "undefined") return "isError";
|
||||
if (value instanceof Date) return "isDate";
|
||||
return "isUnknown";
|
||||
}
|
||||
|
||||
function fieldlist_to_array(p_fieldlist)
|
||||
{
|
||||
var v_field_arr = [];
|
||||
@@ -215,34 +301,76 @@ __Log("TEST_LOADER");
|
||||
return v_field_arr;
|
||||
}
|
||||
|
||||
// *************************************************************************
|
||||
// *************************************************************************
|
||||
var test_xml_only = true;
|
||||
__Log("*> ZENdesk.api");
|
||||
var bevinding = {};
|
||||
if (test_xml_only)
|
||||
function getTicket(p_data)
|
||||
{
|
||||
var facilitor = test_loader();
|
||||
var v_data = {};
|
||||
v_data.ticket = cloneObject(p_data.opdracht);
|
||||
// custom_fields moet een array worden.
|
||||
facilitor.zendesk.data.ticket.custom_fields = fieldlist_to_array(facilitor.zendesk.data.ticket.custom_fields);
|
||||
__Log(facilitor);
|
||||
__Log("*< ZENdesk.api");
|
||||
Response.Write(JSON.stringify(bevinding));
|
||||
Response.End;
|
||||
}
|
||||
else
|
||||
{
|
||||
var facilitor = load_headerdata();
|
||||
// custom_fields moet een array worden.
|
||||
facilitor.zendesk.data.ticket.custom_fields = fieldlist_to_array(facilitor.zendesk.data.ticket.custom_fields);
|
||||
__Log(facilitor);
|
||||
v_data.ticket.custom_fields = fieldlist_to_array(v_data.ticket.custom_fields);
|
||||
return v_data;
|
||||
}
|
||||
|
||||
function getTicketComment(p_data, p_key, p_request)
|
||||
{
|
||||
var v_notities = cloneObject(p_data.notities);
|
||||
var user_request = cloneObject(p_request);
|
||||
user_request.info = { method: "POST"
|
||||
, action: "upsert_user"
|
||||
};
|
||||
if (getTypeOf(v_notities) != "isArray")
|
||||
v_notities = [v_notities];
|
||||
var v_notitie = { result: { success: false
|
||||
, status: 610
|
||||
, message: "No comment found"
|
||||
}
|
||||
};
|
||||
for (var i=0; i<v_notities.length; i++)
|
||||
{
|
||||
if (v_notities[i].key == p_key)
|
||||
{
|
||||
v_notitie.ticket = v_notities[i];
|
||||
if (getTypeOf(v_notitie.ticket.comment.author_id.lookup.user.email) != "isString")
|
||||
{ // Verwijderen email als deze leeg is.
|
||||
delete v_notitie.ticket.comment.author_id.lookup.user.email;
|
||||
}
|
||||
delete v_notitie.ticket.key; // Deze heb je alleen nodig voor het vinden van de juiste notitie. Mag nu weg.
|
||||
// user gegevens vervangen door user-id van Zendesk.
|
||||
var user_data_to_sent = v_notitie.ticket.comment.author_id.lookup;
|
||||
var user_result = call_zendesk(user_request, user_data_to_sent);
|
||||
v_notitie.result = user_result.result;
|
||||
if (user_result.result.success)
|
||||
{ // De notitie kan nu verstuurd worden.
|
||||
v_notitie.ticket.comment.author_id = user_result.data.user.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return v_notitie;
|
||||
}
|
||||
|
||||
function update_mldopdr(methode, actie, ticket)
|
||||
{
|
||||
if (methode == "POST" && actie)
|
||||
{
|
||||
var sql = "UPDATE mld_opdr"
|
||||
+ " SET mld_opdr_externnr = " + ticket.id
|
||||
+ " WHERE mld_opdr_key = " + ticket.external_id;
|
||||
Oracle.Execute(sql);
|
||||
}
|
||||
}
|
||||
|
||||
// *************************************************************************
|
||||
// *************************************************************************
|
||||
__Log("*> ZENdesk.api channel="+channel+" xkey="+xkey);
|
||||
var actions = { "ticket": "/api/v2/tickets"
|
||||
, "request": "/api/v2/requests"
|
||||
, "brand": "/api/v2/brands"
|
||||
, "organization": "/api/v2/organizations"
|
||||
, "group": "/api/v2/groups"
|
||||
, "group": "/api/v2/groups"
|
||||
, "upsert_user": "/api/v2/users/create_or_update"
|
||||
// nieuwe ticket versturen
|
||||
// POST /api/v2/tickets.json
|
||||
// met data: {"ticket": {"subject": "My printer is on fire!", "comment": { "body": "The smoke is very colorful." }}}
|
||||
//
|
||||
// notities worden aan een ticket toegevoegd als comments in het ticket:
|
||||
// PUT /api/v2/tickets/{id}.json
|
||||
// met data: {"ticket": {"comment": {"body": "de notitie tekst", "author_id": 12345678}}}
|
||||
@@ -251,71 +379,51 @@ var test_xml_only = true;
|
||||
// POST /api/v2/uploads?filename=<bestandsnaam>&token=<optional_token>
|
||||
}
|
||||
|
||||
var debug = false;
|
||||
var facilitor = (debug ? test_loader() : load_headerdata());
|
||||
__Log(facilitor);
|
||||
var bevinding = {};
|
||||
|
||||
if (facilitor && facilitor.zendesk)
|
||||
{
|
||||
var coupler = facilitor.zendesk || {};
|
||||
coupler.api_auth = encryptAuth(coupler.api_user, coupler.api_key);
|
||||
coupler.actions = actions;
|
||||
var v_data = facilitor.zendesk.data;
|
||||
var v_request = facilitor.zendesk.request;
|
||||
v_request.api_auth = encryptAuth(v_request.api_user, v_request.api_key);
|
||||
v_request.actions = actions;
|
||||
|
||||
//
|
||||
// Zoek eventueel eerst de benodigde id's op
|
||||
//
|
||||
// Deze log staat als commentaar omdat in deze JSON ook de base64 coded bijlage zit. Dat levert te veel logging op.
|
||||
//__Log(coupler);
|
||||
// We gaan alleen een bericht versturen als we een geldige methode hebben. We gebruiken de methode NONE om
|
||||
// aan te geven dat dit bericht niet verstuurd hoeft te worden. Dit is de mogelijkheid om
|
||||
// in de stylesheet aan te geven dat je geen bericht wilt versturen op deze notificatie.
|
||||
if (coupler.info.method != 'NONE')
|
||||
switch (channel)
|
||||
{
|
||||
var conn_params = getRequestParams(coupler.info.method, coupler.info.action, coupler);
|
||||
if (conn_params.success)
|
||||
{
|
||||
__Log(conn_params.req_conn.methode + ": " + conn_params.req_conn.baseurl + conn_params.req_conn.ext_url);
|
||||
__Log( {"conn_params": conn_params});
|
||||
var conn_result = doRequest(conn_params.req_conn, coupler.data);
|
||||
if (conn_result.success)
|
||||
{
|
||||
delete conn_result.data.ticket.custom_fields; // bevat alleen lege velden
|
||||
delete conn_result.data.ticket.fields; // bevat alleen lege velden
|
||||
delete conn_result.data.audit; // nu niet nodig maar bevat misschien wel nuttige informatie
|
||||
bevinding = { result: { success: true
|
||||
, status: conn_result.status
|
||||
, message: conn_result.errmsg
|
||||
}
|
||||
, ticket: conn_result
|
||||
, attach: ""
|
||||
};
|
||||
if (conn_params.req_conn.methode == "POST" && conn_params.req_conn.actie)
|
||||
{
|
||||
var sql = "UPDATE mld_opdr"
|
||||
+ " SET mld_opdr_externnr = " + conn_result.data.ticket.id
|
||||
+ " WHERE mld_opdr_key = " + conn_result.data.ticket.external_id;
|
||||
Oracle.Execute(sql);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // Een foutmelding van request of een algemene fout.
|
||||
bevinding = { result: { success: false
|
||||
, status: conn_result.status
|
||||
, message: conn_result.errmsg
|
||||
}};
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // Er is iets fout gegaan met het maken van de request parameters.
|
||||
bevinding = { result: { success: false
|
||||
, status: 601
|
||||
, message: conn_params.errmsg
|
||||
}};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bevinding = { result: { success: true
|
||||
, status: 200
|
||||
, message: "er hoeft geen bericht verstuurd te worden"
|
||||
}};
|
||||
case "ORD": var data_to_sent = getTicket(v_data);
|
||||
bevinding = call_zendesk(v_request, data_to_sent);
|
||||
if (bevinding.result.success)
|
||||
{
|
||||
var data_received = bevinding.data;
|
||||
delete data_received.ticket.custom_fields; // bevat alleen lege velden
|
||||
delete data_received.ticket.fields; // bevat alleen lege velden
|
||||
delete data_received.audit; // nu niet nodig maar bevat misschien wel nuttige informatie
|
||||
delete bevinding.data;
|
||||
bevinding.ticket = data_received.ticket;
|
||||
}
|
||||
bevinding.attach = "";
|
||||
|
||||
update_mldopdr(v_request.info.method, v_request.info.action, bevinding.ticket);
|
||||
break;
|
||||
case "NOT": var bevinding = getTicketComment(v_data, xkey, v_request);
|
||||
if (bevinding.result.success)
|
||||
{
|
||||
var data_to_sent = bevinding.ticket;
|
||||
bevinding = call_zendesk(v_request, data_to_sent);
|
||||
if (bevinding.result.success)
|
||||
{
|
||||
var data_received = bevinding.data;
|
||||
delete data_received.ticket.custom_fields; // bevat alleen lege velden
|
||||
delete data_received.ticket.fields; // bevat alleen lege velden
|
||||
delete bevinding.data;
|
||||
bevinding.comment = data_received.ticket;
|
||||
}
|
||||
bevinding.attach = "**"
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user