Announcement notifications to POC of Accounts
Overview
The below document explains the steps needs to be configured for sending notifications to Point Of Contact(POC) of accounts, using announcements.
Implementation
To achieve this requirement, we will be using the following functionalities in our product.
DB trigger
Global functions
Callback Custom Functions
(I) DB Trigger configuration.
To configure DB trigger, add the following entries in the mentioned xml,
Edit [MSP_HOME]\conf\OperationHandler.xml and add following entries
<Module name="Announcement" table="Announcement" operation="C"/>
<OperationHandler>
<Module name="Announcement" table="Announcement" operation="C"/>
</OperationHandler>
Edit [MSP_HOME]\conf\Observers.xml and add the following entries
<Observer class="com.adventnet.mspdesk.service.ScriptObserver" modules="Announcement"/>
<?xml version="1.0" encoding="UTF-8"?>
<Observers>
<Observer class="com.adventnet.mspdesk.service.ScriptObserver" modules="Announcement"/>
</Observers>
Edit [MSP_HOME]\conf\ScriptObserver.xml and add following entries
<Script module="Announcement" output="ANNOUNCEID" table="Announcement" command="announcement_notification.txt"/>
<?xml version="1.0" encoding="UTF-8"?>
<Scripts>
<Script module="Announcement" output="ANNOUNCEID" table="Announcement" command="announcement_notification.txt"/>
</Scripts>
Create announcement_notification.txt under [MSP_HOME]\integration\custom_scripts\executor_files and place below content in it
py triggernotification.py $id announcements
Create triggernotification.py under [MSP_HOME]\integration\custom_scripts and place below content in it.
import requests
import sys,os
import json
import datetime
import time
from pprint import pprint
def postURL(url, data=None, json_data=None, params_data=None, files=None):
with requests.Session() as s:
return s.post(url,data=data, params=params_data, files=files,verify=False)
moduleid = sys.argv[1];
module = sys.argv[2];
#copy paste the customcallbackfuntion url here
baseurl = "http://zyker.com/AppIntegrations?serviceName=callbackFunctions&api_name=sendemailtopoccallback&auth_token=f63e3914ac4ba44d36287ec2a2a3122954803667ab9495e973f6f94bd19c8bc00de891a4e0b5c57ad7ea7249325584af8a673a93e1786613a3ecce8a9e614c0ec39be3ef4a8ae0459e1f93a9e2afcd4acaa52154&PORTALID=1";
url = baseurl+"&rawDataContent=%7B%22moduleid%22%3A%22"+moduleid+"%22%2C%22module%22%3A%22"+module+"%22%7D" ;
postURL(url);
Note : If there are existing entries in step 1,2,3 retain the same and add the new entries alone.
(II) Global functions
Configure the following global functions.
Function 1
Function Name - Get Configuration
Return type - Map
API Name - getconfiguration
Function definition Code
configuration = Map();
//configure the sdpmsp hosted url
configuration.put("url","http:/zyker.com");
//configure technician key of sdadmin permissions
configuration.put("technicianKey","D3689C12-D733-4059-9252-C343D5B32B92");
return configuration;
Note : Edit the url and techniciankey in the above function
Function 2
Function Name - Get Entity Details
Return type - Map
API Name - getentity
Parameters
entityid=int
entity=string
Function definition Code
configuration = getconfiguration();
headers= {"authtoken":configuration.get("technicianKey"),"portalid":1};
response = invokeurl
[
url: configuration.get("url") +"/api/v3/"+entity+"/"+entityid
type: GET
headers: headers
];
singularentity = entity.subString(0, entity.length()-1);
return response.get(singularentity);
Function 3
Function Name - Get POC for accounts
Return type - Map
API Name - getpocforaccounts
Parameters -
account=Map
Function definition Code -
configuration = getconfiguration();
newRequestObj = Collection();
headers= {"authtoken":configuration.get("technicianKey")};
accountvaluestosearch="";
fieldtosearch="";
if(account.containsKey("accountIDs")){
accountvaluestosearch = account.get("accountIDs");
fieldtosearch = "account.id";
}else{
accountvaluestosearch = account.get("accountNames");
fieldtosearch = "account.name";
}
//account={"accountIDs":["3","301"]};
//inputdata construction
list_info = Collection();
search_criteria = [{"field":"associated_roles","condition":"is","value":"SDPointOfContact"},{"field":fieldtosearch,"condition":"in","values":accountvaluestosearch,"logical_operator":"AND"}];
fields_required = Collection("id","name","email_id");
input_data = {"list_info":{"fields_required":fields_required,"search_criteria":search_criteria}};
//info input_data;
//info input_data;
response = invokeurl
[
url: configuration.get("url") +"/api/v3/users"
type: GET
parameters: {"input_data":input_data}
headers : headers
];
//info response;
return response;
Function 4
Function Name - Send Mail for POC
Return type - void
API Name - sendmailforaccountspoc
Parameters -
accountsjson=Map
messagecontent=String
subject=String
Function definition Code -
info accountsjson;
pocforaccounts = getpocforaccounts(accountsjson);
info pocforaccounts;
info pocforaccounts;
toemailIds="";
if(pocforaccounts.containKey("users")) {
users = pocforaccounts.get("users");
info users;
for each user in users
{
//If the email id belongs to technician, data is appended to technician details
if(toemailIds==""){
toemailIds=user.get("email_id");
}else{
toemailIds=toemailIds + "," + user.get("email_id");
}
}
}
info toemailIds;
for each toemail in toemailIds{
sendmail
[
from : "abc@zyker.com"
to : toemail
subject: subject
message : messagecontent
]
}
Note: Configure from address in Line no 23 in the above code. This email address will be used as from address to send mail to the POC of the accounts
(III) Custom Callback functions
Once the above Global functions are defined, configure the Custom call back function as below.
Function Name - Send Mail for POC
Return type - void
API Name - sendemailtopoccallback
Publish - True
Parameters -
moduleid=int
module=String
Function definition Code -
if("announcements".equals(module)){
announcementdetailsjson = getentity(moduleid,module);
if(announcementdetailsjson.get("is_public")!=true){
return;
}
accountsjsonarray = announcementdetailsjson.get("associated_accounts");
affectedaccountsname= Collection();
for each account in accountsjsonarray {
affectedaccountsname.insert(account.get("name"));
}
affectedaccountsjson={"accountNames":affectedaccountsname};
messagecontent=announcementdetailsjson.get("content");
title=announcementdetailsjson.get("title");
}
//send notifications to POC of affected acounts
sendmailforaccountspoc(affectedaccountsjson,messagecontent,title);
Note: Copy the URL shown under "URL to execute this Custom Function" and configure the same in triggernotification.py