Attachments Object

Attachments Object in Cliq contains an array of deluge file objects. The attachments object is passed as an attribute during these following actions.

  • When files are uploaded to a bot.
  • When files are uploaded as arguments to a slash command.
  • When a message action is performed on a file.

Consider a scenario where you want to  you upload files Doc1.txt and Doc2.txt to your Google Drive with a slash command /uploadtodrive

The uploaded files will be present in the Attachments Object as below.


[
	Doc1.txt,
	Doc2.txt
]

 

Sample command execution handler code snippet for the above example is given below.

 



//Sample Syntax to illustrate attachments object
try 
{
  response = Map();
  detailsString = "";
  for each file in attachments
  {
     params = Map();
     params.put("name",file);
     comments = Map();
     comments.put("stringPart","true");
     comments.put("paramName","metaData");
     comments.put("content",params.toString());
     comments.put("contentType","application/json");
     comments.put("encodingType","UTF-8");
     fileList = List();
     fileList.add(comments);
     fileList.add(file);
     googleDriveResponse = invokeurl
     [
       url :"https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"
       type :POST
       files:fileList
       connection:"INSERT YOUR CONNECTION NAME"
     ];
	       
     fileDetails = invokeurl
     [
       url :"https://www.googleapis.com/drive/v3/files/" + encodeUrl(googleDriveResponse.get("id")) + "?fields=name,id,webViewLink&restrictToMyDrive=true"		  		
       type :GET
       connection:"INSERT YOUR CONNECTION NAME"
     ];
           
     detailsString += " [" + googleDriveResponse.get("name") + "]("+fileDetails.get("webViewLink")+"), ";
	 }

     response = {"text":"The files " +detailsString +" has been uploaded to your Google Drive. :thumbsup:"};
     return response;
}
catch (e)
{
     info e;
     return {"type":"banner","text":"Sorry for the inconvenience , Try again later.","status":"failure"};
}
return Map();