Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as nodemailer from 'nodemailer';
- import * as passport from 'koa-passport';
- import * as Router from 'koa-router';
- import * as Pipedrive from 'pipedrive';
- import { STATUS_CODES } from 'http';
- import { InvalidParameters } from './auth/errors';
- import { countBy, find, propEq, indexBy, prop } from 'ramda';
- import { getFiltered, getAll } from './pipeDrives';
- const reMap = {
- "deals": "pipeline",
- "people": "persons"
- }
- const from = "PipeDriveAMS@viableone.cz";
- const htmlEmail = (count, url) =>( `<img src="https://image.ibb.co/g48o3c/pipedrive1.png" style="width:100%"/><br />
- <h3>PIPEDRIVE DATA need your action</h3><br/> <br/> There are ${count} items that require your update in PIPEDRIVE <br /> <br />
- ${url} <br /><br />Automatic Mail Robot for PIPEDRIVE made in V1`
- )
- const createUrl = (type, id) => `https://directpeople.pipedrive.com/${reMap[type]}/filter/${id}`
- const transporter = nodemailer.createTransport({
- host: 'email-smtp.eu-west-1.amazonaws.com',
- port: 465,
- secure: true,
- auth: {
- user: 'AKIAICUMWZ5GBOJETY4A',
- pass: 'AhfLkkXlJX17GK6ernJFlXiQ4XrQVzo931Idj97b2hSS',
- }
- });
- const sendEmail = async (ids, emails, url) => {
- Object.keys(ids).map((item, index) => {
- let mailOptions = {
- from, // sender address
- to: 'uragecz@gmail.com, otto.kalivoda@viableone.cz, frunz@viableone.cz', // list of receivers
- subject: emails[item].email, // Subject line
- html: htmlEmail(ids[item], url) // html body
- };
- transporter.sendMail(mailOptions, (error, info) => {
- if (error) {
- return console.log(error);
- }
- console.log('Message sent: %s', info.messageId);
- console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
- });
- })
- }
- const router = new Router();
- // get entities
- router.get('send', async ctx => {
- const { pipedrive } = ctx.state.authInfo;
- const { filterId, type } = ctx.query;
- const body = await getFiltered(pipedrive, type, filterId);
- const names : any = await getAll(pipedrive, "Users", null)
- const emails = [];
- const countArr = countBy(person => body[person].owner_name, Object.keys(body));
- const nameIndex = indexBy(prop("name"), names);
- const url = createUrl(type, filterId);
- sendEmail(countArr, nameIndex, url );
- ctx.body = countArr;
- ctx.status = 200;
- });
- export default router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement