Skip to main content

Output file from Spell response

You can output a file from a Spell to interact directly with user and propose them to download it.

You have a special object _file that you can return from a Spell:

return {
_file: {
filename: "test.csv" //You can choose here the filename of your file. This filename will be proposed to the user when he will download it
data: new Buffer.from(csv) //data must be a Buffer

Here is a full example of a Spell with output a CSV: (we are using json2csv parser lib to convert a JSON to a CSV)

const someData = [
Firstname: "John",
Lastname: "Doe",
Language: "English",
Age: 31,
Firstname: "Alain",
Lastname: "Terrieur",
Language: "French",
Age: 32,

const json2csvParser = new json2csv.Parser();
const csv = json2csvParser.parse(someData);

return {
_file: {
filename: "people.csv",
data: new Buffer.from(csv),

Here is the output inside the people.csv file: