1const XLSX = require('xlsx');
2const Apify = require('apify');
3const _ = require('underscore');
4const Promise = require('bluebird');
5const request = require('request-promise');
6
7Apify.main(async () => {
8 Apify.setPromisesDependency(Promise);
9 console.log("Start");
10 const attachments = [];
11
12
13 let input = await Apify.getValue('INPUT');
14 let finishWebhookData;
15 console.log(JSON.stringify(input));
16 if(input.data){
17
18 finishWebhookData = JSON.parse(input.data);
19 finishWebhookData._id = input._id
20 }else if(input){
21
22 finishWebhookData = input;
23 }else{
24 throw new Error('Input is missing!');
25 }
26
27 console.log("ID is -> "+ finishWebhookData._id)
28 console.log("Create XLS from json.");
29
30 const run = await Apify.call(
31 'petr_cermak/execution-to-xlsx',
32 {"_id": finishWebhookData._id});
33
34
35 const xlsUrl = run.output.body.output;
36 console.log(JSON.stringify(run));
37
38 const xlsSize = parseFloat(run.output.size);
39 console.log("We have XLS url: "+xlsUrl);
40 console.log("Size of XLS is: "+xlsSize);
41 const runMail = await Apify.call(
42 'apify/send-mail',
43 {to: finishWebhookData.reciever,
44 subject: finishWebhookData.subjectText,
45 text: "Hello, here is the link for XLS result: "+ xlsUrl,
46 attachments: attachments
47 },
48 {});
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82});