This commit is contained in:
NAME
2026-05-23 06:27:07 +00:00
parent 60dd0730f0
commit 83553be5b3
35 changed files with 763 additions and 126 deletions
@@ -29,38 +29,15 @@ export class TelegramContentWriterCompletedProcessor extends WorkerHost {
console.log('TelegramProcessor_facebook_content_writer_completed_process=>posting')
//console.log(fbContent);
if (job.name === 'generate_post_completed') {
const {id, needConfirm, content, autoPublish, telegramChatId, xSubmitProvider} = job.data;
const {
id, needConfirm, content, autoPublish, telegramChatId, xSubmitProvider,
contentTransVi,
contentTransModel,
} = job.data;
console.log({id, needConfirm, autoPublish, xSubmitProvider})
const X_USERS = process.env.TWITTER_USERNAMES!.split(',');
console.log({X_USERS});
//console.log({job})
// if (autoPublish) {
// // await this.publishPageService.publishTwitter(id);
// // await this.publishPageService.publishToFacebook(id);
// const postId = toNumber(id);
// await this.bot.telegram.sendMessage(adminChatId, '🤖Đã viết xong tin auto:');
//
// try {
// await Promise.allSettled([
// this.publishPageService.publishToFacebook(postId).then(() => {
// this.bot.telegram.sendMessage(adminChatId, `Đăng bài lên FB số ${postId} thành công`);
// }).catch(err => {
// this.bot.telegram.sendMessage(adminChatId, `PublishToFacebook error ${err.message}`);
//
// }),
// this.publishPageService.publishTwitter(postId, xSubmitProvider).then((resp) => {
// this.bot.telegram.sendMessage(adminChatId, `Đăng bài lên X số ${postId} thành công via ${xSubmitProvider}, ${resp?.url}`);
// }).catch(err => {
// this.bot.telegram.sendMessage(adminChatId, `PublishToX error ${err.message}`);
// }),
// ]
// )
// } catch (e) {
// await this.bot.telegram.sendMessage(adminChatId, `❌ Lỗi đăng bài: ${e.message}`);
// }
// return;
// }
await this.bot.telegram.sendMessage(telegramChatId || adminChatId, '🤖Đã viết xong:');
await this.bot.telegram.sendMessage(telegramChatId || adminChatId, `🤖Đã viết xong: Dich: ${contentTransVi}`);
await this.bot.telegram.sendMessage(telegramChatId || adminChatId,
`${content}\n\n`,
{
+1 -1
View File
@@ -38,7 +38,7 @@ import {SqsPostService} from "../sqs-module/sqs.post.service";
QuoteWizard,
Comment2Wizard,
XImageUploadService,
SqsPostService
SqsPostService,
],
})
export class TelegramModule implements OnModuleInit{
+160 -21
View File
@@ -1,4 +1,4 @@
import {Action, Command, Ctx, On, Start, Update} from 'nestjs-telegraf';
import {Action, Command, Ctx, Hears, Message, On, Start, Update} from 'nestjs-telegraf';
import {Context, Scenes} from 'telegraf';
import {HttpException, Injectable} from "@nestjs/common";
import {ManagerService} from "../manager/manager.service";
@@ -18,6 +18,8 @@ import {TextUtil} from "../../common/utils/text.util";
import {XStrategy} from "../social-api/x-router.service";
import {XCacheService} from "../x-cache/x-cache.service";
import {SqsPostService} from "../sqs-module/sqs.post.service";
import {PgPostService} from "../../shared/pg.post.service";
import {Language} from "../../common/interfaces/language.prompt.interface";
@Injectable()
@Update()
@@ -30,7 +32,8 @@ export class TelegramUpdates {
private readonly trendsService: TrendsService,
private readonly xUpload: XImageUploadService,
private readonly cacheService: XCacheService,
private readonly sqsPostService: SqsPostService
private readonly sqsPostService: SqsPostService,
private readonly pgPost: PgPostService,
) {
}
@@ -110,14 +113,79 @@ export class TelegramUpdates {
async onWizardCommand(@Ctx() ctx: Scenes.SceneContext): Promise<void> {
await ctx.scene.enter(WIZARD_COMMENT_SCENE_ID);
}
@Command('chatid')
async onGetChatId(ctx: Context) {
// @ts-ignore
ctx.reply(ctx.chat.id)
}
@Command('atc')
async onAutoCommentCommand(@Ctx() ctx: Context): Promise<void> {
//@ts-ignore
let {command, payload} = ctx;
if (!payload) {
await ctx.reply(`vui lòng đưa topic, ví dụ: /${command} LinkX`);
return;
}
await this.sharedAutoComment(ctx, payload);
}
@Action('action_auto_comment')
async onDownloadAction(@Ctx() ctx: Context) {
await ctx.answerCbQuery(); // Tắt trạng thái loading trên nút bấm
// Ép kiểu để ép TypeScript nhận diện đúng đối tượng tin nhắn chữ
// @ts-ignore
const message = ctx.callbackQuery.message as any;
// 💡 LẤY ĐƯỢC LUÔN: Đây chính là nội dung text của tin nhắn chứa nút bấm này!
const textInMessage = message.text;
// await ctx.reply(`Tôi đọc được chữ từ tin nhắn cũ: ${textInMessage}`);
await this.sharedAutoComment(ctx, textInMessage);
}
private async sharedAutoComment(ctx: Context, linkX:string): Promise<void> {
// console.log(ctx);
// @ts-ignore
if (!linkX) {
await ctx.reply(`Thiếu LinkX`);
return;
}
const detectSendLinkX = TextUtil.detectLinkX(linkX);
if (detectSendLinkX.hasLinkX) {
// @ts-ignore
linkX = detectSendLinkX.url;
} else {
await ctx.reply('Không có link X');
return;
}
const chatId = ctx.chat?.id;
await this.managerService.triggerAutoGenerateCommentTwitter(
linkX,
'realflashkaze',
'en',
chatId,
);
await ctx.reply('Chờ xử lý ...');
}
@Command([
'comvi',
'cvi',
'cvil',
'comen',
'cen',
'comja',
'cja',
'comjal',
'cjal',
'comko',
'cko',
'comcn',
'ccn',
])
async onCommentAsTextCommand(@Ctx() ctx: Scenes.SceneContext): Promise<void> {
@@ -125,16 +193,19 @@ export class TelegramUpdates {
let xpostreader = 'api'
// @ts-ignore
let {command, payload} = ctx;
if (['comvi', 'comvn', 'com_vi'].includes(command)) {
if (['cvi', 'cvil', 'comvi', 'comvn', 'com_vi'].includes(command)) {
language = 'vi';
if (['cvil', 'comvil'].includes(command)) {
xpostreader = 'browser'
}
}
if (['comko', 'comkr', 'com_ko'].includes(command)) {
language = 'ko';
}
if (['comja', 'com_ja',].includes(command)) {
if (['comja', 'com_ja', 'cja', 'cjal'].includes(command)) {
language = 'ja';
}
if (['comjal', 'comjalong' ].includes(command)) {
if (['comjal', 'comjalong', 'cjal'].includes(command)) {
language = 'ja';
xpostreader = 'browser';
}
@@ -155,7 +226,7 @@ export class TelegramUpdates {
const match = _linkX.match(/status\/(\d+)/);
if (match) {
//nêu match => get content x
const xpost = await this.xReaderService.readXPost(_linkX, xpostreader, chatId);
const xpost: any = await this.xReaderService.readXPost(_linkX, xpostreader, chatId);
console.log('==> content text:' + xpost.text);
payload = xpost.text;
tweetId = xpost.tweetId;
@@ -176,11 +247,15 @@ export class TelegramUpdates {
'quote_vi',
'quotevi',
'quotevn',
'quotevnl',
'qvnl',
'quote_en',
'quoteen',
'quote_ja',
'quoteja',
'quotejal',
'qjal',
'qja',
'quote_jp',
'quotejp',
'quote_ko',
@@ -191,15 +266,17 @@ export class TelegramUpdates {
// @ts-ignore
let {command, payload} = ctx;
let xreaderMode = 'api';
if(['quotejal'].includes(command)) {
command = 'quote_ja';
xreaderMode='browser';
if (['quotevnl', 'qvnl', 'quotejal', 'qjal'].includes(command)) {
xreaderMode = 'browser';
}
if (['quote_jp', 'quotejp', 'quoteja'].includes(command)) {
if (['quote_jp', 'quotejp', 'quoteja', 'qja', 'quotejal'].includes(command)) {
command = 'quote_ja';
}
if (['quote_vn', 'quotevi', 'quotevn'].includes(command)) {
if (['quote_vn', 'quotevi', 'quotevn', 'quotevnl', 'qvnl'].includes(command)) {
command = 'quote_vi';
}
if (['quoteen'].includes(command)) {
command = 'quote_en';
@@ -329,8 +406,13 @@ export class TelegramUpdates {
const detectSendLinkX = TextUtil.detectLinkX(payload);
if (detectSendLinkX.hasLinkX) {
const xpost = await this.xReaderService.readXPost(detectSendLinkX.url);
// @ts-ignore
payload = xpost.text;
}
if (!payload) {
await ctx.reply(`reader không được`);
return;
}
}
await ctx.scene.enter(WIZARD_WRITER_SCENE_ID, {
@@ -354,8 +436,13 @@ export class TelegramUpdates {
const postNo = 1 * payload;
await ctx.reply(`Đang đẩy bài ${payload} lên Facebook, Twitter`);
const post = await this.pgPost.getById(postNo);
if (!post) {
await ctx.reply('No found');
return;
}
await ctx.reply(
`🤖 **Vui lòng chọn kênh**`,
post.content!,
{
parse_mode: 'Markdown',
reply_markup: {
@@ -429,6 +516,45 @@ export class TelegramUpdates {
await ctx.reply(`vui lòng đưa chờ phân tích ....`);
}
@Command(['tvi', 'tja', 'ten', 'tko', 'tcn'])
async onTranslator(ctx: Context) {
// @ts-ignore
const {command, payload} = ctx;
let lang: Language = 'vi'
switch (command) {
case 'tvi': {
lang = 'vi';
break;
}
case 'tja': {
lang = 'ja';
break;
}
case 'ten': {
lang = 'en';
break;
}
case 'tko': {
lang = 'ko';
break;
}
case 'tcn': {
lang = 'cn';
break;
}
}
if (!payload) {
await ctx.reply(`vui lòng đưa text, ví dụ: /${command} Hot news today in japan ?`);
return;
}
console.log(ctx.chat);
await this.managerService.handleTranslatorText(payload, lang, ctx.chat?.id);
await ctx.reply(`vui lòng chờ ....`);
}
@Command(['xreader', 'xrbr'])
async onXReader(ctx: Context) {
// @ts-ignore
@@ -441,7 +567,7 @@ export class TelegramUpdates {
const content = await this.xReaderService.readXPost(
payload,
['xreader_browser','xrbr'].includes(command) ? 'browser' : 'any'
['xreader_browser', 'xrbr'].includes(command) ? 'browser' : 'any'
).catch((err) => {
ctx.reply(err.message);
return err;
@@ -483,7 +609,7 @@ export class TelegramUpdates {
const callbackData = (ctx.callbackQuery as any).data;
const social = callbackData.split('_')[1];
const postId = _toNum(callbackData.split('_')[2]);
const xUsername = callbackData.split('_')[3];
let xUsername = callbackData.split('_')[3];
await ctx.answerCbQuery(`Đang đẩy bài lên Fb,X ${xUsername}...`);
@@ -501,7 +627,7 @@ export class TelegramUpdates {
case 'twitter':
allowTw = 1;
publishTo = ['x'];
twStrageryPost=XStrategy.BROWSER_FIRST
twStrageryPost = XStrategy.BROWSER_FIRST
break;
case 'twitterbrowser':
allowTw = 1;
@@ -511,6 +637,7 @@ export class TelegramUpdates {
case 'facebook':
allowFb = 1;
publishTo = ['fb'];
xUsername = 'realflashkaze';
break;
}
@@ -682,8 +809,8 @@ export class TelegramUpdates {
)
// const r = await this.publishPageService.relyX(messageText, tweetId)
//@ts-ignore
await ctx.editMessageText(`✅ ** Đã gửi tin sang queue ${xUsername} ID bài viết: ${tweetId}`);
// await ctx.reply(`✅ Đã gửi tin sang queue ${xUsername}!, ID bài viết: ${tweetId}`);
await ctx.editMessageText(`✅ ** Đã gửi tin sang queue ${xUsername} ID bài viết: ${tweetId}`);
// await ctx.reply(`✅ Đã gửi tin sang queue ${xUsername}!, ID bài viết: ${tweetId}`);
// else {
// //@ts-ignore
// await ctx.reply(`❌ Lỗi reply: ${r.error} `);
@@ -818,9 +945,21 @@ export class TelegramUpdates {
}
}
@Command('chatid')
async onGetChatId(ctx: Context) {
// @ts-ignore
ctx.reply(ctx.chat.id)
// Pattern này sẽ bắt tất cả các link dạng ://x.com... hoặc ://twitter.com...
@Hears(/https?:\/\/(www\.)?(x\.com|twitter\.com)\/[a-zA-DR-Z0-9_]+/i)
async handleXLink(@Ctx() ctx: Context, @Message('text') text: string) {
// text ở đây chính là toàn bộ đoạn tin nhắn chứa link x.com
// Ví dụ xử lý: Trích xuất phần ID hoặc convert link để preview (như fixupx.com)
// const fixedLink = text.replace(/x\.com|twitter\.com/i, 'fixupx.com');
await ctx.reply(text, {
reply_markup: {
inline_keyboard: [
[{ text: '📥 Chạy lệnh auto cmt', callback_data: 'action_auto_comment' }]
]
}
});
//return `Tôi đã tìm thấy link X! Đây là bản preview: ${fixedLink}`;
}
}