Email Notification Webhook
Try for free
No credit card required
View all Actors
Email Notification Webhook
mnmkng/email-notification-webhook
Try for free
No credit card required
This actor sends you an email notification with a log file when one of your other actors fails, succeeds, times out, you name it.
Dockerfile
1FROM apify/actor-node-basic
2# Copy source code
3COPY . ./
4#COPY src ./src
5RUN npm --quiet set progress=false \
6&& npm install --only=prod --no-optional \
7&& echo "Installed NPM packages:" \
8&& npm list || true \
9&& echo "Node.js version:" \
10&& node --version \
11&& echo "NPM version:" \
12&& npm --version
main.js
1const Apify = require('apify');
2
3const { client, utils: { log } } = Apify;
4
5Apify.main(async () => {
6 log.info('Getting IDs of the calling actor and run.');
7 let {
8 eventData: { actorId, actorRunId },
9 resource: { status },
10 notificationEmail,
11 } = await Apify.getInput();
12
13 log.info('Getting actor\'s identifier.');
14 const { name, username } = await client.acts.getAct({ actId: actorId });
15 const identifier = `${username}/${name}`;
16
17 log.info(`Using run id: ${actorRunId} to download log file.`);
18 const runLog = await client.logs.getLog({ logId: actorRunId });
19
20 if (!notificationEmail) {
21 log.info('Getting email of the calling user.');
22 const { email } = await client.users.getUser();
23 notificationEmail = email;
24 }
25
26 log.info(`Sending email to: ${notificationEmail}`);
27 await Apify.metamorph('e643gqfZae2TfQEbA', { // ID of apify/send-mail
28 to: notificationEmail,
29 subject: `Apify actor ${identifier} ${status}`,
30 html: `<p>Run <strong>${actorRunId}</strong> of the actor <strong>${identifier}</strong>`
31 + ` (${actorId}) finished with status: <strong>${status}</strong>.</p>`
32 + '<p>You can find the run\'s log in the attached file:</p>\n\n',
33 attachments: [{
34 filename: 'log.txt',
35 data: Buffer.from(runLog).toString('base64'),
36 }],
37 }, { build: 'latest' });
38});
package.json
1{
2 "name": "email-notification-webhook",
3 "version": "0.0.1",
4 "description": "This actor sends you an email notification with a log file when one of your other actors fails, succeeds, times out, you name it.",
5 "main": "main.js",
6 "dependencies": {
7 "apify": "latest"
8 },
9 "scripts": {
10 "start": "node main.js"
11 },
12 "author": "mnmkng"
13}
Developer
Maintained by Community
Actor Metrics
2 monthly users
-
5 stars
97% runs succeeded
Created in Mar 2019
Modified 2 years ago
Categories