@@ -8,7 +8,9 @@ import { config } from '../config';
88import Telegraf , { Context } from 'telegraf' ;
99import { Feed , FeedItem } from '../types/feed' ;
1010import { getUserById , migrateUser } from '../proxies/users' ;
11- import { isNone } from '../types/option' ;
11+ import { isNone , isSome } from '../types/option' ;
12+ import * as ejs from 'ejs' ;
13+ import i18n from '../i18n' ;
1214
1315/**
1416 * handle send error log or delete user or migrate user
@@ -47,9 +49,16 @@ const send = async (
4749) : Promise < void > => {
4850 const subscribers = await getSubscribersByFeedId ( feed . feed_id ) ;
4951 if ( typeof toSend === 'string' ) {
52+ const tpl = toSend ;
5053 subscribers . map ( async ( subscribe ) => {
5154 const userId = subscribe . user_id ;
5255 try {
56+ const user = await getUserById ( userId ) ;
57+ let lang = config . lang ;
58+ if ( isSome ( user ) ) {
59+ lang = user . value . lang ;
60+ }
61+ toSend = ejs . render ( tpl , { i18n : i18n [ lang ] } ) ;
5362 await bot . telegram . sendMessage ( userId , toSend , {
5463 parse_mode : 'HTML' ,
5564 disable_web_page_preview : true
@@ -59,10 +68,11 @@ const send = async (
5968 }
6069 } ) ;
6170 } else {
71+ const feedItems = toSend ;
6272 subscribers . map ( async ( subscribe ) => {
6373 const userId = subscribe . user_id ;
6474 let text = `<b>${ sanitize ( feed . feed_title ) } </b>` ;
65- toSend . forEach ( function ( item ) {
75+ feedItems . forEach ( function ( item ) {
6676 text += `\n<a href="${ item . link . trim ( ) } ">${ sanitize (
6777 item . title
6878 ) } </a>`;
0 commit comments