SymphonyPlatformSolutions / symphony-api-client-node

Symphony API Client for NodeJS
MIT License
6 stars 20 forks source link

How to send JSON data as Excel file in message. #61

Closed sandeepreddy792 closed 3 years ago

sandeepreddy792 commented 5 years ago

I have tried to convert JSON to Excel via "json2xls" module and send as excel file.

sample code: var xls = json2xls(portfolios); Symphony.sendMessageWithAttachment( streamId, "Portfolio Excel", null, "portfolioTrades.xlsx", "application/vnd.ms-excel", xls, Symphony.MESSAGEML_FORMAT );

But when I download and open the file from Symphony, it is giving incorrect file format error.

What is the correct way to send data in Excel?

symphony-elias commented 3 years ago

Hello @sandeepreddy792

The following works with symphony-api-client-node version 1.1.2:

const Symphony = require('symphony-api-client-node');
const fs = require('fs');

Symphony.initBot('/path/to/config.json')
  .then((symAuth) => {
    Symphony.sendMessageWithAttachment('streamID',
      'Hello',
      null,
      'spreadhseet.xlsx',
      'application/octet-stream',
      fs.createReadStream('/path/to/spreadsheet.xlsx'),
      Symphony.MESSAGEML_FORMAT);
  });