new(basic.gblib): SEND MAIL keyword.
This commit is contained in:
parent
28258a72ea
commit
904ec971e1
3 changed files with 44 additions and 42 deletions
|
@ -44,12 +44,10 @@ import { GBMinService } from '../../core.gbapp/services/GBMinService';
|
|||
import { HubSpotServices } from '../../hubspot.gblib/services/HubSpotServices';
|
||||
import { WhatsappDirectLine } from '../../whatsapp.gblib/services/WhatsappDirectLine';
|
||||
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService';
|
||||
import * as fs from 'fs';
|
||||
const DateDiff = require('date-diff');
|
||||
const puppeteer = require('puppeteer');
|
||||
const Path = require('path');
|
||||
import bb, { area, bar, zoom } from "billboard.js";
|
||||
import * as request from 'request-promise-native';
|
||||
const sgMail = require('@sendgrid/mail');
|
||||
|
||||
/**
|
||||
* Base services of conversation to be called by BASIC which
|
||||
|
@ -515,6 +513,42 @@ export class DialogKeywords {
|
|||
return /\b([0-9]|0[0-9]|1?[0-9]|2[0-3]):[0-5]?[0-9]/.exec(nowText)[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends an e-mail.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* SEND MAIL "email@domain.com", "Subject", "Message text."
|
||||
*
|
||||
*/
|
||||
public async sendEmail(to, subject, body) {
|
||||
|
||||
// tslint:disable-next-line:no-console
|
||||
|
||||
GBLog.info(`[E-mail]: to:${to}, subject: ${subject}, body: ${body}.`);
|
||||
const emailToken = process.env.EMAIL_API_KEY;
|
||||
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
sgMail.setApiKey(emailToken);
|
||||
const msg = {
|
||||
to: to,
|
||||
from: process.env.EMAIL_FROM,
|
||||
subject: subject,
|
||||
text: body,
|
||||
html: body
|
||||
};
|
||||
sgMail.send(msg, false, (err, res) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
}
|
||||
else {
|
||||
resolve(res);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a file to a given mobile.
|
||||
*
|
||||
|
|
|
@ -435,11 +435,11 @@ export class GBVMService extends GBService {
|
|||
});
|
||||
|
||||
code = code.replace(/(send email)(\s*)(.*)/gi, ($0, $1, $2, $3) => {
|
||||
return `sys().sendEmail (${$3})\n`;
|
||||
return `sendEmail (${$3})\n`;
|
||||
});
|
||||
|
||||
code = code.replace(/(send mail)(\s*)(.*)/gi, ($0, $1, $2, $3) => {
|
||||
return `sys().sendEmail (${$3})\n`;
|
||||
return `sendEmail (${$3})\n`;
|
||||
});
|
||||
|
||||
code = code.replace(/(send file to)(\s*)(.*)/gi, ($0, $1, $2, $3) => {
|
||||
|
@ -701,7 +701,10 @@ export class GBVMService extends GBService {
|
|||
code = code.replace(/("[^"]*"|'[^']*')|\bclick\b/gi, ($0, $1) => {
|
||||
return $1 === undefined ? 'this.click' : $1;
|
||||
});
|
||||
// await insertion.
|
||||
code = code.replace(/("[^"]*"|'[^']*')|\bsendEmail\b/gi, ($0, $1) => {
|
||||
return $1 === undefined ? 'this.sendEmail' : $1;
|
||||
});
|
||||
// await insertion.
|
||||
|
||||
code = code.replace(/this\./gm, 'await this.');
|
||||
code = code.replace(/function/gm, 'async function');
|
||||
|
|
|
@ -47,7 +47,6 @@ const urlJoin = require('url-join');
|
|||
const url = require('url');
|
||||
const puppeteer = require('puppeteer')
|
||||
const Path = require('path');
|
||||
const sgMail = require('@sendgrid/mail');
|
||||
const ComputerVisionClient = require('@azure/cognitiveservices-computervision').ComputerVisionClient;
|
||||
const ApiKeyCredentials = require('@azure/ms-rest-js').ApiKeyCredentials;
|
||||
const alasql = require('alasql');
|
||||
|
@ -888,7 +887,7 @@ export class SystemKeywords {
|
|||
}
|
||||
row[propertyName] = value;
|
||||
}
|
||||
row['line'] = rowCount + 1;
|
||||
row['line'] = rowCount;
|
||||
row['originalLine'] = foundIndex + 1;
|
||||
table.push(row);
|
||||
}
|
||||
|
@ -1265,40 +1264,6 @@ export class SystemKeywords {
|
|||
return GBAdminService.getRndPassword();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an e-mail.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* SEND MAIL "email@domain.com", "Subject", "Message text."
|
||||
*
|
||||
*/
|
||||
public async sendEmail(to, subject, body) {
|
||||
|
||||
// tslint:disable-next-line:no-console
|
||||
|
||||
GBLog.info(`[E-mail]: to:${to}, subject: ${subject}, body: ${body}.`);
|
||||
const emailToken = process.env.EMAIL_API_KEY;
|
||||
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
sgMail.setApiKey(emailToken);
|
||||
const msg = {
|
||||
to: to,
|
||||
from: process.env.EMAIL_FROM,
|
||||
subject: subject,
|
||||
text: body,
|
||||
html: body
|
||||
};
|
||||
sgMail.send(msg, false, (err, res) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
}
|
||||
else {
|
||||
resolve(res);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls any REST API by using GET HTTP method.
|
||||
|
|
Loading…
Add table
Reference in a new issue