Execution ID To XLS Send
Try for free
No credit card required
View all Actors
Execution ID To XLS Send
vaclavrut/executionid-to-xls-and-send
Try for free
No credit card required
This actor takes JSON at input, creates it as XLS from the execution ID result and then sends a link by email. The URL is also outputted in the log. Solves attaching XLS files to emails.
Dockerfile
1# This is a template for a Dockerfile used to run acts in Actor system.
2# The base image name below is set during the act build, based on user settings.
3# IMPORTANT: The base image must set a correct working directory, such as /usr/src/app or /home/user
4FROM apify/actor-node-basic:v0.21.10
5
6# Second, copy just package.json and package-lock.json since it should be
7# the only file that affects "npm install" in the next step, to speed up the build
8COPY package*.json ./
9
10# Install NPM packages, skip optional and development dependencies to
11# keep the image small. Avoid logging too much and print the dependency
12# tree for debugging
13RUN npm --quiet set progress=false \
14 && npm install --only=prod --no-optional \
15 && echo "Installed NPM packages:" \
16 && (npm list --all || true) \
17 && echo "Node.js version:" \
18 && node --version \
19 && echo "NPM version:" \
20 && npm --version
21
22# Copy source code to container
23# Do this in the last step, to have fast build if only the source code changed
24COPY . ./
25
26# NOTE: The CMD is already defined by the base image.
27# Uncomment this for local node inspector debugging:
28# CMD [ "node", "--inspect=0.0.0.0:9229", "main.js" ]
package.json
1{
2 "name": "apify-project",
3 "version": "0.0.1",
4 "description": "",
5 "author": "It's not you it's me",
6 "license": "ISC",
7 "dependencies": {
8 "xlsx": "latest",
9 "apify": "0.21.10",
10 "underscore": "latest",
11 "bluebird": "latest",
12 "request-promise": "latest"
13 },
14 "scripts": {
15 "start": "node main.js"
16 }
17}
main.js
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 // get Act input and validate it
13 let input = await Apify.getValue('INPUT');
14 let finishWebhookData;
15 console.log(JSON.stringify(input));
16 if(input.data){
17 //run from webhook
18 finishWebhookData = JSON.parse(input.data);
19 finishWebhookData._id = input._id
20 }else if(input){
21 //manual run from console
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 //Next step to attach the file if the size is ok
53 if(xlsSize < 10000000){
54 console.log("Creating attachement, size is ok.")
55 var attachement = await request({ url: xlsUrl, encoding: null });
56 attachments.push({
57 filename: `data.xls`,
58 data: attachement,
59 });
60 }else{
61 console.log("We cant send it as attachement, file is too big.")
62 }
63 */
64 /*
65 console.log("Now we can send the mail.");
66 await Apify.setValue('OUTPUT', {output: xlsUrl});
67 const runMail = await Apify.call({
68 actId: 'apify/send-mail',
69 input: {
70 contentType: 'application/json; charset=utf-8',
71 body: JSON.stringify({
72 to: finishWebhookData.reciever,
73 subject: finishWebhookData.subjectText,
74 text: "Hello, here is the link for XLS result: "+ xlsUrl,
75 attachments: attachments
76 })
77
78 }
79 });
80 console.log("Mail sent, done.")
81 */
82});
Developer
Maintained by Community
Actor metrics
- 1 monthly user
- 3 stars
- Created in Sep 2017
- Modified about 2 years ago
Categories