Overview
The fileAttachments power allows you the ability to feed in csv file data that will be stored as part of a conversation attachment and be returned as an attachment in a tag message. This power will primarily be used in conjunction with the dialogue powers.
In this Article
When to use the fileAttachments power
The fileAttachments power should be used when storing a data file that will be returned to the user via the Andi® window, which the user can then click on to download the attachment.
How to use the fileAttachments power
The power can be used to pass in data to be returned in a csv file or to return a csv file stored in skill storage or accessible via an API (and then using the converToCSV method). It will be called via the fileAttachments property of the Andi powers and then returned as a promise.
return skillContext.powers.andi.fileAttachments.conversation
.storeCsvFileForCurrentUser(fileData, fileName?)
.then((response) => {
//the conditions for which the attachment will be returned
//in a tag
})
It consists of the following parameters:
- fileData - a required parameter, is the data to be stored, and that will be returned to the user in a csv file.
- fileName - an optional parameter entered as a string, is the name given to the file when the user initiates the download. If not provided, the file's unique identifier will be displayed.
Passing in Data
Here's an example of passing in data in the run.ts file that will be returned to the user as a csv file. In this case, the file data is defined and structured in the skill code and returned as part of a summary tag.
//defining the data and structure for the csv to be generated
const lines: string[] = [];
const header: string = "StringField,NumberField,BooleanField";
lines.push(header);
lines.push("string1,1,True");
lines.push("string2,2,False");
let csv: string = "";
let newLine: string = "\r\n";
for (let lineIndex: number = 0; lineIndex < lines.length; lineIndex++) {
const line: string = lines[lineIndex];
const isLastLine: boolean = ((lineIndex + 1) == lines.length);
csv = csv + line;
if (!isLastLine) { csv = csv + newLine; }
}
return skillContext.powers.andi.fileAttachments.conversation
.storeCsvFileForCurrentUser(csv, "Exception Approval Contacts")
.then((response) => {
const exceptionApprovalContactMessage = skillContext.powers.andi
.dialogue.composeDialogueTag(
"provide-latest-exception-approval-contact-list",
FieldTagTypes.Info,
"Click here to view the individuals to contact for an exception request.",
[
{
name: "downloadConversationFileAttachment",
args: [response.fileId]
}
]
)
return skillContext.powers.andi.dialogue.sendDialogueResponseWithTags("Exception Approval Contacts", [exceptionApprovalContactMessage])
});
Returning an Existing File
Here's an example of a run.ts returning a file stored at the skill level and returned as part of a chat dialogue:
const csv = skillContext.powers.andi.storage.currentSkill
.getCSVFileOf("exceptioncontacts.csv")
return skillContext.powers.andi.fileAttachments.conversation
.storeCsvFileForCurrentUser(csv, "Exception Approval Contacts")
.then((response) => {
const exceptionApprovalContactMessage = skillContext.powers.andi.dialogue.composeDialogueTag(
"provide-latest-exception-approval-contact-list",
FieldTagTypes.Info,
"Click here to view the individuals to contact for an exception request.",
[
{
name: "downloadConversationFileAttachment",
args: [response.fileId]
}
]
)
return skillContext.powers.andi.dialogue.sendDialogueResponseWithTags("Exception Approval Contacts", [exceptionApprovalContactMessage])
});