@@ -2,6 +2,7 @@ import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
22import { ethers } from 'ethers' ;
33import html2md from 'html-to-md' ;
44import { LRUCache } from 'lru-cache' ;
5+ import { customAlphabet } from 'nanoid' ;
56import TelegramBot , {
67 ChatMemberUpdated ,
78 ParseMode ,
@@ -10,9 +11,11 @@ import { LessThanOrEqual, MoreThanOrEqual } from 'typeorm';
1011
1112import { NetworkDto } from 'src/common/dto' ;
1213import configFactory from 'src/config' ;
14+ import { ScSession } from 'src/entities/scSession.entity' ;
1315import { TgGroupAndChannel } from 'src/entities/tgGroupAndChannel.entity' ;
1416import { BusinessException } from 'src/exception/business.exception' ;
1517import {
18+ ScSessionRepository ,
1619 TgGroupAndChannelRepository ,
1720 TgMessageRepository ,
1821} from 'src/repositories' ;
@@ -41,6 +44,7 @@ export class FlashNewsBotService implements OnModuleInit {
4144 private readonly coingeckoService : CoingeckoService ,
4245 private readonly tgMessageRepository : TgMessageRepository ,
4346 private readonly tgGroupAndChannelRepository : TgGroupAndChannelRepository ,
47+ private readonly scSessionRepository : ScSessionRepository ,
4448 ) { }
4549
4650 async update ( body : any ) {
@@ -580,7 +584,9 @@ ${this.formatMarkdownV2(content).replaceAll(
580584 fromTokenAddress : string ,
581585 toTokenAddress : string ,
582586 settings : Settings ,
587+ sc ?: string ,
583588 ) {
589+ let shareText = '' ;
584590 const config = await configFactory ( ) ;
585591 const userMiniApp = config . tgbot . userMiniApp ;
586592 const newsChannelIdCn = config . tgbot . newsChannelIdCn ;
@@ -617,6 +623,11 @@ ${this.formatMarkdownV2(content).replaceAll(
617623 let linkIndex = 0 ;
618624 let lang = 'cn' ;
619625 if ( this . containsChineseCharacters ( content ) ) {
626+ shareText = sc
627+ ? sc
628+ : `嘿😎,这是可以自定义你一键操作的 magicLink🎯
629+
630+ 现在通过我的邀请链接开始行动吧!` ;
620631 newsChannelId = newsChannelIdCn ;
621632 captionTemplate = `
622633 🟢*${ this . formatMarkdownV2 ( title ) } *🟢
@@ -634,6 +645,11 @@ ${this.formatMarkdownV2(content).replaceAll(
634645🌈在您的群中推送 magicNews 邀请 [@magicNews](${ tgbot } ?startgroup=join_cn) 到您的群中
635646` ;
636647 } else {
648+ shareText = sc
649+ ? sc
650+ : `Hey😎, here's the magicLink that can customize your one-click action🎯
651+
652+ Start ACTION from my invite link now!` ;
637653 lang = 'en' ;
638654 newsChannelId = newsChannelIdEn ;
639655 captionTemplate = `
@@ -682,6 +698,12 @@ ${this.formatMarkdownV2(content).replaceAll(
682698 ] ;
683699 }
684700 inlineKeyboard . push ( typeActions ) ;
701+
702+ const nanoid = customAlphabet (
703+ '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ,
704+ 8 ,
705+ ) ;
706+ const shareTextArr : ScSession [ ] = [ ] ;
685707 const actions = settings . intentList ;
686708 for ( let i = 0 ; i < actions . length ; i ++ ) {
687709 const lineButtons = [ ] ;
@@ -699,13 +721,20 @@ ${this.formatMarkdownV2(content).replaceAll(
699721 ) {
700722 const urlTmp = new URL ( action . value ) ;
701723 const pathSegments = urlTmp . pathname . split ( '/' ) ;
724+ const scOfUrl = urlTmp . searchParams . get ( 'sc' ) ;
725+ const shareTextLink = scOfUrl ? scOfUrl : shareText ;
726+ const sessionId = nanoid ( 20 ) ;
727+ shareTextArr . push ( {
728+ sessionId,
729+ data : shareTextLink ,
730+ } as ScSession ) ;
702731 const code = pathSegments [ pathSegments . length - 1 ] ;
703732 const btnIndex = action . btnIndex ?? '' ;
704733 const btnIndexStr =
705734 btnIndex === ''
706735 ? ''
707736 : Math . max ( parseInt ( btnIndex ) - 1 , 0 ) . toString ( ) ;
708- url = `${ userMiniApp } ?startapp=${ code } _${ btnIndexStr } ` ;
737+ url = `${ userMiniApp } ?startapp=${ code } _${ btnIndexStr } ___ ${ sessionId } ` ;
709738 } else {
710739 url = action . value ;
711740 }
@@ -717,6 +746,13 @@ ${this.formatMarkdownV2(content).replaceAll(
717746 }
718747 inlineKeyboard . push ( lineButtons ) ;
719748 }
749+ if ( shareTextArr . length > 0 ) {
750+ try {
751+ await this . scSessionRepository . addMany ( shareTextArr ) ;
752+ } catch ( error ) {
753+ this . logger . error ( 'sendNewsOrigin error' , error . stack ) ;
754+ }
755+ }
720756 const reply_markup = {
721757 inline_keyboard : inlineKeyboard ,
722758 } ;
@@ -769,6 +805,10 @@ ${this.formatMarkdownV2(content).replaceAll(
769805 }
770806 }
771807
808+ async getScBySessionId ( sessionId : string ) {
809+ return await this . scSessionRepository . getData ( sessionId ) ;
810+ }
811+
772812 async editMessageReplyMarkupPollText (
773813 chatId : string ,
774814 messageId : string ,
0 commit comments