-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hai Liang Wang
committed
Oct 8, 2022
1 parent
7171645
commit d0d1195
Showing
9 changed files
with
218 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,7 @@ | |
const debug = require("debug")("sync:ctrl:w3"); | ||
const utils = require("../utils/index"); | ||
const feishuService = require("../services/feishu.service"); | ||
|
||
|
||
const mailService = require("../services/email.service"); | ||
|
||
function Controller() { | ||
|
||
|
@@ -19,66 +18,79 @@ function Controller() { | |
* @param {*} body | ||
*/ | ||
Controller.prototype.handleW3broadcast = async function (headers, params, body) { | ||
let ret = { "msg": "done" }; | ||
/** | ||
* sync:routes:w3 /broadcast ctx.params {} , body | ||
let ret = { "msg": "done" }; | ||
/** | ||
* sync:routes:w3 /broadcast ctx.params {} , body | ||
{ | ||
"link": "https://www.cskefu.com/2022/10/08/test-c/", | ||
"post_title": "Test C", | ||
"author_id": "99", | ||
"display_name": "Hai", | ||
"user_email": "[email protected]", | ||
"user_profile": "https://www.cskefu.com/user/99/", | ||
"categories": [ | ||
{ | ||
"term_id": 118, | ||
"name": "业务观点", | ||
"slug": "business", | ||
"term_group": 0, | ||
"term_taxonomy_id": 118, | ||
"taxonomy": "category", | ||
"description": "业务、产品及服务的应用和解决方案:呼叫中心、联络中心、智能客服、客服机器人、CTI、云计算等。有价值的干货:应用场景、业务价 | ||
"link": "https://www.cskefu.com/2022/10/08/test-c/", | ||
"post_title": "Test C", | ||
"author_id": "99", | ||
"display_name": "Hai", | ||
"user_email": "[email protected]", | ||
"user_profile": "https://www.cskefu.com/user/99/", | ||
"categories": [ | ||
{ | ||
"term_id": 118, | ||
"name": "业务观点", | ||
"slug": "business", | ||
"term_group": 0, | ||
"term_taxonomy_id": 118, | ||
"taxonomy": "category", | ||
"description": "业务、产品及服务的应用和解决方案:呼叫中心、联络中心、智能客服、客服机器人、CTI、云计算等。有价值的干货:应用场景、业务价 | ||
值、创新方案。", | ||
"parent": 0, | ||
"count": 12, | ||
"filter": "raw", | ||
"cat_ID": 118, | ||
"category_count": 12, | ||
"category_description": "业务、产品及服务的应用和解决方案:呼叫中心、联络中心、智能客服、客服机器人、CTI、云计算等。有价值的干货:应用场 | ||
"parent": 0, | ||
"count": 12, | ||
"filter": "raw", | ||
"cat_ID": 118, | ||
"category_count": 12, | ||
"category_description": "业务、产品及服务的应用和解决方案:呼叫中心、联络中心、智能客服、客服机器人、CTI、云计算等。有价值的干货:应用场 | ||
景、业务价值、创新方案。", | ||
"cat_name": "业务观点", | ||
"category_nicename": "business", | ||
"category_parent": 0 | ||
}, | ||
{ | ||
"term_id": 145, | ||
"name": "产品专栏", | ||
"slug": "product", | ||
"term_group": 0, | ||
"term_taxonomy_id": 145, | ||
"taxonomy": "category", | ||
"description": "产品理念、产品设计、产品构想等;主要由春松客服产品经理或产品办公室发布。", | ||
"parent": 0, | ||
"count": 2, | ||
"filter": "raw", | ||
"cat_ID": 145, | ||
"category_count": 2, | ||
"category_description": "产品理念、产品设计、产品构想等;主要由春松客服产品经理或产品办公室发布。", | ||
"cat_name": "产品专栏", | ||
"category_nicename": "product", | ||
"category_parent": 0 | ||
} | ||
] | ||
"cat_name": "业务观点", | ||
"category_nicename": "business", | ||
"category_parent": 0 | ||
}, | ||
{ | ||
"term_id": 145, | ||
"name": "产品专栏", | ||
"slug": "product", | ||
"term_group": 0, | ||
"term_taxonomy_id": 145, | ||
"taxonomy": "category", | ||
"description": "产品理念、产品设计、产品构想等;主要由春松客服产品经理或产品办公室发布。", | ||
"parent": 0, | ||
"count": 2, | ||
"filter": "raw", | ||
"cat_ID": 145, | ||
"category_count": 2, | ||
"category_description": "产品理念、产品设计、产品构想等;主要由春松客服产品经理或产品办公室发布。", | ||
"cat_name": "产品专栏", | ||
"category_nicename": "product", | ||
"category_parent": 0, | ||
"content": "Formatted HTML, https://www.kevinleary.net/get-wordpress-post-content-by-post-id/" | ||
} | ||
] | ||
} | ||
*/ | ||
utils.writeTmpOutputFileOnDevelopment(body); | ||
*/ | ||
utils.writeTmpOutputFileOnDevelopment(body); | ||
|
||
// 发送 W3 文章通知到飞书群 | ||
// 发送 W3 文章通知到飞书群 | ||
try { | ||
await feishuService.sendW3BroadcastNotification(body); | ||
} catch (e) { | ||
console.log("[Error] feishuService.sendW3BroadcastNotification") | ||
console.error(e); | ||
} | ||
|
||
// 发送 W3 文章通知到邮件列表服务 | ||
try { | ||
await mailService.sendW3BroadcastMaillists(body); | ||
} catch (e) { | ||
console.log("[Error] mailService.sendW3BroadcastMaillists") | ||
console.error(e); | ||
} | ||
|
||
debug("[handleW3broadcast] ret", JSON.stringify(ret)) | ||
return ret; | ||
debug("[handleW3broadcast] ret", JSON.stringify(ret)) | ||
return ret; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* Send Emails | ||
*/ | ||
|
||
|
||
const debug = require("debug")("sync:services:email"); | ||
const nodemailer = require('nodemailer'); | ||
const smtpTransport = require('nodemailer-smtp-transport'); | ||
const utils = require("../utils/index"); | ||
|
||
const SMTP_HOST = process.env["SMTP_HOST"]; | ||
const SMTP_PORT = process.env["SMTP_PORT"]; | ||
const SMTP_SSL = process.env["SMTP_SSL"]; | ||
const SMTP_USER_FROM = process.env["SMTP_USER_FROM"]; | ||
const SMTP_USER_NAME = process.env["SMTP_USER_NAME"]; | ||
const SMTP_USER_PASS = process.env["SMTP_USER_PASS"]; | ||
const MAIL_W3_EVENTS_CC = process.env["MAIL_W3_EVENTS_CC"]; | ||
const MAIL_W3_EVENTS_BCC = process.env["MAIL_W3_EVENTS_BCC"]; | ||
const BRAND_SUFFIX = process.env["BRAND_SUFFIX"] || "春松客服 W3"; | ||
|
||
const transport = nodemailer.createTransport(smtpTransport({ | ||
host: SMTP_HOST, // 服务 | ||
port: SMTP_PORT, // smtp端口 | ||
secure: SMTP_SSL, | ||
auth: { | ||
user: SMTP_USER_FROM, // 用户名 | ||
pass: SMTP_USER_PASS // SMTP授权码 | ||
} | ||
})); | ||
|
||
/** | ||
* Send Mail | ||
* @param {*} options | ||
* @returns | ||
*/ | ||
function send(options) { | ||
debug("[send] %j", options) | ||
|
||
return new Promise((resolve, reject) => { | ||
transport.sendMail({ | ||
from: `${SMTP_USER_NAME}<${SMTP_USER_FROM}>`, // 发件邮箱 | ||
to: options.to, // 收件列表 | ||
bcc: options.bcc, // 收件列表 | ||
subject: options.subject, // 标题 | ||
html: options.html, | ||
attachments: options.attachment ? [{ path: options.attachment }] : null, | ||
}, | ||
(error, data) => { | ||
if (error) return reject(error) | ||
resolve(data) | ||
}) | ||
}) | ||
|
||
} | ||
|
||
/** | ||
* 发送 W3 服务通知 | ||
* @param {*} payload | ||
*/ | ||
async function sendW3BroadcastMaillists(payload) { | ||
|
||
if (!MAIL_W3_EVENTS_CC) { | ||
debug("[sendW3BroadcastMaillists] not set ENV MAIL_W3_EVENTS_CC, bypass broadcast."); | ||
return; | ||
} | ||
|
||
await send({ | ||
to: MAIL_W3_EVENTS_CC, | ||
bcc: MAIL_W3_EVENTS_BCC, | ||
subject: utils.capitalizeFirstLetter(utils.getW3PostCategories(payload) + " - ") + payload.display_name + " - " + payload.post_title + " | " + BRAND_SUFFIX, | ||
html: ` LINK: ${payload.link} <br /> | ||
AUTHOR: ${payload.display_name}(${payload.user_email}) <br /> | ||
PROFILE: ${payload.user_profile} <br /> | ||
<br /> | ||
CONTENT: <br /> | ||
${payload.content} <br /> | ||
<br /> | ||
<br /> | ||
` | ||
}) | ||
} | ||
|
||
exports = module.exports = { | ||
send, | ||
sendW3BroadcastMaillists | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters