Commit eb55a4b7 by jay

email api sperto fully functional

1 parent ecaede34
...@@ -47,6 +47,21 @@ ...@@ -47,6 +47,21 @@
}, },
"thirdPartyApiError": { "thirdPartyApiError": {
"type": "boolean" "type": "boolean"
},
"httpsRequestEmailBody": {
"type": "text"
},
"httpRequestEmailHeaders": {
"type": "text"
},
"httpRequestEmailUrl": {
"type": "text"
},
"httpRequestEmailMethod": {
"type": "text"
},
"httpResposneEmailBody": {
"type": "text"
} }
} }
} }
...@@ -113,11 +113,16 @@ module.exports = factories.createCoreController( ...@@ -113,11 +113,16 @@ module.exports = factories.createCoreController(
const emailToSend = { const emailToSend = {
to: ctx.request.body.data.email, to: ctx.request.body.data.email,
from: undefined, from: `contact@hiranandani.net`,
replyTo: undefined, // replyTo: undefined,
subject: `Your one time password is: ${oneTimePassword}`, subject: `Your Request for One Time Password`,
text: `Hello ${"Jay Mehta"}, Your one time password to login to your end user portal is ${oneTimePassword}`, text: `Hello ${"Jay Mehta"}, Your one time password to login to your end user portal is ${oneTimePassword}`,
html: `<p>Hello ${"Jay Mehta"}, <br></br>Your one time password to login to your end user portal is ${oneTimePassword}</p><br /> Best Regards, <br /> Team Hiranandani.`, html: `<p>Dear ${ctx.request.body.data.fullName},
Your OTP for Hiranandani Exclusive website login is <strong>${oneTimePassword}</strong> . Valid for 10 minutes. Please do not
share this OTP.
Regards,
Hiranandani Team.`,
}; };
// NOTE: Update the user before sending the email so an Admin can generate the link if the email fails // NOTE: Update the user before sending the email so an Admin can generate the link if the email fails
...@@ -131,12 +136,36 @@ module.exports = factories.createCoreController( ...@@ -131,12 +136,36 @@ module.exports = factories.createCoreController(
}, },
} }
); );
ctx.request.body.data = { ...ctx.request.body.data, emailToSend };
// Send an email to the user. // Send an email to the user.
// await strapi.plugin("email").service("email").send(emailToSend).sendOTPToSpreto({...ctx.request.body.data,body: emailToSend }); // await strapi.plugin("email").service("email").send(emailToSend).sendOTPToSpreto({...ctx.request.body.data,body: emailToSend });
try {
const spretoOTP = await strapi const spretoOTP = await strapi
.service("api::end-user.end-user") .service("api::end-user.end-user")
.sendOTPToSpreto(ctx.request.body.data); .sendOTPToSpreto(ctx.request.body.data);
ctx.request.body.data.httpRequestEmailHeaders = JSON.stringify(
spretoOTP.headers
);
ctx.request.body.data.httpRequestEmailMethod = spretoOTP.config.method;
ctx.request.body.data.httpRequestEmailUrl = spretoOTP.config.url;
ctx.request.body.data.httpsRequestEmailBody = spretoOTP.config.data;
ctx.request.body.data.httpResposneEmailBody = JSON.stringify(
spretoOTP.data
);
ctx.request.body.data.thirdPartyApiError = false;
} catch (error) {
ctx.request.body.data.httpRequestEmailHeaders = JSON.stringify(
error.config.headers
);
ctx.request.body.data.httpRequestEmailMethod = error.config.method;
ctx.request.body.data.httpRequestEmailUrl = error.config.url;
ctx.request.body.data.httpsRequestEmailBody = error.config.data;
ctx.request.body.data.httpResposneEmailBody = JSON.stringify(
error.message
);
ctx.request.body.data.thirdPartyApiError = true;
}
// TODO: Send SMS. // TODO: Send SMS.
if (existingEndUser && existingEndUser.length !== 0) { if (existingEndUser && existingEndUser.length !== 0) {
......
...@@ -10,7 +10,7 @@ const { createCoreService } = require("@strapi/strapi").factories; ...@@ -10,7 +10,7 @@ const { createCoreService } = require("@strapi/strapi").factories;
module.exports = createCoreService("api::end-user.end-user", module.exports = createCoreService("api::end-user.end-user",
({ strapi: Strapi }) => ({ ({ strapi: Strapi }) => ({
async sendLeadToSperto(data) { async sendLeadToSperto(data) {
console.log(">>>",data); // console.log(">>>",data);
const headers = { "Content-Type": "application/json" }; const headers = { "Content-Type": "application/json" };
const leadData = { const leadData = {
api_key: process.env.SPERTO_API_KEY, api_key: process.env.SPERTO_API_KEY,
...@@ -47,14 +47,15 @@ module.exports = createCoreService("api::end-user.end-user", ...@@ -47,14 +47,15 @@ module.exports = createCoreService("api::end-user.end-user",
}, },
async sendOTPToSpreto(data) { async sendOTPToSpreto(data) {
console.log("OTP error", data);
const headers = { "Content-Type": "application/json" }; const headers = { "Content-Type": "application/json" };
const otpDetails = { const otpDetails = {
api_key: process.env.SPERTO_API_KEY, api_key: process.env.SPERTO_API_KEY,
from_name: data.from_name, from_name: "Hiranandani",
from_mail: data.from_mail, from_mail: data.emailToSend.from,
to: data.to, to: data.emailToSend.to,
subject: data.subject, subject: data.emailToSend.subject,
body: data.body, body: data.emailToSend.html,
// lead_category: "W", // lead_category: "W",
// campaign_key: process.env.CAMPAIGN_KEY, // campaign_key: process.env.CAMPAIGN_KEY,
// customer_name: data.fullName, // customer_name: data.fullName,
...@@ -63,14 +64,13 @@ module.exports = createCoreService("api::end-user.end-user", ...@@ -63,14 +64,13 @@ module.exports = createCoreService("api::end-user.end-user",
// email_id1: data.email, // email_id1: data.email,
// otp_verified_yn: "N", // otp_verified_yn: "N",
}; };
console.log("OTPDETAILS", otpDetails);
const spertoResponse = await axios.post( const spertoResponse = await axios.post(
"https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php", "https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php",
otpDetails, otpDetails,
{ headers: headers } { headers: headers }
); );
console.log("spertoResponse",spertoResponse);
return spertoResponse; return spertoResponse;
// return ; // return ;
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!