Commit eb55a4b7 by jay

email api sperto fully functional

1 parent ecaede34
......@@ -47,6 +47,21 @@
},
"thirdPartyApiError": {
"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(
const emailToSend = {
to: ctx.request.body.data.email,
from: undefined,
replyTo: undefined,
subject: `Your one time password is: ${oneTimePassword}`,
from: `contact@hiranandani.net`,
// replyTo: undefined,
subject: `Your Request for One Time Password`,
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
......@@ -131,12 +136,36 @@ module.exports = factories.createCoreController(
},
}
);
ctx.request.body.data = { ...ctx.request.body.data, emailToSend };
// Send an email to the user.
// await strapi.plugin("email").service("email").send(emailToSend).sendOTPToSpreto({...ctx.request.body.data,body: emailToSend });
try {
const spretoOTP = await strapi
.service("api::end-user.end-user")
.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.
if (existingEndUser && existingEndUser.length !== 0) {
......
......@@ -10,7 +10,7 @@ const { createCoreService } = require("@strapi/strapi").factories;
module.exports = createCoreService("api::end-user.end-user",
({ strapi: Strapi }) => ({
async sendLeadToSperto(data) {
console.log(">>>",data);
// console.log(">>>",data);
const headers = { "Content-Type": "application/json" };
const leadData = {
api_key: process.env.SPERTO_API_KEY,
......@@ -47,14 +47,15 @@ module.exports = createCoreService("api::end-user.end-user",
},
async sendOTPToSpreto(data) {
console.log("OTP error", data);
const headers = { "Content-Type": "application/json" };
const otpDetails = {
api_key: process.env.SPERTO_API_KEY,
from_name: data.from_name,
from_mail: data.from_mail,
to: data.to,
subject: data.subject,
body: data.body,
from_name: "Hiranandani",
from_mail: data.emailToSend.from,
to: data.emailToSend.to,
subject: data.emailToSend.subject,
body: data.emailToSend.html,
// lead_category: "W",
// campaign_key: process.env.CAMPAIGN_KEY,
// customer_name: data.fullName,
......@@ -63,14 +64,13 @@ module.exports = createCoreService("api::end-user.end-user",
// email_id1: data.email,
// otp_verified_yn: "N",
};
console.log("OTPDETAILS", otpDetails);
const spertoResponse = await axios.post(
"https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php",
otpDetails,
{ headers: headers }
);
console.log("spertoResponse",spertoResponse);
return spertoResponse;
// return ;
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!