Sample custom node to update or add a contact into CE campaign database.
Note
This code uses sample values hardwired in the XML code! Make sure you review and understand it before using it in production.
Template Data Sheet
Name |
Minimum Engine version |
Minimum Designer version |
CEAppendContact_example |
2.1 |
7.5.0 |
Parameters
Exit Points
Name |
Description |
error |
Error happened during the process. |
ok |
AppendContact succeeded. |
JSON
{
"name": "CEAppendContact",
"type": "template",
"description": "<b>CEAppendContact</b> template:<br/> Append contact data frontend",
"attributes": [
{
"name": "id",
"type": "integer",
"defaultvalue": "3700"
}
],
"parameters": [
{
"name": "m_compsrv"
},
{
"name": "m_sipuri"
}
],
"connections": [
{
"name": "error"
},
{
"name": "ok"
}
]
}
XML
<template name="CEAppendContact" id="#ID#" version="1.1">
<parameters>
<parameter id="m_compsrv"><![CDATA[#M_COMPSRV#]]></parameter>
<parameter id="m_sipuri"><![CDATA[#M_SIPURI#]]></parameter>
</parameters>
<connections namedoutputs="true">
<connection name="error" destination="#ERROR#" />
<connection name="ok" destination="#OK#" />
</connections>
<flow>
<nodes>
<script id="1">
<parameters>
<parameter id="m_compsrv" type="Variable" datatype="String" direction="Input">?</parameter>
<parameter id="m_sipuri" type="Variable" datatype="String" direction="Input">?</parameter>
</parameters>
<connections namedoutputs="true">
<connection exitpoint="error" name="ERROR" destination="?" />
<connection exitpoint="ok" name="OK" destination="?" />
</connections>
<data><![CDATA[
try {
var hfrom = '' + headers['FROM'];
var m = hfrom.match(/^.*<sip:(\+?\d+)(\D.*)?@.*$/);
var caller = "";
if (( m != null) && (m.length > 1)) {
caller = m[1];
}
if (caller == "") {
m = hfrom.match(/^.*<(sip:.*@.*)>.*$/);
if ((m != null) && (m.length > 1)) {
caller = m[1];
}
}
if (caller.length > 3) {
log.debug("Caller:" + caller);
$$nextConnection$$ = 'ERROR';
var url = '' + LOCALS['m_compsrv'];
var sipuri = '' + LOCALS['m_sipuri'];
var tenantid = flowvars['TENANT_ID'];
if (tenantid === null) {
log.error("Tenant id not specified");
$$nextConnection$$ = 'ERROR';
}
else {
var timeout = 10000;
var mimetype = 'application/jsonrequest';
var js = toolkit.getJSonRetriever();
var req = {};
req["action"] = 'AppendContact';
req["tenant"] = parseInt(tenantid);
req["sipuri"] = sipuri;
var c = { };
c['filter'] = 'unique_field';
c['customer'] = 'IVR Inbound Contact';
c['phone1'] = caller;
c['data'] = {};
c['data']['unique_field'] = '88888';
c['data']['comment'] = 'Comment:' + new Date().toString();
req["contacts"] = [ c ];
var sresp = js.postData(url, timeout, JSON.stringify(req), mimetype);
var resp = JSON.parse(sresp);
if ((resp!= null) && (resp.result == 'TRUE')) {
$$nextConnection$$ = 'OK';
}
}
}
} catch (err) {
$$nextConnection$$ = 'ERROR';
log.error('Error in script:' + err);
}
log.debug('Script Done: nextConnection=' + $$nextConnection$$);
]]> </data>
</script>
</nodes>
</flow>
</template>