-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add url token and fix telegram adapt problem
- Loading branch information
1 parent
5b826ca
commit e6f0267
Showing
7 changed files
with
58 additions
and
15 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
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
41 changes: 28 additions & 13 deletions
41
src/server/model/notification/token/tokenizer/telegram.ts
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 |
---|---|---|
@@ -1,22 +1,37 @@ | ||
import { ImageContentToken, TitleContentToken } from '../type'; | ||
import { MarkdownContentTokenizer } from './markdown'; | ||
import { | ||
ImageContentToken, | ||
ParagraphContentToken, | ||
TextContentToken, | ||
TitleContentToken, | ||
UrlContentToken, | ||
} from '../type'; | ||
import { BaseContentTokenizer } from './base'; | ||
|
||
export class TelegramContentTokenizer extends MarkdownContentTokenizer { | ||
export class TelegramContentTokenizer extends BaseContentTokenizer { | ||
parseImage(token: ImageContentToken) { | ||
return ''; | ||
} | ||
|
||
parseText(token: TextContentToken): string { | ||
return this.parseEntityCharacter(token.content); | ||
} | ||
|
||
parseTitle(token: TitleContentToken) { | ||
if (token.level === 1) { | ||
return `\n\\# ${token.content}\n`; | ||
} | ||
if (token.level === 2) { | ||
return `\n\\#\\# ${token.content}\n`; | ||
} | ||
if (token.level === 3) { | ||
return `\n\\#\\#\\# ${token.content}\n`; | ||
} | ||
return `\n<b>${this.parseEntityCharacter(token.content)}</b>\n`; | ||
} | ||
|
||
parseParagraph(token: ParagraphContentToken) { | ||
return `\n${this.parseEntityCharacter(token.content)}\n`; | ||
} | ||
|
||
parseUrl(token: UrlContentToken): string { | ||
return `<a href="${token.url}">${token.title ?? token.url}</a>`; | ||
} | ||
|
||
return `\n${token.content}\n`; | ||
private parseEntityCharacter(input: string): string { | ||
return input | ||
.replaceAll('<', '<') | ||
.replaceAll('>', '>') | ||
.replaceAll('&', '&'); | ||
} | ||
} |
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