BigFix AEX Livestation Attachment Feature

BigFix AEX has the attachment feature through which one can upload attachments. Attachments can be of any type - jpg, jpeg, pdf, txt or xlsx.

User can transfer the file to third party in the form of bytes, streams or base 64.

In BigFix AEX Web Action is used for it.

What is Web Action?

A web action is an action that can be invoked without authentication and can be used to implement HTTP handlers that respond with headers, status code, and body content of different types. When you create an IBM Cloud® Functions web action, you generate a URL to invoke that action from any web-based app. It can be trigger from any web-based app.

Through this URL we can trigger the web action from anywhere and can send the file data into it.

Furthermore, we can call any client API from where attachment can be uploaded to the required storage.

We need to call a particular rule using web action method. The rule must contain about dynamic JavaScript which helps the user to populate the file-upload options in BigFix AEX chat window, a sample of the code has been appended here in below:

<script>

if (params.entered_message === 'upload') {

const random = Math.floor(Math.random() * 10000000000);

const host = params.creds.apihost.split('.')[0] + '.functions' + '.appdomain.cloud';

const webActionUrl = 'https://' + host + '/api/v1/web/' + params.creds.namespace + '/default/' + 'livestation_file_transfer.json?blocking=true';

function fileUpload_${ random }(_this){

$(_this).removeClass('option_link').addClass('disabled_link');

const fileInput = document.querySelector('#file-upload-${ random }');

const successDiv = document.querySelector('#success-upload-${ random }');

console.log('successDiv',successDiv);

const file = fileInput.files[0];

console.log('fileeeeeeeeee',file);

const reader = new FileReader();

reader.onload = () => {

console.log('reader...aaaa..',reader);

const base64 = reader.result;

const jsonObject = {};

jsonObject.fileData = base64;

jsonObject.fileName = file.name;

console.log('jsonObject',jsonObject);

fetch("${ webActionUrl }", {

method: "POST",

headers: {

'accept': 'application/json',

'Content-type': 'application/json'

},

body: JSON.stringify(jsonObject)

})

.then(response => response.json())

.then(json => {

console.log('json>>>>>>>>>>>>>',json.message);

if(json.message === 'success'){

console.log('inside if',json.ticketNumber);

document.getElementById("success-upload-${ random }").style.display = "block";

document.getElementById("success-upload-${ random }").innerHTML += 'We have successfully uploaded file. ' + json.ticketNumber + ' ' + '<a href="#" class="option_link ChatBotBtn">Do you want to proceed?</a>';

}else{

document.getElementById("failure-upload-${ random }").style.display = "block";

}

})

}

reader.readAsDataURL(file);

}

</script>